gbflowengine 0.0.0-stage → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +270 -2
  3. package/dist/gbflowengine.css +1 -0
  4. package/dist/gbflowengine.js +19682 -0
  5. package/dist/gbflowengine.js.map +1 -0
  6. package/dist/gbflowengine.umd.cjs +5 -0
  7. package/dist/gbflowengine.umd.cjs.map +1 -0
  8. package/package.json +83 -4
  9. package/src/center/DefinitionInspect.vue +291 -0
  10. package/src/center/FlowCenter.vue +33 -0
  11. package/src/center/index.js +29 -0
  12. package/src/center/storage.js +748 -0
  13. package/src/core/flow/condition.js +160 -0
  14. package/src/core/flow/customNode.js +385 -0
  15. package/src/core/flow/defaults.js +124 -0
  16. package/src/core/flow/flowConstant.js +265 -0
  17. package/src/core/flow/flowNodeUtils.js +30 -0
  18. package/src/core/flow/index.js +47 -0
  19. package/src/core/flow/node.js +44 -0
  20. package/src/core/flow/nodeFactory.js +58 -0
  21. package/src/core/flow/prediction.js +325 -0
  22. package/src/core/flow/runtime/auto.js +83 -0
  23. package/src/core/flow/runtime/decide.js +329 -0
  24. package/src/core/flow/runtime/event.js +28 -0
  25. package/src/core/flow/runtime/execute.js +357 -0
  26. package/src/core/flow/runtime/helpers.js +52 -0
  27. package/src/core/flow/runtime/query.js +146 -0
  28. package/src/core/flow/runtime/reject.js +137 -0
  29. package/src/core/flow/runtime/token.js +269 -0
  30. package/src/core/flow/runtime.js +129 -0
  31. package/src/core/flow/schema.js +864 -0
  32. package/src/definition/FlowDefinitionDesigner.vue +338 -0
  33. package/src/definition/index.js +9 -0
  34. package/src/index.js +39 -0
  35. package/src/storage.js +200 -0
  36. package/src/testing/FlowTestPanel.vue +2502 -0
  37. package/src/testing/UserConfigDrawer.vue +376 -0
  38. package/src/testing/diagram/FlowProgressDiagram.vue +318 -0
  39. package/src/testing/diagramModel.js +517 -0
  40. package/src/testing/index.js +23 -0
  41. package/src/testing/mock.js +246 -0
  42. package/src/testing/oaExecutors.js +51 -0
  43. package/src/testing/oaSeed.js +467 -0
  44. package/src/testing/sample.js +412 -0
  45. package/src/testing/seed.js +122 -0
  46. package/src/utils/format.js +27 -0
  47. package/src/visual/FlowCanvas.vue +441 -0
  48. package/src/visual/NodeProgressDetail.vue +43 -0
  49. package/src/visual/NodeStatusBadge.vue +17 -0
  50. package/src/visual/NodeWrap.vue +47 -0
  51. package/src/visual/ScWorkflow.vue +50 -0
  52. package/src/visual/SelectDialog.vue +460 -0
  53. package/src/visual/conditionHelpers.js +117 -0
  54. package/src/visual/index.js +6 -0
  55. package/src/visual/nodes/AddNode.vue +223 -0
  56. package/src/visual/nodes/ApproverNode.vue +348 -0
  57. package/src/visual/nodes/BranchNode.vue +442 -0
  58. package/src/visual/nodes/CustomNode.vue +339 -0
  59. package/src/visual/nodes/EndNode.vue +22 -0
  60. package/src/visual/nodes/PassNode.vue +101 -0
  61. package/src/visual/nodes/PromoterNode.vue +135 -0
  62. package/src/visual/nodes/RejectNode.vue +101 -0
  63. package/src/visual/nodes/SendNode.vue +152 -0
  64. package/src/visual/styles.scss +879 -0
  65. package/src/visual/useScNodeStatus.js +18 -0
  66. package/src/workbench/OaWorkbench.vue +1341 -0
  67. package/src/workbench/components/ApprovalWorkspace.vue +2090 -0
  68. package/src/workbench/components/CategoryIcon.vue +74 -0
  69. package/src/workbench/components/NotificationIcon.vue +73 -0
  70. package/src/workbench/components/ProcessSteps.vue +557 -0
  71. package/src/workbench/components/ResubmitDialog.vue +227 -0
  72. package/src/workbench/components/SidebarNav.vue +138 -0
  73. package/src/workbench/components/StartFlowDialog.vue +1058 -0
  74. package/src/workbench/components/UserAvatar.vue +68 -0
  75. package/src/workbench/custom-tasks.js +130 -0
  76. package/src/workbench/model.js +1080 -0
  77. package/src/workbench/pages/DesignPage.vue +798 -0
  78. package/src/workbench/pages/HomePage.vue +1050 -0
  79. package/src/workbench/pages/MonitorPage.vue +1029 -0
  80. package/src/workbench/pages/NotificationsPage.vue +554 -0
  81. package/src/workbench/pages/RequestsPage.vue +644 -0
  82. package/src/workbench/pages/TaskCenterPage.vue +1155 -0
  83. package/src/workbench/pages/TemplatesPage.vue +680 -0
  84. package/src/workbench/persistence.js +89 -0
  85. package/src/workbench/shared.js +18 -0
  86. package/src/workbench/styles.scss +555 -0
  87. package/src/workbench/useWorkbench.js +955 -0
  88. package/types/center.d.ts +5 -0
  89. package/types/core.d.ts +479 -0
  90. package/types/definition.d.ts +4 -0
  91. package/types/index.d.ts +34 -0
  92. package/types/testing.d.ts +20 -0
  93. package/types/visual.d.ts +20 -0
