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.
- package/LICENSE +21 -0
- package/README.md +270 -2
- package/dist/gbflowengine.css +1 -0
- package/dist/gbflowengine.js +19682 -0
- package/dist/gbflowengine.js.map +1 -0
- package/dist/gbflowengine.umd.cjs +5 -0
- package/dist/gbflowengine.umd.cjs.map +1 -0
- package/package.json +83 -4
- package/src/center/DefinitionInspect.vue +291 -0
- package/src/center/FlowCenter.vue +33 -0
- package/src/center/index.js +29 -0
- package/src/center/storage.js +748 -0
- package/src/core/flow/condition.js +160 -0
- package/src/core/flow/customNode.js +385 -0
- package/src/core/flow/defaults.js +124 -0
- package/src/core/flow/flowConstant.js +265 -0
- package/src/core/flow/flowNodeUtils.js +30 -0
- package/src/core/flow/index.js +47 -0
- package/src/core/flow/node.js +44 -0
- package/src/core/flow/nodeFactory.js +58 -0
- package/src/core/flow/prediction.js +325 -0
- package/src/core/flow/runtime/auto.js +83 -0
- package/src/core/flow/runtime/decide.js +329 -0
- package/src/core/flow/runtime/event.js +28 -0
- package/src/core/flow/runtime/execute.js +357 -0
- package/src/core/flow/runtime/helpers.js +52 -0
- package/src/core/flow/runtime/query.js +146 -0
- package/src/core/flow/runtime/reject.js +137 -0
- package/src/core/flow/runtime/token.js +269 -0
- package/src/core/flow/runtime.js +129 -0
- package/src/core/flow/schema.js +864 -0
- package/src/definition/FlowDefinitionDesigner.vue +338 -0
- package/src/definition/index.js +9 -0
- package/src/index.js +39 -0
- package/src/storage.js +200 -0
- package/src/testing/FlowTestPanel.vue +2502 -0
- package/src/testing/UserConfigDrawer.vue +376 -0
- package/src/testing/diagram/FlowProgressDiagram.vue +318 -0
- package/src/testing/diagramModel.js +517 -0
- package/src/testing/index.js +23 -0
- package/src/testing/mock.js +246 -0
- package/src/testing/oaExecutors.js +51 -0
- package/src/testing/oaSeed.js +467 -0
- package/src/testing/sample.js +412 -0
- package/src/testing/seed.js +122 -0
- package/src/utils/format.js +27 -0
- package/src/visual/FlowCanvas.vue +441 -0
- package/src/visual/NodeProgressDetail.vue +43 -0
- package/src/visual/NodeStatusBadge.vue +17 -0
- package/src/visual/NodeWrap.vue +47 -0
- package/src/visual/ScWorkflow.vue +50 -0
- package/src/visual/SelectDialog.vue +460 -0
- package/src/visual/conditionHelpers.js +117 -0
- package/src/visual/index.js +6 -0
- package/src/visual/nodes/AddNode.vue +223 -0
- package/src/visual/nodes/ApproverNode.vue +348 -0
- package/src/visual/nodes/BranchNode.vue +442 -0
- package/src/visual/nodes/CustomNode.vue +339 -0
- package/src/visual/nodes/EndNode.vue +22 -0
- package/src/visual/nodes/PassNode.vue +101 -0
- package/src/visual/nodes/PromoterNode.vue +135 -0
- package/src/visual/nodes/RejectNode.vue +101 -0
- package/src/visual/nodes/SendNode.vue +152 -0
- package/src/visual/styles.scss +879 -0
- package/src/visual/useScNodeStatus.js +18 -0
- package/src/workbench/OaWorkbench.vue +1341 -0
- package/src/workbench/components/ApprovalWorkspace.vue +2090 -0
- package/src/workbench/components/CategoryIcon.vue +74 -0
- package/src/workbench/components/NotificationIcon.vue +73 -0
- package/src/workbench/components/ProcessSteps.vue +557 -0
- package/src/workbench/components/ResubmitDialog.vue +227 -0
- package/src/workbench/components/SidebarNav.vue +138 -0
- package/src/workbench/components/StartFlowDialog.vue +1058 -0
- package/src/workbench/components/UserAvatar.vue +68 -0
- package/src/workbench/custom-tasks.js +130 -0
- package/src/workbench/model.js +1080 -0
- package/src/workbench/pages/DesignPage.vue +798 -0
- package/src/workbench/pages/HomePage.vue +1050 -0
- package/src/workbench/pages/MonitorPage.vue +1029 -0
- package/src/workbench/pages/NotificationsPage.vue +554 -0
- package/src/workbench/pages/RequestsPage.vue +644 -0
- package/src/workbench/pages/TaskCenterPage.vue +1155 -0
- package/src/workbench/pages/TemplatesPage.vue +680 -0
- package/src/workbench/persistence.js +89 -0
- package/src/workbench/shared.js +18 -0
- package/src/workbench/styles.scss +555 -0
- package/src/workbench/useWorkbench.js +955 -0
- package/types/center.d.ts +5 -0
- package/types/core.d.ts +479 -0
- package/types/definition.d.ts +4 -0
- package/types/index.d.ts +34 -0
- package/types/testing.d.ts +20 -0
- package/types/visual.d.ts +20 -0
|
@@ -0,0 +1,412 @@
|
|
|
1
|
+
import { createDefinition, normalizeDefinition } from '../core/flow/schema.js'
|
|
2
|
+
|
|
3
|
+
function condition(variable, variableName, operator, value, fieldType, logic = 'AND') {
|
|
4
|
+
return { variable, variableName, operator, value, fieldType, logic }
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
function approve(nodeId, nodeName, userList, userNickNames, deptNameMap, extra = {}) {
|
|
8
|
+
return {
|
|
9
|
+
nodeId,
|
|
10
|
+
nodeName,
|
|
11
|
+
type: 'approve',
|
|
12
|
+
signMode: 'and',
|
|
13
|
+
approverType: 'user',
|
|
14
|
+
userList,
|
|
15
|
+
userNickNames,
|
|
16
|
+
deptNameMap,
|
|
17
|
+
roleList: [],
|
|
18
|
+
roleNameMap: {},
|
|
19
|
+
superiorLevel: 1,
|
|
20
|
+
allowTransfer: true,
|
|
21
|
+
rejectStrategy: 'to_initiator',
|
|
22
|
+
rejectTargetNodeId: null,
|
|
23
|
+
childNode: null,
|
|
24
|
+
...extra
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function createSampleDefinition() {
|
|
29
|
+
const workflow = {
|
|
30
|
+
nodeId: 100,
|
|
31
|
+
nodeName: '发起人',
|
|
32
|
+
type: 'start',
|
|
33
|
+
childNode: approve(
|
|
34
|
+
101,
|
|
35
|
+
'部门主管审批',
|
|
36
|
+
[1, 2],
|
|
37
|
+
{ 1: '张明', 2: '李婷' },
|
|
38
|
+
{ 1: '产品中心', 2: '设计部' },
|
|
39
|
+
{ signMode: 'and' }
|
|
40
|
+
)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const manager = workflow.childNode
|
|
44
|
+
manager.childNode = {
|
|
45
|
+
nodeId: 102,
|
|
46
|
+
nodeName: '条件分支',
|
|
47
|
+
type: 'branch',
|
|
48
|
+
branchList: [
|
|
49
|
+
{
|
|
50
|
+
nodeId: 103,
|
|
51
|
+
nodeName: '大额采购',
|
|
52
|
+
type: 'condition',
|
|
53
|
+
conditions: [
|
|
54
|
+
condition('amount', '申请金额', '>', 1000, 'integer')
|
|
55
|
+
],
|
|
56
|
+
childNode: {
|
|
57
|
+
nodeId: 104,
|
|
58
|
+
nodeName: '财务审批',
|
|
59
|
+
type: 'approve',
|
|
60
|
+
approverType: 'role',
|
|
61
|
+
roleList: [1],
|
|
62
|
+
roleNameMap: { 1: '财务专员' },
|
|
63
|
+
userList: [],
|
|
64
|
+
signMode: 'or',
|
|
65
|
+
superiorLevel: 1,
|
|
66
|
+
allowTransfer: false,
|
|
67
|
+
rejectStrategy: 'to_initiator',
|
|
68
|
+
rejectTargetNodeId: null,
|
|
69
|
+
childNode: null
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
nodeId: 105,
|
|
74
|
+
nodeName: '特殊合同',
|
|
75
|
+
type: 'condition',
|
|
76
|
+
conditions: [
|
|
77
|
+
condition('category', '申请类型', '==', 'special', 'string')
|
|
78
|
+
],
|
|
79
|
+
childNode: {
|
|
80
|
+
nodeId: 106,
|
|
81
|
+
nodeName: '直接拒绝',
|
|
82
|
+
type: 'reject',
|
|
83
|
+
childNode: null
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
nodeId: 107,
|
|
88
|
+
nodeName: '加急申请',
|
|
89
|
+
type: 'condition',
|
|
90
|
+
conditions: [
|
|
91
|
+
condition('urgent', '是否加急', '==', 'yes', 'string')
|
|
92
|
+
],
|
|
93
|
+
childNode: {
|
|
94
|
+
nodeId: 108,
|
|
95
|
+
nodeName: '直接通过',
|
|
96
|
+
type: 'pass',
|
|
97
|
+
childNode: null
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
nodeId: 122,
|
|
102
|
+
nodeName: '需要发票',
|
|
103
|
+
type: 'condition',
|
|
104
|
+
conditions: [
|
|
105
|
+
condition('needInvoice', '是否需要发票', '==', true, 'boolean')
|
|
106
|
+
],
|
|
107
|
+
childNode: {
|
|
108
|
+
nodeId: 123,
|
|
109
|
+
nodeName: '抄送税务',
|
|
110
|
+
type: 'cc',
|
|
111
|
+
userList: [8],
|
|
112
|
+
userNickNames: { 8: '吴军' },
|
|
113
|
+
deptNameMap: { 8: '技术支持部' },
|
|
114
|
+
allowInitiatorAddUsers: false,
|
|
115
|
+
childNode: null
|
|
116
|
+
}
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
nodeId: 109,
|
|
120
|
+
nodeName: '其他条件',
|
|
121
|
+
type: 'condition',
|
|
122
|
+
isDefaultCondition: true,
|
|
123
|
+
childNode: null
|
|
124
|
+
}
|
|
125
|
+
],
|
|
126
|
+
childNode: {
|
|
127
|
+
nodeId: 110,
|
|
128
|
+
nodeName: '抄送人力资源',
|
|
129
|
+
type: 'cc',
|
|
130
|
+
userList: [3],
|
|
131
|
+
userNickNames: { 3: '王芳' },
|
|
132
|
+
deptNameMap: { 3: '人力资源部' },
|
|
133
|
+
allowInitiatorAddUsers: true,
|
|
134
|
+
childNode: {
|
|
135
|
+
nodeId: 111,
|
|
136
|
+
nodeName: '并行会签',
|
|
137
|
+
type: 'parallel',
|
|
138
|
+
branchList: [
|
|
139
|
+
{
|
|
140
|
+
nodeId: 112,
|
|
141
|
+
nodeName: '法务分支',
|
|
142
|
+
type: 'parallel_branch',
|
|
143
|
+
branchIndex: 0,
|
|
144
|
+
childNode: approve(
|
|
145
|
+
113,
|
|
146
|
+
'法务审批',
|
|
147
|
+
[4],
|
|
148
|
+
{ 4: '陈浩' },
|
|
149
|
+
{ 4: '法务部' },
|
|
150
|
+
{ rejectStrategy: 'to_previous' }
|
|
151
|
+
)
|
|
152
|
+
},
|
|
153
|
+
{
|
|
154
|
+
nodeId: 114,
|
|
155
|
+
nodeName: '人事分支',
|
|
156
|
+
type: 'parallel_branch',
|
|
157
|
+
branchIndex: 1,
|
|
158
|
+
childNode: approve(
|
|
159
|
+
115,
|
|
160
|
+
'人事审批',
|
|
161
|
+
[5],
|
|
162
|
+
{ 5: '赵磊' },
|
|
163
|
+
{ 5: '人事部' },
|
|
164
|
+
{ signMode: 'or' }
|
|
165
|
+
)
|
|
166
|
+
}
|
|
167
|
+
],
|
|
168
|
+
childNode: {
|
|
169
|
+
nodeId: 116,
|
|
170
|
+
nodeName: '包容分支',
|
|
171
|
+
type: 'inclusive',
|
|
172
|
+
branchList: [
|
|
173
|
+
{
|
|
174
|
+
nodeId: 117,
|
|
175
|
+
nodeName: '需财务归档',
|
|
176
|
+
type: 'inclusive_branch',
|
|
177
|
+
branchIndex: 0,
|
|
178
|
+
conditions: [
|
|
179
|
+
condition('amount', '申请金额', '>=', 500, 'integer')
|
|
180
|
+
],
|
|
181
|
+
isDefaultBranch: false,
|
|
182
|
+
childNode: {
|
|
183
|
+
nodeId: 118,
|
|
184
|
+
nodeName: '抄送财务',
|
|
185
|
+
type: 'cc',
|
|
186
|
+
userList: [6],
|
|
187
|
+
userNickNames: { 6: '孙丽' },
|
|
188
|
+
deptNameMap: { 6: '财务部' },
|
|
189
|
+
allowInitiatorAddUsers: false,
|
|
190
|
+
childNode: null
|
|
191
|
+
}
|
|
192
|
+
},
|
|
193
|
+
{
|
|
194
|
+
nodeId: 119,
|
|
195
|
+
nodeName: '其他分支',
|
|
196
|
+
type: 'inclusive_branch',
|
|
197
|
+
branchIndex: 1,
|
|
198
|
+
conditions: [],
|
|
199
|
+
isDefaultBranch: true,
|
|
200
|
+
childNode: approve(
|
|
201
|
+
120,
|
|
202
|
+
'行政备案',
|
|
203
|
+
[7],
|
|
204
|
+
{ 7: '周琪' },
|
|
205
|
+
{ 7: '行政部' },
|
|
206
|
+
{ signMode: 'or' }
|
|
207
|
+
)
|
|
208
|
+
}
|
|
209
|
+
],
|
|
210
|
+
childNode: {
|
|
211
|
+
nodeId: 121,
|
|
212
|
+
nodeName: '流程结束',
|
|
213
|
+
type: 'end',
|
|
214
|
+
childNode: null
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
const form = [
|
|
222
|
+
{
|
|
223
|
+
id: 'cmp_reason',
|
|
224
|
+
type: 'input',
|
|
225
|
+
value: '',
|
|
226
|
+
required: true,
|
|
227
|
+
defaultValue: '',
|
|
228
|
+
props: {
|
|
229
|
+
label: '申请事由',
|
|
230
|
+
variableName: 'reason',
|
|
231
|
+
placeholder: '请输入申请事由'
|
|
232
|
+
},
|
|
233
|
+
style: { width: '100%' }
|
|
234
|
+
},
|
|
235
|
+
{
|
|
236
|
+
id: 'cmp_amount',
|
|
237
|
+
type: 'input-number',
|
|
238
|
+
value: null,
|
|
239
|
+
required: true,
|
|
240
|
+
min: 0,
|
|
241
|
+
max: 100000,
|
|
242
|
+
defaultValue: 500,
|
|
243
|
+
props: {
|
|
244
|
+
label: '申请金额',
|
|
245
|
+
variableName: 'amount',
|
|
246
|
+
placeholder: '请输入金额'
|
|
247
|
+
},
|
|
248
|
+
style: { width: '50%' }
|
|
249
|
+
},
|
|
250
|
+
{
|
|
251
|
+
id: 'cmp_category',
|
|
252
|
+
type: 'radio-group',
|
|
253
|
+
value: '',
|
|
254
|
+
required: true,
|
|
255
|
+
defaultValue: 'normal',
|
|
256
|
+
props: {
|
|
257
|
+
label: '申请类型',
|
|
258
|
+
variableName: 'category',
|
|
259
|
+
options: [
|
|
260
|
+
{ label: '普通采购', value: 'normal' },
|
|
261
|
+
{ label: '特殊合同', value: 'special' }
|
|
262
|
+
]
|
|
263
|
+
},
|
|
264
|
+
style: { width: '50%' }
|
|
265
|
+
},
|
|
266
|
+
{
|
|
267
|
+
id: 'cmp_urgent',
|
|
268
|
+
type: 'radio-group',
|
|
269
|
+
value: '',
|
|
270
|
+
required: true,
|
|
271
|
+
defaultValue: 'no',
|
|
272
|
+
props: {
|
|
273
|
+
label: '是否加急',
|
|
274
|
+
variableName: 'urgent',
|
|
275
|
+
options: [
|
|
276
|
+
{ label: '否', value: 'no' },
|
|
277
|
+
{ label: '是', value: 'yes' }
|
|
278
|
+
]
|
|
279
|
+
},
|
|
280
|
+
style: { width: '50%' }
|
|
281
|
+
},
|
|
282
|
+
{
|
|
283
|
+
id: 'cmp_date',
|
|
284
|
+
type: 'date-picker',
|
|
285
|
+
value: null,
|
|
286
|
+
required: true,
|
|
287
|
+
defaultValue: null,
|
|
288
|
+
props: {
|
|
289
|
+
label: '期望日期',
|
|
290
|
+
variableName: 'applyDate',
|
|
291
|
+
placeholder: '请选择日期'
|
|
292
|
+
},
|
|
293
|
+
style: { width: '50%' }
|
|
294
|
+
},
|
|
295
|
+
{
|
|
296
|
+
id: 'cmp_budget_type',
|
|
297
|
+
type: 'select',
|
|
298
|
+
value: '',
|
|
299
|
+
required: false,
|
|
300
|
+
defaultValue: '',
|
|
301
|
+
props: {
|
|
302
|
+
label: '预算科目',
|
|
303
|
+
variableName: 'budgetType',
|
|
304
|
+
placeholder: '请选择预算科目',
|
|
305
|
+
options: [
|
|
306
|
+
{ label: '市场推广', value: 'marketing' },
|
|
307
|
+
{ label: '研发投入', value: 'rd' },
|
|
308
|
+
{ label: '行政支出', value: 'admin' }
|
|
309
|
+
]
|
|
310
|
+
},
|
|
311
|
+
style: { width: '50%' }
|
|
312
|
+
},
|
|
313
|
+
{
|
|
314
|
+
id: 'cmp_invoice',
|
|
315
|
+
type: 'switch',
|
|
316
|
+
value: false,
|
|
317
|
+
required: false,
|
|
318
|
+
defaultValue: false,
|
|
319
|
+
props: {
|
|
320
|
+
label: '是否需要发票',
|
|
321
|
+
variableName: 'needInvoice',
|
|
322
|
+
activeText: '是',
|
|
323
|
+
inactiveText: '否'
|
|
324
|
+
},
|
|
325
|
+
style: { width: '50%' }
|
|
326
|
+
},
|
|
327
|
+
{
|
|
328
|
+
id: 'cmp_attachments',
|
|
329
|
+
type: 'checkbox-group',
|
|
330
|
+
value: [],
|
|
331
|
+
required: false,
|
|
332
|
+
defaultValue: [],
|
|
333
|
+
props: {
|
|
334
|
+
label: '随附材料',
|
|
335
|
+
variableName: 'attachments',
|
|
336
|
+
options: [
|
|
337
|
+
{ label: '报价单', value: 'quote' },
|
|
338
|
+
{ label: '合同草稿', value: 'contract' },
|
|
339
|
+
{ label: '资质证明', value: 'certificate' }
|
|
340
|
+
]
|
|
341
|
+
},
|
|
342
|
+
style: { width: '100%' }
|
|
343
|
+
},
|
|
344
|
+
{
|
|
345
|
+
id: 'cmp_remark',
|
|
346
|
+
type: 'textarea',
|
|
347
|
+
value: '',
|
|
348
|
+
required: false,
|
|
349
|
+
defaultValue: '',
|
|
350
|
+
props: {
|
|
351
|
+
label: '补充说明',
|
|
352
|
+
variableName: 'remark',
|
|
353
|
+
placeholder: '请输入补充说明',
|
|
354
|
+
rows: 3
|
|
355
|
+
},
|
|
356
|
+
style: { width: '100%' }
|
|
357
|
+
},
|
|
358
|
+
{
|
|
359
|
+
id: 'cmp_row',
|
|
360
|
+
type: 'row',
|
|
361
|
+
required: false,
|
|
362
|
+
props: {
|
|
363
|
+
gutter: 20,
|
|
364
|
+
columns: [{ span: 12 }, { span: 12 }]
|
|
365
|
+
},
|
|
366
|
+
children: [
|
|
367
|
+
[
|
|
368
|
+
{
|
|
369
|
+
id: 'cmp_dept',
|
|
370
|
+
type: 'input',
|
|
371
|
+
value: '',
|
|
372
|
+
required: false,
|
|
373
|
+
defaultValue: '',
|
|
374
|
+
props: { label: '需求部门', variableName: 'dept', placeholder: '请输入部门' },
|
|
375
|
+
style: { width: '100%' }
|
|
376
|
+
}
|
|
377
|
+
],
|
|
378
|
+
[
|
|
379
|
+
{
|
|
380
|
+
id: 'cmp_contact',
|
|
381
|
+
type: 'input',
|
|
382
|
+
value: '',
|
|
383
|
+
required: false,
|
|
384
|
+
defaultValue: '',
|
|
385
|
+
props: { label: '联系人', variableName: 'contact', placeholder: '请输入联系人' },
|
|
386
|
+
style: { width: '100%' }
|
|
387
|
+
}
|
|
388
|
+
]
|
|
389
|
+
]
|
|
390
|
+
}
|
|
391
|
+
]
|
|
392
|
+
|
|
393
|
+
return normalizeDefinition(
|
|
394
|
+
createDefinition({
|
|
395
|
+
workflow,
|
|
396
|
+
form,
|
|
397
|
+
meta: {
|
|
398
|
+
name: '采购申请流程',
|
|
399
|
+
description: '演示全部节点类型的示例模板',
|
|
400
|
+
tags: ['demo', 'purchase']
|
|
401
|
+
}
|
|
402
|
+
})
|
|
403
|
+
)
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
export function createSampleWorkflow() {
|
|
407
|
+
return createSampleDefinition().workflow
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
export function createSampleForm() {
|
|
411
|
+
return createSampleDefinition().form.components
|
|
412
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 预置实例:让流程中心/测试面板一进来就有数据,实例列表不为空。
|
|
3
|
+
*
|
|
4
|
+
* 这里全部走引擎的公开 API(createFlowRuntime + mock context),
|
|
5
|
+
* 不碰 FlowTestPanel 的内部状态,实例结构与面板自己创建时保持一致。
|
|
6
|
+
*/
|
|
7
|
+
import { createFlowRuntime } from '../core/flow/runtime.js'
|
|
8
|
+
import { createMockRuntimeContext, mockDepartments, mockRoles, mockUsers } from './mock.js'
|
|
9
|
+
import { createSampleDefinition } from './sample.js'
|
|
10
|
+
|
|
11
|
+
const clone = (value) => JSON.parse(JSON.stringify(value))
|
|
12
|
+
|
|
13
|
+
const definition = createSampleDefinition()
|
|
14
|
+
|
|
15
|
+
const userById = (id) => mockUsers.find((user) => String(user.id) === String(id)) || mockUsers[0]
|
|
16
|
+
|
|
17
|
+
function toInitiator(user) {
|
|
18
|
+
return {
|
|
19
|
+
id: user.id,
|
|
20
|
+
name: user.realName || user.username || String(user.id),
|
|
21
|
+
deptName: user.deptName || ''
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function pendingApprover(task) {
|
|
26
|
+
const approved = new Set((task.approvedBy || []).map((item) => String(item.id)))
|
|
27
|
+
return (task.approvers || []).find((approver) => !approved.has(String(approver.id))) || null
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** 找到第一个审批节点(示例流程里它是「部门主管审批」) */
|
|
31
|
+
function firstApproveNode(node) {
|
|
32
|
+
if (!node) return null
|
|
33
|
+
if (node.type === 'approve') return node
|
|
34
|
+
if (Array.isArray(node.branchList)) {
|
|
35
|
+
for (const branch of node.branchList) {
|
|
36
|
+
const found = firstApproveNode(branch)
|
|
37
|
+
if (found) return found
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return firstApproveNode(node.childNode)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* @param {object} options
|
|
45
|
+
* @param {number} options.seq 序号(用于名称与 id)
|
|
46
|
+
* @param {number} options.initiatorId 发起人
|
|
47
|
+
* @param {object} options.data 表单数据
|
|
48
|
+
* @param {'running'|'completed'|'rejected'} options.outcome 期望的最终状态
|
|
49
|
+
* @param {number} options.minutesAgo 创建时间往前推几分钟
|
|
50
|
+
*/
|
|
51
|
+
function buildInstance({ seq, initiatorId, data, outcome = 'running', minutesAgo = 30 }) {
|
|
52
|
+
const initiator = userById(initiatorId)
|
|
53
|
+
const context = createMockRuntimeContext({
|
|
54
|
+
initiatorId: initiator.id,
|
|
55
|
+
users: mockUsers,
|
|
56
|
+
departments: mockDepartments,
|
|
57
|
+
roles: mockRoles
|
|
58
|
+
})
|
|
59
|
+
const instanceDefinition = clone(definition)
|
|
60
|
+
// 示例流程的拒绝策略是「退回发起人」,流程会继续运行;
|
|
61
|
+
// 这里把首个审批节点改成「终止流程」,好演示「已拒绝」状态。
|
|
62
|
+
if (outcome === 'rejected') {
|
|
63
|
+
const node = firstApproveNode(instanceDefinition.workflow)
|
|
64
|
+
if (node) node.rejectStrategy = 'terminate'
|
|
65
|
+
}
|
|
66
|
+
const runtime = createFlowRuntime({ workflow: instanceDefinition.workflow, context })
|
|
67
|
+
let state = runtime.start(data, initiator)
|
|
68
|
+
|
|
69
|
+
if (outcome === 'rejected') {
|
|
70
|
+
const task = state.tasks.find((item) => item.status === 'pending')
|
|
71
|
+
const approver = task && pendingApprover(task)
|
|
72
|
+
if (task && approver) state = runtime.reject(task.id, { user: approver, comment: '预算超标,退回补充材料' })
|
|
73
|
+
} else if (outcome === 'completed') {
|
|
74
|
+
let steps = 0
|
|
75
|
+
while (state.status === 'running' && steps < 50) {
|
|
76
|
+
const task = state.tasks.find((item) => item.status === 'pending')
|
|
77
|
+
const approver = task && pendingApprover(task)
|
|
78
|
+
if (!task || !approver) break
|
|
79
|
+
state = runtime.approve(task.id, { user: approver, comment: '演示数据自动推进' })
|
|
80
|
+
steps += 1
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const createdAt = new Date(Date.now() - minutesAgo * 60 * 1000).toISOString()
|
|
85
|
+
return {
|
|
86
|
+
id: `demo_${seq}_${initiator.id}`,
|
|
87
|
+
name: `${definition.meta.name} #${String(seq).padStart(2, '0')}`,
|
|
88
|
+
definition: instanceDefinition,
|
|
89
|
+
initiatorId: initiator.id,
|
|
90
|
+
initiator: toInitiator(initiator),
|
|
91
|
+
extraCcUsers: {},
|
|
92
|
+
createdAt,
|
|
93
|
+
updatedAt: state.endedAt || createdAt,
|
|
94
|
+
state
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export function createDemoInstances() {
|
|
99
|
+
return [
|
|
100
|
+
buildInstance({
|
|
101
|
+
seq: 1,
|
|
102
|
+
initiatorId: 1,
|
|
103
|
+
minutesAgo: 15,
|
|
104
|
+
data: { amount: 8600, category: '普通采购', reason: '研发部显示器批量采购', urgent: '否', needInvoice: '是' },
|
|
105
|
+
outcome: 'running'
|
|
106
|
+
}),
|
|
107
|
+
buildInstance({
|
|
108
|
+
seq: 2,
|
|
109
|
+
initiatorId: 2,
|
|
110
|
+
minutesAgo: 180,
|
|
111
|
+
data: { amount: 12800, category: '特殊合同', reason: '设计外包合同签署', urgent: '是', needInvoice: '是' },
|
|
112
|
+
outcome: 'completed'
|
|
113
|
+
}),
|
|
114
|
+
buildInstance({
|
|
115
|
+
seq: 3,
|
|
116
|
+
initiatorId: 3,
|
|
117
|
+
minutesAgo: 320,
|
|
118
|
+
data: { amount: 46000, category: '市场推广', reason: '年度品牌推广预算', urgent: '否', needInvoice: '否' },
|
|
119
|
+
outcome: 'rejected'
|
|
120
|
+
})
|
|
121
|
+
]
|
|
122
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
const pad = (part) => String(part).padStart(2, '0')
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Formats an ISO timestamp as `YYYY-MM-DD HH:mm` (or `MM-DD HH:mm` when short).
|
|
5
|
+
* Invalid values are returned as their string form so imported data stays visible.
|
|
6
|
+
*/
|
|
7
|
+
export function formatDateTime(value, { short = false, dateOnly = false } = {}) {
|
|
8
|
+
if (!value) return ''
|
|
9
|
+
const date = new Date(value)
|
|
10
|
+
if (Number.isNaN(date.getTime())) return String(value)
|
|
11
|
+
const day = short
|
|
12
|
+
? `${pad(date.getMonth() + 1)}-${pad(date.getDate())}`
|
|
13
|
+
: `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}`
|
|
14
|
+
return dateOnly ? day : `${day} ${pad(date.getHours())}:${pad(date.getMinutes())}`
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** Human-readable rendering for form variable values in detail panels. */
|
|
18
|
+
export function formatFieldValue(value) {
|
|
19
|
+
if (value === null || value === undefined || value === '') return '—'
|
|
20
|
+
if (Array.isArray(value)) return value.length ? value.join('、') : '—'
|
|
21
|
+
if (typeof value === 'boolean') return value ? '是' : '否'
|
|
22
|
+
if (typeof value === 'string' && /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}/.test(value)) {
|
|
23
|
+
return formatDateTime(value, { dateOnly: true })
|
|
24
|
+
}
|
|
25
|
+
if (typeof value === 'object') return JSON.stringify(value)
|
|
26
|
+
return String(value)
|
|
27
|
+
}
|