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,748 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 流程中心的数据层:流程定义(模板)在浏览器本地的存取与版本管理。
|
|
3
|
+
*
|
|
4
|
+
* 实例数据由 FlowTestPanel 自己维护(同一存储适配层),这里只管「流程设计」这一侧的清单。
|
|
5
|
+
* 定义采用「工作副本 + 已发布快照」模型:运行中的新实例只使用最近一次发布的内容,
|
|
6
|
+
* 设计器里的修改在再次发布前不会影响新实例。
|
|
7
|
+
*/
|
|
8
|
+
import { createCustomNodeConfig, createDefinition, ensureEndNode, normalizeDefinition } from '../core/flow/index.js'
|
|
9
|
+
import { createSampleDefinition } from '../testing/sample.js'
|
|
10
|
+
import { flowStorage } from '../storage.js'
|
|
11
|
+
|
|
12
|
+
export const DEFINITION_STORAGE_KEY = 'gb-flow-center-definitions-v1'
|
|
13
|
+
export const MAX_REVISIONS = 20
|
|
14
|
+
|
|
15
|
+
const clone = (value) => JSON.parse(JSON.stringify(value))
|
|
16
|
+
|
|
17
|
+
const isUsableDefinition = (item) =>
|
|
18
|
+
Boolean(item && item.meta?.id && item.workflow && item.form)
|
|
19
|
+
|
|
20
|
+
function snapshotOf(definition, version) {
|
|
21
|
+
return {
|
|
22
|
+
version,
|
|
23
|
+
publishedAt: new Date().toISOString(),
|
|
24
|
+
name: definition.meta?.name || '未命名流程',
|
|
25
|
+
description: definition.meta?.description || '',
|
|
26
|
+
groupId: definition.meta?.groupId ?? null,
|
|
27
|
+
tags: clone(definition.meta?.tags || []),
|
|
28
|
+
business: clone(definition.meta?.business || null),
|
|
29
|
+
workflow: clone(definition.workflow),
|
|
30
|
+
form: clone(definition.form)
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function nextVersion(definition) {
|
|
35
|
+
const revisions = Array.isArray(definition.meta?.revisions) ? definition.meta.revisions : []
|
|
36
|
+
const versions = [
|
|
37
|
+
Number(definition.meta?.version) || 0,
|
|
38
|
+
...revisions.map((revision) => Number(revision.version) || 0)
|
|
39
|
+
]
|
|
40
|
+
return Math.max(...versions) + 1
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function isDefinitionRunnable(definition) {
|
|
44
|
+
const status = definition?.meta?.status
|
|
45
|
+
return !status || status === 'published'
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** New instances always start from the latest published snapshot. */
|
|
49
|
+
export function getPublishedDefinition(definition) {
|
|
50
|
+
if (!definition) return null
|
|
51
|
+
const revisions = Array.isArray(definition.meta?.revisions)
|
|
52
|
+
? definition.meta.revisions
|
|
53
|
+
: []
|
|
54
|
+
const latest = revisions[revisions.length - 1]
|
|
55
|
+
if (!latest?.workflow) return clone(definition)
|
|
56
|
+
return {
|
|
57
|
+
...clone(definition),
|
|
58
|
+
meta: {
|
|
59
|
+
...clone(definition.meta),
|
|
60
|
+
name: latest.name ?? definition.meta?.name,
|
|
61
|
+
description: latest.description ?? definition.meta?.description,
|
|
62
|
+
groupId: latest.groupId ?? definition.meta?.groupId,
|
|
63
|
+
tags: clone(latest.tags ?? definition.meta?.tags ?? []),
|
|
64
|
+
business: clone(latest.business ?? definition.meta?.business ?? null),
|
|
65
|
+
version: Number(latest.version) || 1,
|
|
66
|
+
status: 'published',
|
|
67
|
+
publishedAt: latest.publishedAt,
|
|
68
|
+
updatedAt: latest.publishedAt
|
|
69
|
+
},
|
|
70
|
+
workflow: clone(latest.workflow),
|
|
71
|
+
form: clone(latest.form || { components: [], options: {} })
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export function hasUnpublishedChanges(definition) {
|
|
76
|
+
if (!definition) return false
|
|
77
|
+
const revisions = Array.isArray(definition.meta?.revisions)
|
|
78
|
+
? definition.meta.revisions
|
|
79
|
+
: []
|
|
80
|
+
const latest = revisions[revisions.length - 1]
|
|
81
|
+
if (!latest) return true
|
|
82
|
+
const current = {
|
|
83
|
+
name: definition.meta?.name || '',
|
|
84
|
+
description: definition.meta?.description || '',
|
|
85
|
+
groupId: definition.meta?.groupId ?? null,
|
|
86
|
+
tags: definition.meta?.tags || [],
|
|
87
|
+
business: definition.meta?.business || null,
|
|
88
|
+
workflow: definition.workflow,
|
|
89
|
+
form: definition.form
|
|
90
|
+
}
|
|
91
|
+
const published = {
|
|
92
|
+
name: latest.name,
|
|
93
|
+
description: latest.description,
|
|
94
|
+
groupId: latest.groupId ?? null,
|
|
95
|
+
tags: latest.tags || [],
|
|
96
|
+
business: latest.business || null,
|
|
97
|
+
workflow: latest.workflow,
|
|
98
|
+
form: latest.form
|
|
99
|
+
}
|
|
100
|
+
return JSON.stringify(current) !== JSON.stringify(published)
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** Publishes the working copy as a new immutable revision. */
|
|
104
|
+
export function publishDefinition(list, definition) {
|
|
105
|
+
const next = normalizeDefinition(definition)
|
|
106
|
+
const version = nextVersion(next)
|
|
107
|
+
const revision = snapshotOf(next, version)
|
|
108
|
+
next.meta = {
|
|
109
|
+
...next.meta,
|
|
110
|
+
version,
|
|
111
|
+
status: 'published',
|
|
112
|
+
publishedAt: revision.publishedAt,
|
|
113
|
+
updatedAt: revision.publishedAt,
|
|
114
|
+
revisions: [...(next.meta?.revisions || []), revision].slice(-MAX_REVISIONS)
|
|
115
|
+
}
|
|
116
|
+
return upsertDefinition(list, next)
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export function disableDefinition(list, id) {
|
|
120
|
+
const index = list.findIndex((item) => String(item.meta?.id) === String(id))
|
|
121
|
+
if (index < 0) return list
|
|
122
|
+
const copy = [...list]
|
|
123
|
+
const next = clone(copy[index])
|
|
124
|
+
next.meta = { ...next.meta, status: 'disabled', updatedAt: new Date().toISOString() }
|
|
125
|
+
copy[index] = next
|
|
126
|
+
return copy
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export function rollbackDefinition(list, id, version) {
|
|
130
|
+
const current = list.find((item) => String(item.meta?.id) === String(id))
|
|
131
|
+
if (!current) throw new Error('流程定义不存在')
|
|
132
|
+
const revision = (current.meta?.revisions || []).find(
|
|
133
|
+
(item) => Number(item.version) === Number(version)
|
|
134
|
+
)
|
|
135
|
+
if (!revision) throw new Error(`未找到版本 v${version}`)
|
|
136
|
+
const restored = clone(current)
|
|
137
|
+
restored.meta = {
|
|
138
|
+
...restored.meta,
|
|
139
|
+
name: revision.name || restored.meta.name,
|
|
140
|
+
description: revision.description ?? restored.meta.description,
|
|
141
|
+
groupId: revision.groupId ?? restored.meta.groupId,
|
|
142
|
+
tags: clone(revision.tags || []),
|
|
143
|
+
business: clone(revision.business ?? restored.meta.business ?? null),
|
|
144
|
+
status: 'published'
|
|
145
|
+
}
|
|
146
|
+
restored.workflow = clone(revision.workflow)
|
|
147
|
+
restored.form = clone(revision.form)
|
|
148
|
+
return publishDefinition(list, restored)
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function businessInfo(overrides = {}) {
|
|
152
|
+
return {
|
|
153
|
+
category: '通用',
|
|
154
|
+
scenario: '',
|
|
155
|
+
slaHours: 24,
|
|
156
|
+
codePrefix: 'SP',
|
|
157
|
+
materials: [],
|
|
158
|
+
keyFields: [],
|
|
159
|
+
popularity: 50,
|
|
160
|
+
owner: '流程管理部',
|
|
161
|
+
...overrides
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function textField(id, label, variableName, options = {}) {
|
|
166
|
+
return {
|
|
167
|
+
id,
|
|
168
|
+
type: options.type || 'input',
|
|
169
|
+
value: options.value ?? '',
|
|
170
|
+
required: options.required ?? true,
|
|
171
|
+
defaultValue: options.defaultValue ?? options.value ?? '',
|
|
172
|
+
props: {
|
|
173
|
+
label,
|
|
174
|
+
variableName,
|
|
175
|
+
placeholder: options.placeholder || `请输入${label}`,
|
|
176
|
+
...(options.options ? { options: options.options } : {})
|
|
177
|
+
},
|
|
178
|
+
style: { width: options.width || '100%' },
|
|
179
|
+
...(options.extra || {})
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
function numberField(id, label, variableName, options = {}) {
|
|
184
|
+
return {
|
|
185
|
+
...textField(id, label, variableName, { ...options, type: 'input-number' }),
|
|
186
|
+
min: options.min ?? 0,
|
|
187
|
+
max: options.max ?? 10000000,
|
|
188
|
+
value: options.value ?? null,
|
|
189
|
+
defaultValue: options.defaultValue ?? null
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
function dateField(id, label, variableName, options = {}) {
|
|
194
|
+
return {
|
|
195
|
+
...textField(id, label, variableName, { ...options, type: 'date-picker' }),
|
|
196
|
+
value: null,
|
|
197
|
+
defaultValue: null
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
function selectField(id, label, variableName, options) {
|
|
202
|
+
return textField(id, label, variableName, {
|
|
203
|
+
type: 'select',
|
|
204
|
+
options,
|
|
205
|
+
placeholder: `请选择${label}`
|
|
206
|
+
})
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
function textareaField(id, label, variableName, options = {}) {
|
|
210
|
+
return textField(id, label, variableName, {
|
|
211
|
+
type: 'textarea',
|
|
212
|
+
required: options.required ?? false,
|
|
213
|
+
extra: { props: { label, variableName, placeholder: options.placeholder || `请输入${label}`, rows: 3 } }
|
|
214
|
+
})
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
function checkboxField(id, label, variableName, options) {
|
|
218
|
+
return {
|
|
219
|
+
id,
|
|
220
|
+
type: 'checkbox-group',
|
|
221
|
+
value: [],
|
|
222
|
+
required: false,
|
|
223
|
+
defaultValue: [],
|
|
224
|
+
props: { label, variableName, options },
|
|
225
|
+
style: { width: '100%' }
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
function approveNode({
|
|
230
|
+
nodeId,
|
|
231
|
+
nodeName,
|
|
232
|
+
users = [],
|
|
233
|
+
userNames = {},
|
|
234
|
+
deptNames = {},
|
|
235
|
+
roles = [],
|
|
236
|
+
roleNames = {},
|
|
237
|
+
signMode = 'or',
|
|
238
|
+
rejectStrategy = 'to_initiator',
|
|
239
|
+
allowTransfer = true,
|
|
240
|
+
childNode = null,
|
|
241
|
+
extra = {}
|
|
242
|
+
}) {
|
|
243
|
+
return {
|
|
244
|
+
nodeId,
|
|
245
|
+
nodeName,
|
|
246
|
+
type: 'approve',
|
|
247
|
+
approverType: roles.length ? 'role' : 'user',
|
|
248
|
+
userList: users,
|
|
249
|
+
userNickNames: userNames,
|
|
250
|
+
deptNameMap: deptNames,
|
|
251
|
+
roleList: roles,
|
|
252
|
+
roleNameMap: roleNames,
|
|
253
|
+
signMode,
|
|
254
|
+
superiorLevel: 1,
|
|
255
|
+
allowTransfer,
|
|
256
|
+
rejectStrategy,
|
|
257
|
+
rejectTargetNodeId: null,
|
|
258
|
+
childNode,
|
|
259
|
+
...extra
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
function buildLeaveDefinition() {
|
|
264
|
+
const workflow = {
|
|
265
|
+
nodeId: 1,
|
|
266
|
+
nodeName: '发起人',
|
|
267
|
+
type: 'start',
|
|
268
|
+
childNode: approveNode({
|
|
269
|
+
nodeId: 2,
|
|
270
|
+
nodeName: '直属主管审批',
|
|
271
|
+
users: [1, 2],
|
|
272
|
+
userNames: { 1: '张明', 2: '李婷' },
|
|
273
|
+
deptNames: { 1: '产品中心', 2: '设计部' },
|
|
274
|
+
signMode: 'or',
|
|
275
|
+
childNode: {
|
|
276
|
+
nodeId: 3,
|
|
277
|
+
nodeName: '流程结束',
|
|
278
|
+
type: 'end',
|
|
279
|
+
childNode: null
|
|
280
|
+
}
|
|
281
|
+
})
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
const form = [
|
|
285
|
+
numberField('leave_days', '请假天数', 'days', {
|
|
286
|
+
value: 1,
|
|
287
|
+
defaultValue: 1,
|
|
288
|
+
min: 0.5,
|
|
289
|
+
max: 30,
|
|
290
|
+
width: '50%'
|
|
291
|
+
}),
|
|
292
|
+
selectField('leave_type', '请假类型', 'leaveType', [
|
|
293
|
+
{ label: '事假', value: 'personal' },
|
|
294
|
+
{ label: '年假', value: 'annual' },
|
|
295
|
+
{ label: '病假', value: 'sick' }
|
|
296
|
+
]),
|
|
297
|
+
dateField('leave_start', '开始日期', 'startDate', { required: true, width: '50%' }),
|
|
298
|
+
dateField('leave_end', '结束日期', 'endDate', { required: true, width: '50%' }),
|
|
299
|
+
textareaField('leave_reason', '请假事由', 'reason', { required: true })
|
|
300
|
+
]
|
|
301
|
+
|
|
302
|
+
return normalizeDefinition(
|
|
303
|
+
createDefinition({
|
|
304
|
+
workflow,
|
|
305
|
+
form,
|
|
306
|
+
meta: {
|
|
307
|
+
id: 'flow_leave_demo',
|
|
308
|
+
name: '请假申请',
|
|
309
|
+
description: '直属主管一级审批,适用于事假、年假与病假',
|
|
310
|
+
tags: ['hr', 'demo'],
|
|
311
|
+
business: businessInfo({
|
|
312
|
+
category: '人事',
|
|
313
|
+
scenario: '事假、年假与病假申请,直属主管一级审批',
|
|
314
|
+
slaHours: 8,
|
|
315
|
+
codePrefix: 'QJ',
|
|
316
|
+
materials: ['病假需附医院证明'],
|
|
317
|
+
keyFields: [
|
|
318
|
+
{ variable: 'days', label: '请假天数', type: 'number', emphasis: true },
|
|
319
|
+
{ variable: 'leaveType', label: '请假类型' },
|
|
320
|
+
{ variable: 'startDate', label: '开始日期', type: 'date' },
|
|
321
|
+
{ variable: 'endDate', label: '结束日期', type: 'date' }
|
|
322
|
+
],
|
|
323
|
+
popularity: 82,
|
|
324
|
+
owner: '人力资源部'
|
|
325
|
+
})
|
|
326
|
+
}
|
|
327
|
+
})
|
|
328
|
+
)
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
function buildExpenseDefinition() {
|
|
332
|
+
const finance = approveNode({
|
|
333
|
+
nodeId: 5,
|
|
334
|
+
nodeName: '财务复核',
|
|
335
|
+
roles: [1],
|
|
336
|
+
roleNames: { 1: '财务专员' },
|
|
337
|
+
signMode: 'or',
|
|
338
|
+
rejectStrategy: 'to_initiator'
|
|
339
|
+
})
|
|
340
|
+
const workflow = {
|
|
341
|
+
nodeId: 1,
|
|
342
|
+
nodeName: '发起人',
|
|
343
|
+
type: 'start',
|
|
344
|
+
childNode: approveNode({
|
|
345
|
+
nodeId: 2,
|
|
346
|
+
nodeName: '直属主管审批',
|
|
347
|
+
users: [1, 2],
|
|
348
|
+
userNames: { 1: '张明', 2: '李婷' },
|
|
349
|
+
deptNames: { 1: '产品中心', 2: '设计部' },
|
|
350
|
+
signMode: 'or',
|
|
351
|
+
rejectStrategy: 'to_initiator',
|
|
352
|
+
rejectRetryLimit: 1,
|
|
353
|
+
childNode: {
|
|
354
|
+
nodeId: 3,
|
|
355
|
+
nodeName: '金额分流',
|
|
356
|
+
type: 'branch',
|
|
357
|
+
branchList: [
|
|
358
|
+
{
|
|
359
|
+
nodeId: 4,
|
|
360
|
+
nodeName: '大额费用',
|
|
361
|
+
type: 'condition',
|
|
362
|
+
conditions: [{ variable: 'amount', variableName: '报销金额', operator: '>', value: 5000, fieldType: 'integer', logic: 'AND' }],
|
|
363
|
+
childNode: finance
|
|
364
|
+
},
|
|
365
|
+
{
|
|
366
|
+
nodeId: 6,
|
|
367
|
+
nodeName: '常规费用',
|
|
368
|
+
type: 'condition',
|
|
369
|
+
isDefaultCondition: true,
|
|
370
|
+
childNode: null
|
|
371
|
+
}
|
|
372
|
+
],
|
|
373
|
+
childNode: {
|
|
374
|
+
nodeId: 7,
|
|
375
|
+
nodeName: '流程结束',
|
|
376
|
+
type: 'end',
|
|
377
|
+
childNode: null
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
})
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
const form = [
|
|
384
|
+
selectField('expense_type', '费用类型', 'expenseType', [
|
|
385
|
+
{ label: '差旅费', value: 'travel' },
|
|
386
|
+
{ label: '业务招待费', value: 'hospitality' },
|
|
387
|
+
{ label: '办公费用', value: 'office' },
|
|
388
|
+
{ label: '其他', value: 'other' }
|
|
389
|
+
]),
|
|
390
|
+
numberField('expense_amount', '报销金额', 'amount', { value: 0, defaultValue: 0, width: '50%' }),
|
|
391
|
+
dateField('expense_date', '费用发生日期', 'expenseDate', { width: '50%' }),
|
|
392
|
+
textareaField('expense_reason', '费用说明', 'reason', { required: true }),
|
|
393
|
+
checkboxField('expense_files', '随附凭证', 'attachments', [
|
|
394
|
+
{ label: '发票', value: 'invoice' },
|
|
395
|
+
{ label: '行程单', value: 'itinerary' },
|
|
396
|
+
{ label: '审批单', value: 'approval' }
|
|
397
|
+
])
|
|
398
|
+
]
|
|
399
|
+
|
|
400
|
+
return normalizeDefinition(
|
|
401
|
+
createDefinition({
|
|
402
|
+
workflow,
|
|
403
|
+
form,
|
|
404
|
+
meta: {
|
|
405
|
+
id: 'flow_expense_demo',
|
|
406
|
+
name: '费用报销',
|
|
407
|
+
description: '主管审批后按金额自动分流,大额费用需财务复核',
|
|
408
|
+
tags: ['finance', 'demo'],
|
|
409
|
+
business: businessInfo({
|
|
410
|
+
category: '财务',
|
|
411
|
+
scenario: '差旅、招待与日常费用报销,大额自动转财务复核',
|
|
412
|
+
slaHours: 48,
|
|
413
|
+
codePrefix: 'BX',
|
|
414
|
+
materials: ['发票', '行程单', '费用明细'],
|
|
415
|
+
keyFields: [
|
|
416
|
+
{ variable: 'amount', label: '报销金额', type: 'money', emphasis: true },
|
|
417
|
+
{ variable: 'expenseType', label: '费用类型' },
|
|
418
|
+
{ variable: 'expenseDate', label: '发生日期', type: 'date' },
|
|
419
|
+
{ variable: 'reason', label: '费用说明' }
|
|
420
|
+
],
|
|
421
|
+
popularity: 88,
|
|
422
|
+
owner: '财务共享中心'
|
|
423
|
+
})
|
|
424
|
+
}
|
|
425
|
+
})
|
|
426
|
+
)
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
function buildContractDefinition() {
|
|
430
|
+
const workflow = {
|
|
431
|
+
nodeId: 1,
|
|
432
|
+
nodeName: '发起人',
|
|
433
|
+
type: 'start',
|
|
434
|
+
childNode: approveNode({
|
|
435
|
+
nodeId: 2,
|
|
436
|
+
nodeName: '承办部门负责人',
|
|
437
|
+
users: [1, 2],
|
|
438
|
+
userNames: { 1: '张明', 2: '李婷' },
|
|
439
|
+
deptNames: { 1: '产品中心', 2: '设计部' },
|
|
440
|
+
signMode: 'or',
|
|
441
|
+
rejectStrategy: 'to_initiator',
|
|
442
|
+
childNode: approveNode({
|
|
443
|
+
nodeId: 3,
|
|
444
|
+
nodeName: '法务审查',
|
|
445
|
+
users: [4],
|
|
446
|
+
userNames: { 4: '陈浩' },
|
|
447
|
+
deptNames: { 4: '法务部' },
|
|
448
|
+
signMode: 'or',
|
|
449
|
+
rejectStrategy: 'to_initiator',
|
|
450
|
+
rejectRetryLimit: 1,
|
|
451
|
+
childNode: {
|
|
452
|
+
nodeId: 4,
|
|
453
|
+
nodeName: '合同金额',
|
|
454
|
+
type: 'branch',
|
|
455
|
+
branchList: [
|
|
456
|
+
{
|
|
457
|
+
nodeId: 5,
|
|
458
|
+
nodeName: '重大合同',
|
|
459
|
+
type: 'condition',
|
|
460
|
+
conditions: [{ variable: 'amount', variableName: '合同金额', operator: '>=', value: 100000, fieldType: 'integer', logic: 'AND' }],
|
|
461
|
+
childNode: approveNode({
|
|
462
|
+
nodeId: 6,
|
|
463
|
+
nodeName: '财务复核',
|
|
464
|
+
roles: [1],
|
|
465
|
+
roleNames: { 1: '财务专员' },
|
|
466
|
+
signMode: 'or',
|
|
467
|
+
rejectStrategy: 'to_initiator'
|
|
468
|
+
})
|
|
469
|
+
},
|
|
470
|
+
{
|
|
471
|
+
nodeId: 7,
|
|
472
|
+
nodeName: '一般合同',
|
|
473
|
+
type: 'condition',
|
|
474
|
+
isDefaultCondition: true,
|
|
475
|
+
childNode: null
|
|
476
|
+
}
|
|
477
|
+
],
|
|
478
|
+
childNode: {
|
|
479
|
+
nodeId: 8,
|
|
480
|
+
nodeName: '流程结束',
|
|
481
|
+
type: 'end',
|
|
482
|
+
childNode: null
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
})
|
|
486
|
+
})
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
const form = [
|
|
490
|
+
textField('contract_name', '合同名称', 'contractName', { width: '50%' }),
|
|
491
|
+
textField('contract_party', '合同相对方', 'counterparty', { width: '50%' }),
|
|
492
|
+
selectField('contract_type', '合同类型', 'contractType', [
|
|
493
|
+
{ label: '采购合同', value: 'purchase' },
|
|
494
|
+
{ label: '服务合同', value: 'service' },
|
|
495
|
+
{ label: '框架协议', value: 'framework' },
|
|
496
|
+
{ label: '其他', value: 'other' }
|
|
497
|
+
]),
|
|
498
|
+
numberField('contract_amount', '合同金额', 'amount', { value: 0, defaultValue: 0, width: '50%' }),
|
|
499
|
+
dateField('contract_sign_date', '计划签署日期', 'signDate', { width: '50%' }),
|
|
500
|
+
textareaField('contract_reason', '合作背景与说明', 'reason', { required: true }),
|
|
501
|
+
checkboxField('contract_files', '合同材料', 'attachments', [
|
|
502
|
+
{ label: '合同正文', value: 'contract' },
|
|
503
|
+
{ label: '对方资质', value: 'certificate' },
|
|
504
|
+
{ label: '用印申请', value: 'seal' }
|
|
505
|
+
])
|
|
506
|
+
]
|
|
507
|
+
|
|
508
|
+
return normalizeDefinition(
|
|
509
|
+
createDefinition({
|
|
510
|
+
workflow,
|
|
511
|
+
form,
|
|
512
|
+
meta: {
|
|
513
|
+
id: 'flow_contract_demo',
|
|
514
|
+
name: '合同审批',
|
|
515
|
+
description: '部门负责人、法务审查,重大合同追加财务复核',
|
|
516
|
+
tags: ['legal', 'finance', 'demo'],
|
|
517
|
+
business: businessInfo({
|
|
518
|
+
category: '法务',
|
|
519
|
+
scenario: '对外合同与协议签署,法务审查后按金额追加财务复核',
|
|
520
|
+
slaHours: 72,
|
|
521
|
+
codePrefix: 'HT',
|
|
522
|
+
materials: ['合同正文', '对方资质', '用印申请'],
|
|
523
|
+
keyFields: [
|
|
524
|
+
{ variable: 'contractName', label: '合同名称' },
|
|
525
|
+
{ variable: 'amount', label: '合同金额', type: 'money', emphasis: true },
|
|
526
|
+
{ variable: 'counterparty', label: '合同相对方' },
|
|
527
|
+
{ variable: 'contractType', label: '合同类型' }
|
|
528
|
+
],
|
|
529
|
+
popularity: 66,
|
|
530
|
+
owner: '法务部'
|
|
531
|
+
})
|
|
532
|
+
}
|
|
533
|
+
})
|
|
534
|
+
)
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
function buildSupplierDefinition() {
|
|
538
|
+
const workflow = {
|
|
539
|
+
nodeId: 1,
|
|
540
|
+
nodeName: '发起人',
|
|
541
|
+
type: 'start',
|
|
542
|
+
childNode: approveNode({
|
|
543
|
+
nodeId: 2,
|
|
544
|
+
nodeName: '采购负责人审批',
|
|
545
|
+
users: [1, 2],
|
|
546
|
+
userNames: { 1: '张明', 2: '李婷' },
|
|
547
|
+
deptNames: { 1: '产品中心', 2: '设计部' },
|
|
548
|
+
signMode: 'or',
|
|
549
|
+
rejectStrategy: 'to_initiator',
|
|
550
|
+
childNode: {
|
|
551
|
+
nodeId: 3,
|
|
552
|
+
nodeName: '外部风控校验',
|
|
553
|
+
type: 'custom',
|
|
554
|
+
custom: createCustomNodeConfig({
|
|
555
|
+
executorType: 'method',
|
|
556
|
+
methodKey: 'demo.verifySupplier',
|
|
557
|
+
resultVariable: 'supplierRisk',
|
|
558
|
+
onError: 'terminate',
|
|
559
|
+
timeoutMs: 10000
|
|
560
|
+
}),
|
|
561
|
+
childNode: approveNode({
|
|
562
|
+
nodeId: 4,
|
|
563
|
+
nodeName: '财务复核',
|
|
564
|
+
roles: [1],
|
|
565
|
+
roleNames: { 1: '财务专员' },
|
|
566
|
+
signMode: 'or',
|
|
567
|
+
rejectStrategy: 'to_initiator',
|
|
568
|
+
childNode: {
|
|
569
|
+
nodeId: 5,
|
|
570
|
+
nodeName: '流程结束',
|
|
571
|
+
type: 'end',
|
|
572
|
+
childNode: null
|
|
573
|
+
}
|
|
574
|
+
})
|
|
575
|
+
}
|
|
576
|
+
})
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
const form = [
|
|
580
|
+
textField('supplier_name', '供应商名称', 'supplierName', { width: '50%' }),
|
|
581
|
+
textField('supplier_credit', '统一社会信用代码', 'creditCode', { width: '50%' }),
|
|
582
|
+
selectField('supplier_type', '合作类型', 'cooperationType', [
|
|
583
|
+
{ label: '生产制造', value: 'manufacturing' },
|
|
584
|
+
{ label: '贸易代理', value: 'trading' },
|
|
585
|
+
{ label: '服务外包', value: 'service' },
|
|
586
|
+
{ label: '其他', value: 'other' }
|
|
587
|
+
]),
|
|
588
|
+
numberField('supplier_amount', '年度预计采购额', 'amount', { value: 0, defaultValue: 0, width: '50%' }),
|
|
589
|
+
textField('supplier_contact', '对接联系人', 'contact', { required: false, width: '50%' }),
|
|
590
|
+
textareaField('supplier_reason', '准入说明', 'reason', { required: true }),
|
|
591
|
+
checkboxField('supplier_files', '准入材料', 'attachments', [
|
|
592
|
+
{ label: '营业执照', value: 'license' },
|
|
593
|
+
{ label: '资质证明', value: 'certificate' },
|
|
594
|
+
{ label: '报价单', value: 'quote' }
|
|
595
|
+
])
|
|
596
|
+
]
|
|
597
|
+
|
|
598
|
+
return normalizeDefinition(
|
|
599
|
+
createDefinition({
|
|
600
|
+
workflow,
|
|
601
|
+
form,
|
|
602
|
+
meta: {
|
|
603
|
+
id: 'flow_supplier_demo',
|
|
604
|
+
name: '供应商准入',
|
|
605
|
+
description: '主管审批后调用外部风控方法,校验结果写入流程变量',
|
|
606
|
+
tags: ['purchase', 'custom', 'demo'],
|
|
607
|
+
business: businessInfo({
|
|
608
|
+
category: '采购',
|
|
609
|
+
scenario: '供应商准入,主管审批后执行外部风控方法校验',
|
|
610
|
+
slaHours: 24,
|
|
611
|
+
codePrefix: 'GYS',
|
|
612
|
+
materials: ['营业执照', '资质证明', '报价单'],
|
|
613
|
+
keyFields: [
|
|
614
|
+
{ variable: 'supplierName', label: '供应商名称' },
|
|
615
|
+
{ variable: 'amount', label: '年度预计采购额', type: 'money', emphasis: true },
|
|
616
|
+
{ variable: 'cooperationType', label: '合作类型' },
|
|
617
|
+
{ variable: 'creditCode', label: '统一社会信用代码' }
|
|
618
|
+
],
|
|
619
|
+
popularity: 58,
|
|
620
|
+
owner: '采购管理部'
|
|
621
|
+
})
|
|
622
|
+
}
|
|
623
|
+
})
|
|
624
|
+
)
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
/** 首次进入时给五条已发布示例流程,覆盖主要业务域与自定义节点 */
|
|
628
|
+
export function createSeedDefinitions() {
|
|
629
|
+
const purchase = createSampleDefinition()
|
|
630
|
+
purchase.meta = {
|
|
631
|
+
...purchase.meta,
|
|
632
|
+
id: purchase.meta.id || 'flow_purchase_demo',
|
|
633
|
+
business: businessInfo({
|
|
634
|
+
category: '采购',
|
|
635
|
+
scenario: '办公物资、设备与服务采购,按金额自动分流财务复核',
|
|
636
|
+
slaHours: 24,
|
|
637
|
+
codePrefix: 'CG',
|
|
638
|
+
materials: ['报价单', '比价记录', '合同草稿(如需)'],
|
|
639
|
+
keyFields: [
|
|
640
|
+
{ variable: 'amount', label: '申请金额', type: 'money', emphasis: true },
|
|
641
|
+
{ variable: 'category', label: '采购类型' },
|
|
642
|
+
{ variable: 'applyDate', label: '期望日期', type: 'date' },
|
|
643
|
+
{ variable: 'dept', label: '需求部门' }
|
|
644
|
+
],
|
|
645
|
+
popularity: 96,
|
|
646
|
+
owner: '采购管理部'
|
|
647
|
+
})
|
|
648
|
+
}
|
|
649
|
+
return [
|
|
650
|
+
publishDefinition([], normalizeDefinition(purchase))[0],
|
|
651
|
+
publishDefinition([], buildLeaveDefinition())[0],
|
|
652
|
+
publishDefinition([], buildExpenseDefinition())[0],
|
|
653
|
+
publishDefinition([], buildContractDefinition())[0],
|
|
654
|
+
publishDefinition([], buildSupplierDefinition())[0]
|
|
655
|
+
]
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
function ensureVersioned(definition) {
|
|
659
|
+
if (definition.meta?.revisions?.length) return definition
|
|
660
|
+
return publishDefinition([], definition)[0]
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
export async function loadDefinitions() {
|
|
664
|
+
try {
|
|
665
|
+
const list = await flowStorage.getJSON(DEFINITION_STORAGE_KEY)
|
|
666
|
+
if (Array.isArray(list)) {
|
|
667
|
+
const usable = list.filter(isUsableDefinition)
|
|
668
|
+
if (usable.length) {
|
|
669
|
+
const versioned = usable.map(ensureVersioned)
|
|
670
|
+
if (JSON.stringify(versioned) !== JSON.stringify(usable)) {
|
|
671
|
+
await saveDefinitions(versioned)
|
|
672
|
+
}
|
|
673
|
+
return versioned
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
} catch {
|
|
677
|
+
// 存档损坏时退回示例数据
|
|
678
|
+
}
|
|
679
|
+
const seed = createSeedDefinitions()
|
|
680
|
+
await saveDefinitions(seed)
|
|
681
|
+
return seed
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
export async function saveDefinitions(list) {
|
|
685
|
+
try {
|
|
686
|
+
await flowStorage.setJSON(DEFINITION_STORAGE_KEY, list)
|
|
687
|
+
} catch {
|
|
688
|
+
// 存储不可用时保持内存态可用
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
/** 新建一条空白流程(含开始与结束节点),发布前不可发起 */
|
|
693
|
+
export function createBlankDefinition(name = '未命名流程') {
|
|
694
|
+
const definition = createDefinition({
|
|
695
|
+
workflow: null,
|
|
696
|
+
form: [],
|
|
697
|
+
meta: { name, status: 'draft', version: 0, revisions: [] }
|
|
698
|
+
})
|
|
699
|
+
ensureEndNode(definition.workflow)
|
|
700
|
+
return normalizeDefinition(definition)
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
export function duplicateDefinition(source) {
|
|
704
|
+
const copy = clone(source)
|
|
705
|
+
copy.meta = {
|
|
706
|
+
...copy.meta,
|
|
707
|
+
id: `flow_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 6)}`,
|
|
708
|
+
name: `${source.meta?.name || '未命名流程'} 副本`,
|
|
709
|
+
status: 'draft',
|
|
710
|
+
version: 0,
|
|
711
|
+
revisions: [],
|
|
712
|
+
createdAt: new Date().toISOString(),
|
|
713
|
+
updatedAt: new Date().toISOString()
|
|
714
|
+
}
|
|
715
|
+
return normalizeDefinition(copy)
|
|
716
|
+
}
|
|
717
|
+
|
|
718
|
+
/** 保存(存在则更新,不存在则插入到最前),返回新列表 */
|
|
719
|
+
export function upsertDefinition(list, definition) {
|
|
720
|
+
const next = clone(definition)
|
|
721
|
+
next.meta = { ...next.meta, updatedAt: new Date().toISOString() }
|
|
722
|
+
const index = list.findIndex((item) => String(item.meta?.id) === String(next.meta?.id))
|
|
723
|
+
if (index < 0) return [next, ...list]
|
|
724
|
+
const copy = [...list]
|
|
725
|
+
copy[index] = next
|
|
726
|
+
return copy
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
export function removeDefinition(list, id) {
|
|
730
|
+
return list.filter((item) => String(item.meta?.id) !== String(id))
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
/** 导入 JSON(文件内容或对象),返回可发布的定义 */
|
|
734
|
+
export function definitionFromImport(input) {
|
|
735
|
+
const parsed = typeof input === 'string' ? JSON.parse(input) : clone(input)
|
|
736
|
+
const definition = normalizeDefinition(parsed)
|
|
737
|
+
if (!definition.meta?.id) {
|
|
738
|
+
definition.meta = { ...definition.meta, id: `flow_${Date.now().toString(36)}` }
|
|
739
|
+
}
|
|
740
|
+
if (!definition.meta?.revisions?.length) {
|
|
741
|
+
return publishDefinition([], definition)[0]
|
|
742
|
+
}
|
|
743
|
+
return definition
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
export async function clearDefinitions() {
|
|
747
|
+
await flowStorage.remove(DEFINITION_STORAGE_KEY)
|
|
748
|
+
}
|