@@ -0,0 +1,68 @@
1
+ <template>
2
+ <span
3
+ class="oa-avatar"
4
+ :class="`oa-avatar--${tone}`"
5
+ :style="{ width: `${size}px`, height: `${size}px`, fontSize: `${Math.max(10, size * 0.4)}px` }"
6
+ :title="name"
7
+ >
8
+ {{ initial }}
9
+ </span>
10
+ </template>
11
+
12
+ <script setup>
13
+ import { computed } from 'vue'
14
+
15
+ defineOptions({ name: 'OaUserAvatar' })
16
+
17
+ const props = defineProps({
18
+ name: { type: String, default: '' },
19
+ size: { type: Number, default: 30 }
20
+ })
21
+
22
+ const initials = ['张', '李', '王', '陈', '赵', '孙', '周', '吴', '刘', '何', '林']
23
+ const tones = ['blue', 'green', 'amber', 'violet', 'rose', 'slate']
24
+
25
+ const initial = computed(() => String(props.name || '用').slice(0, 1))
26
+ const tone = computed(() => {
27
+ const index = Math.max(0, initials.indexOf(initial.value))
28
+ return tones[index % tones.length] || 'blue'
29
+ })
30
+ </script>
31
+
32
+ <style scoped lang="scss">
33
+ .oa-avatar {
34
+ display: inline-flex;
35
+ align-items: center;
36
+ justify-content: center;
37
+ flex-shrink: 0;
38
+ border-radius: 50%;
39
+ color: #fff;
40
+ font-weight: 600;
41
+ letter-spacing: 0.02em;
42
+ user-select: none;
43
+
44
+ &--blue {
45
+ background: linear-gradient(135deg, #3c6fe8, #2b53b7);
46
+ }
47
+
48
+ &--green {
49
+ background: linear-gradient(135deg, #2c9c77, #177454);
50
+ }
51
+
52
+ &--amber {
53
+ background: linear-gradient(135deg, #c28a2e, #9c681a);
54
+ }
55
+
56
+ &--violet {
57
+ background: linear-gradient(135deg, #7b6ad4, #5c4bb0);
58
+ }
59
+
60
+ &--rose {
61
+ background: linear-gradient(135deg, #cf6a78, #a94353);
62
+ }
63
+
64
+ &--slate {
65
+ background: linear-gradient(135deg, #607089, #415066);
66
+ }
67
+ }
68
+ </style>
@@ -0,0 +1,130 @@
1
+ // [文件] gbflowengine·workbench·custom-tasks —— 自定义节点执行 —— 待执行队列、并发控制、成功/失败回填
2
+ //
3
+ // [设计] 从 useWorkbench 拆出的职责块,接收一个 ctx(refs + state + 兄弟函数),把隐式闭包改成显式依赖:
4
+ // 仍是同一份响应式对象、同一个 state,行为不变。
5
+ // ctx 里的函数只在调用时解析,所以装配顺序无关(Object.assign 早于任何生命周期回调)。
6
+
7
+ import { executeCustomNode } from '../core/flow/customNode.js'
8
+ import { sameId } from './model.js'
9
+ import { clone } from './shared.js'
10
+
11
+ export function createCustomTasks(ctx) {
12
+ function resolveCustomExecutors() {
13
+ return ctx.props.customExecutors && typeof ctx.props.customExecutors === 'object'
14
+ ? ctx.props.customExecutors
15
+ : {}
16
+ }
17
+
18
+ function executorLabelOf(config) {
19
+ return config?.executorType === 'method'
20
+ ? `方法 ${config.methodKey}`
21
+ : 'HTTP 请求'
22
+ }
23
+
24
+ function pendingCustomEntries() {
25
+ const entries = []
26
+ ctx.instances.value.forEach((instance) => {
27
+ if (instance.state?.status !== 'running') return
28
+ ;(instance.state.tasks || []).forEach((task) => {
29
+ if (task.kind !== 'custom' || task.status !== 'pending') return
30
+ const key = `${instance.id}:${task.id}`
31
+ if (ctx.customExecutionKeys.has(key) || ctx.customStuckKeys.has(key)) return
32
+ entries.push({
33
+ key,
34
+ instance,
35
+ task,
36
+ config: task.custom,
37
+ variables: clone(instance.state.variables || {})
38
+ })
39
+ })
40
+ })
41
+ return entries
42
+ }
43
+
44
+ function completeCustomEntry(entry, payload) {
45
+ if (ctx.lifecycle.disposed) return
46
+ const instance = ctx.instances.value.find((item) => item === entry.instance)
47
+ if (!instance || instance.state?.status !== 'running') return
48
+ const task = (instance.state.tasks || []).find(
49
+ (item) => sameId(item.id, entry.task.id)
50
+ )
51
+ if (!task || task.kind !== 'custom' || task.status !== 'pending') return
52
+ try {
53
+ const runtime = ctx.runtimeFor(instance)
54
+ const state = runtime.completeCustomTask(task.id, payload)
55
+ ctx.syncState(instance, state)
56
+ ctx.schedulePersist()
57
+ } catch {
58
+ // 任务可能已被终止、撤回或由其它页签处理;避免对同一任务反复执行
59
+ ctx.customStuckKeys.add(entry.key)
60
+ }
61
+ }
62
+
63
+ async function runCustomSweep() {
64
+ if (!ctx.storageReady.value || ctx.lifecycle.customSweepRunning || ctx.lifecycle.disposed) return
65
+ ctx.lifecycle.customSweepRunning = true
66
+ let exhausted = false
67
+ try {
68
+ let guard = 0
69
+ while (guard < 50 && !ctx.lifecycle.disposed) {
70
+ guard += 1
71
+ const entry = ctx.pendingCustomEntries()[0]
72
+ if (!entry) break
73
+ ctx.customExecutionKeys.add(entry.key)
74
+ ctx.customExecutingTaskIds.value = [...customExecutionKeys]
75
+ const controller = new AbortController()
76
+ ctx.customControllers.set(entry.key, controller)
77
+ const startedAt = Date.now()
78
+ try {
79
+ const node = ctx.findNodeInWorkflow(
80
+ entry.instance.definition?.workflow,
81
+ entry.task.nodeId
82
+ )
83
+ const result = await executeCustomNode(entry.config, {
84
+ variables: entry.variables,
85
+ executors: ctx.resolveCustomExecutors(),
86
+ fetchImpl: typeof ctx.props.customFetch === 'function' ? ctx.props.customFetch : undefined,
87
+ signal: controller.signal,
88
+ node,
89
+ instance: entry.instance
90
+ })
91
+ ctx.completeCustomEntry(entry, {
92
+ success: true,
93
+ result,
94
+ durationMs: Date.now() - startedAt,
95
+ executorLabel: ctx.executorLabelOf(entry.config)
96
+ })
97
+ } catch (error) {
98
+ ctx.completeCustomEntry(entry, {
99
+ success: false,
100
+ error: error.message || String(error),
101
+ durationMs: Date.now() - startedAt,
102
+ executorLabel: ctx.executorLabelOf(entry.config)
103
+ })
104
+ } finally {
105
+ ctx.customExecutionKeys.delete(entry.key)
106
+ ctx.customExecutingTaskIds.value = [...customExecutionKeys]
107
+ ctx.customControllers.delete(entry.key)
108
+ }
109
+ }
110
+ if (guard >= 50) exhausted = true
111
+ } finally {
112
+ ctx.lifecycle.customSweepRunning = false
113
+ if (!ctx.lifecycle.disposed && !exhausted && ctx.pendingCustomEntries().length) {
114
+ ctx.scheduleCustomSweep(120)
115
+ }
116
+ }
117
+ }
118
+
119
+ function scheduleCustomSweep(delay = 160) {
120
+ if (!ctx.ready.value || ctx.lifecycle.disposed || ctx.lifecycle.customSweepTimer) return
121
+ ctx.lifecycle.customSweepTimer = setTimeout(() => {
122
+ ctx.lifecycle.customSweepTimer = null
123
+ ctx.runCustomSweep().catch(() => {
124
+ // 自定义节点批处理失败不应中断 OA 主流程
125
+ })
126
+ }, delay)
127
+ }
128
+
129
+ return { resolveCustomExecutors, executorLabelOf, pendingCustomEntries, completeCustomEntry, runCustomSweep, scheduleCustomSweep }
130
+ }