gbflowengine 0.0.0-stage → 0.1.0
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 +271 -3
- package/dist/gbflowengine.css +1 -0
- package/dist/gbflowengine.js +18363 -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 +84 -6
- 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,329 @@
|
|
|
1
|
+
// [文件] gbflowengine·runtime·decide —— 发起 / 审批 / 转办 / 加签 / 重提 / 撤销
|
|
2
|
+
|
|
3
|
+
// [设计] 方法以对象字面量导出,由 runtime.js 末尾 Object.assign 装配到 FlowRuntime.prototype(同一 this,调用形状不变)。
|
|
4
|
+
|
|
5
|
+
import { SignMode } from '../flowConstant.js'
|
|
6
|
+
import { clone, normalizeApprover, sameId, taskHasApprover, taskApprovedBy, RUNNING, IDLE, CANCELLED, REVOKED } from './helpers.js'
|
|
7
|
+
export const decideMethods = {
|
|
8
|
+
|
|
9
|
+
start(initialData = null, initiator = null) {
|
|
10
|
+
if (this.state.status === RUNNING) return this.getState()
|
|
11
|
+
if (this.state.status !== IDLE) {
|
|
12
|
+
throw new Error('流程已结束,不能重复发起')
|
|
13
|
+
}
|
|
14
|
+
if (initialData) this.state.variables = { ...this.state.variables, ...clone(initialData) }
|
|
15
|
+
if (initiator) {
|
|
16
|
+
this.state.initiator = normalizeApprover(initiator, this.context.initiator?.id ?? 'initiator')
|
|
17
|
+
} else if (!this.state.initiator && this.context.initiator) {
|
|
18
|
+
this.state.initiator = normalizeApprover(this.context.initiator, 'initiator')
|
|
19
|
+
}
|
|
20
|
+
this.state.status = RUNNING
|
|
21
|
+
this.state.startedAt = this.state.startedAt || new Date().toISOString()
|
|
22
|
+
this.state.endedAt = null
|
|
23
|
+
this.state.history.push(
|
|
24
|
+
this._event('start', { nodeId: this.workflow.nodeId, initiator: this.state.initiator })
|
|
25
|
+
)
|
|
26
|
+
const token = this._createToken(this.workflow.nodeId)
|
|
27
|
+
this.state.tokens.push(token)
|
|
28
|
+
this._emit('onStart', { runtime: this, state: this.getState() })
|
|
29
|
+
this._run()
|
|
30
|
+
return this.getState()
|
|
31
|
+
},
|
|
32
|
+
|
|
33
|
+
approve(taskId, payload = {}) {
|
|
34
|
+
return this._decide(taskId, 'approve', payload)
|
|
35
|
+
},
|
|
36
|
+
|
|
37
|
+
reject(taskId, payload = {}) {
|
|
38
|
+
return this._decide(taskId, 'reject', payload)
|
|
39
|
+
},
|
|
40
|
+
|
|
41
|
+
_decide(taskId, action, payload) {
|
|
42
|
+
const task = this.state.tasks.find((item) => item.id === taskId)
|
|
43
|
+
if (!task) throw new Error(`任务不存在:${taskId}`)
|
|
44
|
+
if (task.status !== 'pending') throw new Error(`任务已处理:${taskId}`)
|
|
45
|
+
if (task.kind === 'submit') throw new Error('发起人任务请使用 resubmit 重新提交')
|
|
46
|
+
if (this.state.status !== RUNNING) throw new Error('流程当前不在运行中')
|
|
47
|
+
|
|
48
|
+
const explicitActor =
|
|
49
|
+
payload.user ??
|
|
50
|
+
payload.approver ??
|
|
51
|
+
(payload.approverId !== undefined ? { id: payload.approverId } : null)
|
|
52
|
+
if (!explicitActor) {
|
|
53
|
+
throw new Error('审批操作必须指定操作人(payload.user)')
|
|
54
|
+
}
|
|
55
|
+
const operator = normalizeApprover(explicitActor, payload.approverId || 0)
|
|
56
|
+
if (!taskHasApprover(task, operator.id)) {
|
|
57
|
+
throw new Error(`「${operator.name}」不是任务「${task.nodeName}」的审批人`)
|
|
58
|
+
}
|
|
59
|
+
if (taskApprovedBy(task, operator.id)) {
|
|
60
|
+
throw new Error(`「${operator.name}」已处理过任务「${task.nodeName}」`)
|
|
61
|
+
}
|
|
62
|
+
const node = this.getNode(task.nodeId)
|
|
63
|
+
const record = {
|
|
64
|
+
action,
|
|
65
|
+
approver: operator,
|
|
66
|
+
comment: payload.comment || '',
|
|
67
|
+
at: new Date().toISOString()
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (action === 'reject') {
|
|
71
|
+
task.status = 'rejected'
|
|
72
|
+
task.records = [...(task.records || []), record]
|
|
73
|
+
this.state.history.push(
|
|
74
|
+
this._event('reject', { nodeId: node?.nodeId, taskId, approver: operator, comment: record.comment })
|
|
75
|
+
)
|
|
76
|
+
this._handleReject(task, node, operator)
|
|
77
|
+
this._run()
|
|
78
|
+
return this.getState()
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
task.records = [...(task.records || []), record]
|
|
82
|
+
task.approvedBy = [...(task.approvedBy || []), operator]
|
|
83
|
+
this.state.history.push(
|
|
84
|
+
this._event('approve', {
|
|
85
|
+
nodeId: node?.nodeId,
|
|
86
|
+
taskId,
|
|
87
|
+
approver: operator,
|
|
88
|
+
comment: record.comment
|
|
89
|
+
})
|
|
90
|
+
)
|
|
91
|
+
|
|
92
|
+
const approved = task.approvedBy.length
|
|
93
|
+
const required = task.approvers.length || 1
|
|
94
|
+
const finished = task.signMode === SignMode.OR ? approved >= 1 : approved >= required
|
|
95
|
+
|
|
96
|
+
if (!finished) {
|
|
97
|
+
this._emit('onTaskUpdated', { runtime: this, task: clone(task), state: this.getState() })
|
|
98
|
+
return this.getState()
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
task.status = 'approved'
|
|
102
|
+
task.finishedAt = new Date().toISOString()
|
|
103
|
+
const token = this.state.tokens.find((item) => item.id === task.tokenId)
|
|
104
|
+
if (token) {
|
|
105
|
+
token.blockedTaskId = null
|
|
106
|
+
this._emit('onNodeLeave', { runtime: this, node, token: clone(token) })
|
|
107
|
+
this._advanceFrom(node, token)
|
|
108
|
+
}
|
|
109
|
+
this._emit('onTaskApproved', { runtime: this, task: clone(task), state: this.getState() })
|
|
110
|
+
this._run()
|
|
111
|
+
return this.getState()
|
|
112
|
+
},
|
|
113
|
+
|
|
114
|
+
transfer(taskId, payload = {}) {
|
|
115
|
+
const task = this.state.tasks.find((item) => item.id === taskId)
|
|
116
|
+
if (!task) throw new Error(`任务不存在:${taskId}`)
|
|
117
|
+
if (task.status !== 'pending') throw new Error(`任务已处理:${taskId}`)
|
|
118
|
+
if (task.kind === 'submit') throw new Error('发起人任务不能转交')
|
|
119
|
+
if (this.state.status !== RUNNING) throw new Error('流程当前不在运行中')
|
|
120
|
+
|
|
121
|
+
const node = this.getNode(task.nodeId)
|
|
122
|
+
if (node?.allowTransfer === false) {
|
|
123
|
+
throw new Error(`节点「${task.nodeName}」不允许转交`)
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const actorInput = payload.user || payload.fromUser || payload.approver
|
|
127
|
+
if (!actorInput) throw new Error('转交必须指定操作人(payload.user)')
|
|
128
|
+
const from = normalizeApprover(actorInput, 0)
|
|
129
|
+
if (!taskHasApprover(task, from.id)) {
|
|
130
|
+
throw new Error(`「${from.name}」不是任务「${task.nodeName}」的审批人`)
|
|
131
|
+
}
|
|
132
|
+
if (taskApprovedBy(task, from.id)) {
|
|
133
|
+
throw new Error(`「${from.name}」已同意任务「${task.nodeName}」,不能转交`)
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const targetInput = payload.toUser || payload.targetUser || payload.target
|
|
137
|
+
if (targetInput === undefined || targetInput === null) {
|
|
138
|
+
throw new Error('转交必须指定目标用户')
|
|
139
|
+
}
|
|
140
|
+
const target = normalizeApprover(targetInput, task.approvers.length + 1)
|
|
141
|
+
if (target.id === undefined || target.id === null || target.id === '') {
|
|
142
|
+
throw new Error('转交目标用户缺少 ID')
|
|
143
|
+
}
|
|
144
|
+
if (taskHasApprover(task, target.id)) {
|
|
145
|
+
throw new Error(`「${target.name}」已经是任务「${task.nodeName}」的审批人`)
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
const at = new Date().toISOString()
|
|
149
|
+
task.approvers = task.approvers.map((approver) =>
|
|
150
|
+
sameId(approver.id, from.id)
|
|
151
|
+
? { ...target, transferredFrom: { id: from.id, name: from.name } }
|
|
152
|
+
: approver
|
|
153
|
+
)
|
|
154
|
+
task.records = [
|
|
155
|
+
...(task.records || []),
|
|
156
|
+
{ action: 'transfer', approver: from, target, comment: payload.comment || '', at }
|
|
157
|
+
]
|
|
158
|
+
this.state.history.push(
|
|
159
|
+
this._event('transfer', {
|
|
160
|
+
nodeId: task.nodeId,
|
|
161
|
+
taskId,
|
|
162
|
+
approver: from,
|
|
163
|
+
target,
|
|
164
|
+
comment: payload.comment || ''
|
|
165
|
+
})
|
|
166
|
+
)
|
|
167
|
+
this._emit('onTaskTransferred', {
|
|
168
|
+
runtime: this,
|
|
169
|
+
task: clone(task),
|
|
170
|
+
from: clone(from),
|
|
171
|
+
to: clone(target),
|
|
172
|
+
state: this.getState()
|
|
173
|
+
})
|
|
174
|
+
return this.getState()
|
|
175
|
+
},
|
|
176
|
+
|
|
177
|
+
addSign(taskId, payload = {}) {
|
|
178
|
+
const task = this.state.tasks.find((item) => item.id === taskId)
|
|
179
|
+
if (!task) throw new Error(`任务不存在:${taskId}`)
|
|
180
|
+
if (task.status !== 'pending') throw new Error(`任务已处理:${taskId}`)
|
|
181
|
+
if (task.kind === 'submit') throw new Error('发起人任务不能加签')
|
|
182
|
+
if (this.state.status !== RUNNING) throw new Error('流程当前不在运行中')
|
|
183
|
+
|
|
184
|
+
const node = this.getNode(task.nodeId)
|
|
185
|
+
if (node?.allowAddSign === false) {
|
|
186
|
+
throw new Error(`节点「${task.nodeName}」不允许加签`)
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
const actorInput = payload.user || payload.approver
|
|
190
|
+
if (!actorInput) throw new Error('加签必须指定操作人(payload.user)')
|
|
191
|
+
const from = normalizeApprover(actorInput, 0)
|
|
192
|
+
if (!taskHasApprover(task, from.id)) {
|
|
193
|
+
throw new Error(`「${from.name}」不是任务「${task.nodeName}」的审批人`)
|
|
194
|
+
}
|
|
195
|
+
if (taskApprovedBy(task, from.id)) {
|
|
196
|
+
throw new Error(`「${from.name}」已同意任务「${task.nodeName}」,不能加签`)
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
const targetInput = payload.toUser || payload.targetUser || payload.target
|
|
200
|
+
if (targetInput === undefined || targetInput === null) {
|
|
201
|
+
throw new Error('加签必须指定目标用户')
|
|
202
|
+
}
|
|
203
|
+
const target = normalizeApprover(targetInput, task.approvers.length + 1)
|
|
204
|
+
if (target.id === undefined || target.id === null || target.id === '') {
|
|
205
|
+
throw new Error('加签目标用户缺少 ID')
|
|
206
|
+
}
|
|
207
|
+
if (taskHasApprover(task, target.id)) {
|
|
208
|
+
throw new Error(`「${target.name}」已经是任务「${task.nodeName}」的审批人`)
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
const at = new Date().toISOString()
|
|
212
|
+
const comment = payload.comment || ''
|
|
213
|
+
task.approvers = [...task.approvers, { ...target, addedBy: { id: from.id, name: from.name } }]
|
|
214
|
+
task.records = [
|
|
215
|
+
...(task.records || []),
|
|
216
|
+
{ action: 'addSign', approver: from, target, comment, at }
|
|
217
|
+
]
|
|
218
|
+
this.state.history.push(
|
|
219
|
+
this._event('addSign', {
|
|
220
|
+
nodeId: task.nodeId,
|
|
221
|
+
taskId,
|
|
222
|
+
approver: from,
|
|
223
|
+
target,
|
|
224
|
+
comment
|
|
225
|
+
})
|
|
226
|
+
)
|
|
227
|
+
this._emit('onTaskAddSign', {
|
|
228
|
+
runtime: this,
|
|
229
|
+
task: clone(task),
|
|
230
|
+
from: clone(from),
|
|
231
|
+
to: clone(target),
|
|
232
|
+
state: this.getState()
|
|
233
|
+
})
|
|
234
|
+
return this.getState()
|
|
235
|
+
},
|
|
236
|
+
|
|
237
|
+
resubmit(taskId, payload = {}) {
|
|
238
|
+
const task = this.state.tasks.find((item) => item.id === taskId)
|
|
239
|
+
if (!task) throw new Error(`任务不存在:${taskId}`)
|
|
240
|
+
if (task.kind !== 'submit') throw new Error(`任务「${task.nodeName}」不是发起人重新提交任务`)
|
|
241
|
+
if (task.status !== 'pending') throw new Error(`任务已处理:${taskId}`)
|
|
242
|
+
if (this.state.status !== RUNNING) throw new Error('流程当前不在运行中')
|
|
243
|
+
|
|
244
|
+
const actorInput = payload.user ?? payload.approver
|
|
245
|
+
if (!actorInput) throw new Error('重新提交必须指定操作人(payload.user)')
|
|
246
|
+
const operator = normalizeApprover(actorInput, 0)
|
|
247
|
+
if (!taskHasApprover(task, operator.id)) {
|
|
248
|
+
throw new Error(`「${operator.name}」不是该流程的发起人`)
|
|
249
|
+
}
|
|
250
|
+
if (payload.data && typeof payload.data === 'object') {
|
|
251
|
+
this.state.variables = { ...this.state.variables, ...clone(payload.data) }
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
const at = new Date().toISOString()
|
|
255
|
+
const comment = payload.comment || ''
|
|
256
|
+
task.records = [
|
|
257
|
+
...(task.records || []),
|
|
258
|
+
{ action: 'resubmit', approver: operator, comment, at }
|
|
259
|
+
]
|
|
260
|
+
task.approvedBy = [...(task.approvedBy || []), operator]
|
|
261
|
+
task.status = 'approved'
|
|
262
|
+
task.finishedAt = at
|
|
263
|
+
|
|
264
|
+
this.state.history.push(
|
|
265
|
+
this._event('resubmit', {
|
|
266
|
+
nodeId: this.workflow.nodeId,
|
|
267
|
+
taskId,
|
|
268
|
+
approver: operator,
|
|
269
|
+
comment
|
|
270
|
+
})
|
|
271
|
+
)
|
|
272
|
+
|
|
273
|
+
const token = this.state.tokens.find((item) => item.id === task.tokenId)
|
|
274
|
+
if (token) {
|
|
275
|
+
token.blockedTaskId = null
|
|
276
|
+
this._emit('onNodeLeave', { runtime: this, node: clone(this.workflow), token: clone(token) })
|
|
277
|
+
this._advanceFrom(this.workflow, token)
|
|
278
|
+
}
|
|
279
|
+
this._emit('onResubmitted', {
|
|
280
|
+
runtime: this,
|
|
281
|
+
task: clone(task),
|
|
282
|
+
state: this.getState()
|
|
283
|
+
})
|
|
284
|
+
this._run()
|
|
285
|
+
return this.getState()
|
|
286
|
+
},
|
|
287
|
+
|
|
288
|
+
/**
|
|
289
|
+
* Initiator withdraws a running instance. Distinct from cancel(), which is
|
|
290
|
+
* an administrative termination.
|
|
291
|
+
*/
|
|
292
|
+
revoke(payload = {}) {
|
|
293
|
+
if (this.state.status !== RUNNING) throw new Error('流程当前不在运行中')
|
|
294
|
+
const actorInput = payload.user ?? payload.approver ?? this.state.initiator
|
|
295
|
+
if (!actorInput) throw new Error('撤回流程必须指定操作人')
|
|
296
|
+
const operator = normalizeApprover(actorInput, 0)
|
|
297
|
+
const initiator = this.state.initiator
|
|
298
|
+
if (initiator && !sameId(initiator.id, operator.id)) {
|
|
299
|
+
throw new Error('只有发起人可以撤回流程')
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
this.state.status = REVOKED
|
|
303
|
+
this.state.endedAt = new Date().toISOString()
|
|
304
|
+
this.state.tasks.forEach((task) => {
|
|
305
|
+
if (task.status === 'pending') task.status = 'cancelled'
|
|
306
|
+
})
|
|
307
|
+
this.state.tokens = []
|
|
308
|
+
this.joinGroups.clear()
|
|
309
|
+
this.state.history.push(
|
|
310
|
+
this._event('revoke', { reason: payload.reason || '', approver: operator })
|
|
311
|
+
)
|
|
312
|
+
this._emit('onFinished', { runtime: this, status: REVOKED, state: this.getState() })
|
|
313
|
+
return this.getState()
|
|
314
|
+
},
|
|
315
|
+
|
|
316
|
+
cancel(reason = '') {
|
|
317
|
+
if (this.state.status !== RUNNING) return this.getState()
|
|
318
|
+
this.state.status = CANCELLED
|
|
319
|
+
this.state.endedAt = new Date().toISOString()
|
|
320
|
+
this.state.tasks.forEach((task) => {
|
|
321
|
+
if (task.status === 'pending') task.status = 'cancelled'
|
|
322
|
+
})
|
|
323
|
+
this.state.tokens = []
|
|
324
|
+
this.joinGroups.clear()
|
|
325
|
+
this.state.history.push(this._event('cancel', { reason }))
|
|
326
|
+
this._emit('onFinished', { runtime: this, status: CANCELLED, state: this.getState() })
|
|
327
|
+
return this.getState()
|
|
328
|
+
}
|
|
329
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// [文件] gbflowengine·runtime·event —— 事件与告警
|
|
2
|
+
|
|
3
|
+
// [设计] 方法以对象字面量导出,由 runtime.js 末尾 Object.assign 装配到 FlowRuntime.prototype(同一 this,调用形状不变)。
|
|
4
|
+
|
|
5
|
+
import { clone } from './helpers.js'
|
|
6
|
+
export const eventMethods = {
|
|
7
|
+
|
|
8
|
+
_event(event, payload = {}) {
|
|
9
|
+
this.seq.event += 1
|
|
10
|
+
return {
|
|
11
|
+
id: `event_${this.seq.event}`,
|
|
12
|
+
event,
|
|
13
|
+
at: new Date().toISOString(),
|
|
14
|
+
cycle: this.state.cycle || 1,
|
|
15
|
+
...clone(payload)
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
|
|
19
|
+
_warn(code, message) {
|
|
20
|
+
this.state.warnings.push({ code, message, at: new Date().toISOString() })
|
|
21
|
+
this._emit('onWarning', { runtime: this, code, message })
|
|
22
|
+
},
|
|
23
|
+
|
|
24
|
+
_emit(name, payload) {
|
|
25
|
+
const handler = this.handlers[name]
|
|
26
|
+
if (typeof handler === 'function') handler(payload)
|
|
27
|
+
}
|
|
28
|
+
}
|