gbflowengine 0.1.0 → 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.
- package/README.md +271 -271
- package/dist/gbflowengine.css +1 -1
- package/dist/gbflowengine.js +8232 -6913
- package/dist/gbflowengine.js.map +1 -1
- package/dist/gbflowengine.umd.cjs +2 -2
- package/dist/gbflowengine.umd.cjs.map +1 -1
- package/package.json +85 -84
- package/src/center/DefinitionInspect.vue +291 -291
- package/src/center/FlowCenter.vue +33 -33
- package/src/center/index.js +29 -29
- package/src/center/storage.js +748 -748
- package/src/core/flow/condition.js +160 -160
- package/src/core/flow/customNode.js +385 -385
- package/src/core/flow/defaults.js +124 -124
- package/src/core/flow/flowConstant.js +265 -265
- package/src/core/flow/flowNodeUtils.js +29 -29
- package/src/core/flow/index.js +47 -47
- package/src/core/flow/node.js +44 -44
- package/src/core/flow/nodeFactory.js +58 -58
- package/src/core/flow/prediction.js +325 -325
- package/src/core/flow/schema.js +864 -864
- package/src/definition/FlowDefinitionDesigner.vue +338 -338
- package/src/definition/index.js +9 -9
- package/src/index.js +39 -39
- package/src/storage.js +200 -200
- package/src/testing/FlowTestPanel.vue +2502 -2502
- package/src/testing/UserConfigDrawer.vue +376 -376
- package/src/testing/diagram/FlowProgressDiagram.vue +318 -318
- package/src/testing/diagramModel.js +517 -517
- package/src/testing/index.js +23 -23
- package/src/testing/mock.js +246 -246
- package/src/testing/oaExecutors.js +51 -51
- package/src/testing/oaSeed.js +467 -467
- package/src/testing/sample.js +412 -412
- package/src/testing/seed.js +122 -122
- package/src/utils/format.js +27 -27
- package/src/visual/FlowCanvas.vue +440 -440
- package/src/visual/NodeProgressDetail.vue +43 -43
- package/src/visual/NodeStatusBadge.vue +17 -17
- package/src/visual/NodeWrap.vue +46 -46
- package/src/visual/ScWorkflow.vue +49 -49
- package/src/visual/SelectDialog.vue +459 -459
- package/src/visual/conditionHelpers.js +116 -116
- package/src/visual/index.js +6 -6
- package/src/visual/nodes/AddNode.vue +222 -222
- package/src/visual/nodes/ApproverNode.vue +347 -347
- package/src/visual/nodes/BranchNode.vue +441 -441
- package/src/visual/nodes/CustomNode.vue +339 -339
- package/src/visual/nodes/EndNode.vue +21 -21
- package/src/visual/nodes/PassNode.vue +100 -100
- package/src/visual/nodes/PromoterNode.vue +134 -134
- package/src/visual/nodes/RejectNode.vue +100 -100
- package/src/visual/nodes/SendNode.vue +151 -151
- package/src/visual/styles.scss +879 -879
- package/src/visual/useScNodeStatus.js +18 -18
- package/src/workbench/OaWorkbench.vue +1341 -1341
- package/src/workbench/components/ApprovalWorkspace.vue +2090 -2090
- package/src/workbench/components/CategoryIcon.vue +74 -74
- package/src/workbench/components/NotificationIcon.vue +73 -73
- package/src/workbench/components/ProcessSteps.vue +557 -557
- package/src/workbench/components/ResubmitDialog.vue +227 -227
- package/src/workbench/components/SidebarNav.vue +138 -138
- package/src/workbench/components/StartFlowDialog.vue +1058 -1058
- package/src/workbench/components/UserAvatar.vue +68 -68
- package/src/workbench/model.js +1080 -1080
- package/src/workbench/pages/DesignPage.vue +798 -798
- package/src/workbench/pages/HomePage.vue +1050 -1050
- package/src/workbench/pages/MonitorPage.vue +1029 -1029
- package/src/workbench/pages/NotificationsPage.vue +554 -554
- package/src/workbench/pages/RequestsPage.vue +644 -644
- package/src/workbench/pages/TaskCenterPage.vue +1155 -1155
- package/src/workbench/pages/TemplatesPage.vue +680 -680
- package/src/workbench/styles.scss +555 -555
- package/types/center.d.ts +5 -5
- package/types/core.d.ts +479 -479
- package/types/definition.d.ts +4 -4
- package/types/index.d.ts +34 -34
- package/types/testing.d.ts +20 -20
- package/types/visual.d.ts +20 -20
|
@@ -1,325 +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 }
|
|
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 }
|