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,325 @@
1
+ import {
2
+ ApproverType,
3
+ ApproverTypeLabel,
4
+ FlowNodeType,
5
+ NodeTypeLabel,
6
+ SignMode,
7
+ SignModeLabel
8
+ } from './flowConstant.js'
9
+ import { selectBranchNode, selectInclusiveBranches } from './condition.js'
10
+ import { createFlowRuntime } from './runtime.js'
11
+ import { customNodeSummary } from './customNode.js'
12
+
13
+ const MAX_PREDICTION_NODES = 2000
14
+
15
+ function clone(value) {
16
+ return value === undefined ? undefined : JSON.parse(JSON.stringify(value))
17
+ }
18
+
19
+ function normalizeInitiator(initiator) {
20
+ if (initiator === null || initiator === undefined) return null
21
+ if (typeof initiator !== 'object') {
22
+ return { id: initiator, name: `用户${initiator}`, deptName: '', deptId: null }
23
+ }
24
+ const id = initiator.id ?? initiator.userId ?? initiator.approverId ?? initiator.username
25
+ return {
26
+ id,
27
+ name:
28
+ initiator.realName ||
29
+ initiator.nickName ||
30
+ initiator.name ||
31
+ initiator.userName ||
32
+ String(id),
33
+ deptName: initiator.deptName || '',
34
+ deptId: initiator.deptId ?? null
35
+ }
36
+ }
37
+
38
+ function makeGroup(container, branch, type) {
39
+ return {
40
+ type,
41
+ nodeId: container.nodeId,
42
+ nodeName: container.nodeName,
43
+ branchId: branch?.nodeId ?? null,
44
+ branchName: branch?.nodeName ?? '',
45
+ branchIndex: branch?.branchIndex ?? null
46
+ }
47
+ }
48
+
49
+ /**
50
+ * Simulates a workflow definition without starting an instance.
51
+ * Resolves branch decisions, approvers and cc users so the caller can
52
+ * preview the exact path the current form data would take.
53
+ */
54
+ export function predictWorkflow({
55
+ definition = null,
56
+ workflow = null,
57
+ data = {},
58
+ context = {},
59
+ initiator = null
60
+ } = {}) {
61
+ const root = workflow || definition?.workflow
62
+ if (!root) throw new Error('predictWorkflow: workflow is required')
63
+
64
+ const runtime = createFlowRuntime({ workflow: root, data, context })
65
+ const variables = clone(data)
66
+ const nodes = []
67
+ const decisions = []
68
+ const warnings = []
69
+ const visited = new Set()
70
+ let sequence = 0
71
+ let steps = 0
72
+ let approvalNodeCount = 0
73
+ let approvalTaskCount = 0
74
+ let ccNodeCount = 0
75
+ let ccUserCount = 0
76
+ let status = 'completed'
77
+
78
+ const addWarning = (code, message, node) => {
79
+ if (warnings.some((item) => item.code === code && String(item.nodeId) === String(node?.nodeId))) {
80
+ return
81
+ }
82
+ warnings.push({
83
+ code,
84
+ message,
85
+ nodeId: node?.nodeId ?? null,
86
+ nodeName: node?.nodeName || ''
87
+ })
88
+ }
89
+
90
+ const addNode = (node, kind, path, group, extra = {}) => {
91
+ sequence += 1
92
+ const entry = {
93
+ id: `prediction_${sequence}`,
94
+ nodeId: node.nodeId,
95
+ nodeName: node.nodeName,
96
+ type: node.type,
97
+ typeLabel: NodeTypeLabel[node.type] || node.type,
98
+ kind,
99
+ depth: path.length,
100
+ path: [...path, node.nodeName],
101
+ group,
102
+ ...extra
103
+ }
104
+ nodes.push(entry)
105
+ return entry
106
+ }
107
+
108
+ const walkChain = (startNode, path = [], group = null) => {
109
+ let node = startNode
110
+ while (node) {
111
+ steps += 1
112
+ if (steps > MAX_PREDICTION_NODES) {
113
+ addWarning('PREDICTION_GUARD', '流程预测步数超过保护上限,可能存在环', node)
114
+ return
115
+ }
116
+ const key = String(node.nodeId)
117
+ if (visited.has(key)) {
118
+ addWarning('PREDICTION_LOOP', `节点「${node.nodeName}」重复出现,预测已停止`, node)
119
+ return
120
+ }
121
+ visited.add(key)
122
+
123
+ switch (node.type) {
124
+ case FlowNodeType.START: {
125
+ addNode(node, 'start', path, group)
126
+ node = node.childNode
127
+ continue
128
+ }
129
+ case FlowNodeType.APPROVE: {
130
+ const approvers = runtime.resolveApprovers(node)
131
+ const signMode = node.signMode === SignMode.OR ? SignMode.OR : SignMode.AND
132
+ const approverType = node.approverType || ApproverType.USER
133
+ const note = approvers.length
134
+ ? ''
135
+ : approverType === ApproverType.SUPERIOR_LEADER
136
+ ? `第 ${node.superiorLevel || 1} 级上级领导为空,运行时将自动通过`
137
+ : '未解析到审批人,运行时将自动通过'
138
+ if (!approvers.length) {
139
+ addWarning(
140
+ 'APPROVERS_EMPTY',
141
+ `审批节点「${node.nodeName}」${note}`,
142
+ node
143
+ )
144
+ }
145
+ approvalNodeCount += 1
146
+ approvalTaskCount += approvers.length
147
+ addNode(node, 'approve', path, group, {
148
+ signMode,
149
+ signModeLabel: SignModeLabel[signMode],
150
+ approverType,
151
+ approverTypeLabel: ApproverTypeLabel[approverType] || approverType,
152
+ superiorLevel: node.superiorLevel || null,
153
+ approvers,
154
+ note
155
+ })
156
+ node = node.childNode
157
+ continue
158
+ }
159
+ case FlowNodeType.CC: {
160
+ const users = runtime.resolveCcUsers(node)
161
+ const note = users.length ? '' : '未配置抄送人,运行时将跳过'
162
+ ccNodeCount += 1
163
+ ccUserCount += users.length
164
+ addNode(node, 'cc', path, group, {
165
+ ccUsers: users,
166
+ allowInitiatorAddUsers: node.allowInitiatorAddUsers !== false,
167
+ note
168
+ })
169
+ node = node.childNode
170
+ continue
171
+ }
172
+ case FlowNodeType.BRANCH: {
173
+ const selected = selectBranchNode(node, variables)
174
+ const decision = selected
175
+ ? {
176
+ branchId: selected.nodeId,
177
+ branchName: selected.nodeName,
178
+ branchNames: [selected.nodeName]
179
+ }
180
+ : null
181
+ addNode(node, 'branch', path, group, {
182
+ decision,
183
+ note: selected ? '' : '未命中任何条件分支,流程将在此结束'
184
+ })
185
+ decisions.push({
186
+ nodeId: node.nodeId,
187
+ nodeName: node.nodeName,
188
+ type: 'branch',
189
+ selectedBranchId: selected?.nodeId ?? null,
190
+ selectedBranchName: selected?.nodeName ?? '',
191
+ selectedBranchNames: selected ? [selected.nodeName] : []
192
+ })
193
+ if (!selected) {
194
+ addWarning(
195
+ 'NO_MATCHING_BRANCH',
196
+ `条件分支「${node.nodeName}」未命中任何分支,流程将在此结束`,
197
+ node
198
+ )
199
+ return
200
+ }
201
+ if (selected.childNode) {
202
+ walkChain(
203
+ selected.childNode,
204
+ [...path, node.nodeName, selected.nodeName],
205
+ makeGroup(node, selected, 'condition')
206
+ )
207
+ }
208
+ node = node.childNode
209
+ continue
210
+ }
211
+ case FlowNodeType.PARALLEL: {
212
+ const branches = (node.branchList || []).filter(Boolean)
213
+ addNode(node, 'parallel', path, group, {
214
+ branchNames: branches.map((branch) => branch.nodeName),
215
+ note: branches.length ? '' : '未配置并行分支'
216
+ })
217
+ decisions.push({
218
+ nodeId: node.nodeId,
219
+ nodeName: node.nodeName,
220
+ type: 'parallel',
221
+ branchNames: branches.map((branch) => branch.nodeName)
222
+ })
223
+ branches.forEach((branch) => {
224
+ if (!branch.childNode) return
225
+ walkChain(
226
+ branch.childNode,
227
+ [...path, node.nodeName, branch.nodeName],
228
+ makeGroup(node, branch, 'parallel')
229
+ )
230
+ })
231
+ node = node.childNode
232
+ continue
233
+ }
234
+ case FlowNodeType.INCLUSIVE: {
235
+ const branches = (node.branchList || []).filter(Boolean)
236
+ const selected = selectInclusiveBranches(node, variables)
237
+ const decision = {
238
+ branchIds: selected.map((branch) => branch.nodeId),
239
+ branchNames: selected.map((branch) => branch.nodeName)
240
+ }
241
+ addNode(node, 'inclusive', path, group, {
242
+ decision,
243
+ note: selected.length ? '' : '未命中包容分支,将直接进入后续节点'
244
+ })
245
+ decisions.push({
246
+ nodeId: node.nodeId,
247
+ nodeName: node.nodeName,
248
+ type: 'inclusive',
249
+ selectedBranchIds: decision.branchIds,
250
+ selectedBranchNames: decision.branchNames
251
+ })
252
+ if (!selected.length) {
253
+ addWarning(
254
+ 'NO_MATCHING_BRANCH',
255
+ `包容分支「${node.nodeName}」未命中任何分支`,
256
+ node
257
+ )
258
+ }
259
+ selected.forEach((branch) => {
260
+ if (!branch.childNode) return
261
+ walkChain(
262
+ branch.childNode,
263
+ [...path, node.nodeName, branch.nodeName],
264
+ makeGroup(node, branch, 'inclusive')
265
+ )
266
+ })
267
+ node = node.childNode
268
+ continue
269
+ }
270
+ case FlowNodeType.CUSTOM: {
271
+ addNode(node, 'custom', path, group, {
272
+ note: `系统执行:${customNodeSummary(node.custom)}`,
273
+ custom: clone(node.custom)
274
+ })
275
+ node = node.childNode
276
+ continue
277
+ }
278
+ case FlowNodeType.PASS: {
279
+ addNode(node, 'pass', path, group, {
280
+ note: '到达此节点后流程直接通过并结束'
281
+ })
282
+ return
283
+ }
284
+ case FlowNodeType.REJECT: {
285
+ status = 'rejected'
286
+ addNode(node, 'reject', path, group, {
287
+ note: '到达此节点后流程直接拒绝'
288
+ })
289
+ return
290
+ }
291
+ case FlowNodeType.END: {
292
+ addNode(node, 'end', path, group)
293
+ return
294
+ }
295
+ default: {
296
+ node = node.childNode
297
+ }
298
+ }
299
+ }
300
+ }
301
+
302
+ walkChain(root)
303
+
304
+ return {
305
+ rootNodeId: root.nodeId,
306
+ definitionName: definition?.meta?.name || null,
307
+ initiator: normalizeInitiator(initiator || context?.initiator),
308
+ status,
309
+ nodeCount: nodes.length,
310
+ approvalNodeCount,
311
+ approvalTaskCount,
312
+ ccNodeCount,
313
+ ccUserCount,
314
+ branchCount: decisions.length,
315
+ decisions,
316
+ warnings,
317
+ nodes
318
+ }
319
+ }
320
+
321
+ export function predictFlow(workflow, data = {}, context = {}, initiator = null) {
322
+ return predictWorkflow({ workflow, data, context, initiator })
323
+ }
324
+
325
+ export { MAX_PREDICTION_NODES }
@@ -0,0 +1,83 @@
1
+ // [文件] gbflowengine·runtime·auto —— 自动推进 —— 超时与自动通过
2
+
3
+ // [设计] 方法以对象字面量导出,由 runtime.js 末尾 Object.assign 装配到 FlowRuntime.prototype(同一 this,调用形状不变)。
4
+
5
+ import { clone, RUNNING } from './helpers.js'
6
+ export const autoMethods = {
7
+
8
+ /**
9
+ * Evaluates approval deadlines. Call on load and whenever the app becomes
10
+ * active; browsers cannot be trusted to run timers while closed.
11
+ */
12
+ tick(now = Date.now()) {
13
+ if (this.state.status !== RUNNING) return this.getState()
14
+ const timestamp = now instanceof Date ? now.getTime() : Number(now)
15
+ if (!Number.isFinite(timestamp)) return this.getState()
16
+
17
+ let processed = 0
18
+ const guard = 1000
19
+ while (processed < guard) {
20
+ const task = this.state.tasks.find(
21
+ (item) =>
22
+ item.status === 'pending' &&
23
+ item.kind !== 'submit' &&
24
+ item.dueAt &&
25
+ new Date(item.dueAt).getTime() <= timestamp
26
+ )
27
+ if (!task) break
28
+ this._autoCompleteTask(task)
29
+ processed += 1
30
+ if (this.state.status !== RUNNING) break
31
+ }
32
+ return this.getState()
33
+ },
34
+
35
+ _autoCompleteTask(task) {
36
+ const node = this.getNode(task.nodeId)
37
+ if (!node) {
38
+ this._warn('NODE_NOT_FOUND', `超时任务找不到节点:${task.nodeId}`)
39
+ const token = this.state.tokens.find((item) => item.id === task.tokenId)
40
+ if (token) this._finishToken(token)
41
+ this._run()
42
+ return
43
+ }
44
+ const mode = node?.termMode === 1 ? 'reject' : 'approve'
45
+ const at = new Date().toISOString()
46
+ const operator = { id: 'system', name: '系统超时' }
47
+ const comment = `审批超过 ${node?.term || 0} 小时,系统自动${mode === 'reject' ? '拒绝' : '通过'}`
48
+ const record = { action: mode === 'reject' ? 'reject' : 'approve', approver: operator, comment, at, system: true }
49
+
50
+ if (mode === 'reject') {
51
+ task.status = 'rejected'
52
+ task.records = [...(task.records || []), record]
53
+ this.state.history.push(
54
+ this._event('timeoutReject', { nodeId: task.nodeId, taskId: task.id, comment })
55
+ )
56
+ this.state.warnings.push({
57
+ code: 'TASK_TIMEOUT_REJECTED',
58
+ message: `任务「${task.nodeName}」审批超时,已自动拒绝`,
59
+ at
60
+ })
61
+ this._handleReject(task, node, operator)
62
+ this._run()
63
+ return
64
+ }
65
+
66
+ task.records = [...(task.records || []), record]
67
+ task.approvedBy = (task.approvers || []).map((approver) => clone(approver))
68
+ task.status = 'approved'
69
+ task.finishedAt = at
70
+ task.autoApproved = true
71
+ const token = this.state.tokens.find((item) => item.id === task.tokenId)
72
+ if (token) {
73
+ token.blockedTaskId = null
74
+ this._emit('onNodeLeave', { runtime: this, node: clone(node), token: clone(token) })
75
+ this._advanceFrom(node, token)
76
+ }
77
+ this.state.history.push(
78
+ this._event('timeoutApprove', { nodeId: task.nodeId, taskId: task.id, comment })
79
+ )
80
+ this._emit('onTaskApproved', { runtime: this, task: clone(task), state: this.getState() })
81
+ this._run()
82
+ }
83
+ }