CustomContextPad.js
8.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
import {changeElementSize} from '@/components/VueBpmn/custom/util'
import {getNewShapePosition} from 'bpmn-js/lib/features/auto-place/BpmnAutoPlaceUtil.js'
import {assign} from 'min-dash'
export default class CustomContextPad {
constructor(
config,
contextPad,
create,
elementFactory,
injector,
translate,
modeling,
bpmnFactory,
selection
) {
this.create = create
this.elementFactory = elementFactory
this.translate = translate
this.modeling = modeling
this.bpmnFactory = bpmnFactory
this.selection = selection
if (config.autoPlace !== false) {
this.autoPlace = injector.get('autoPlace', false)
}
contextPad.registerProvider(this) // // 定义这是一个contextPad
}
getContextPadEntries(element) {
// 自定义右键菜单 如果点击的是线 不出现自定义菜单
if (element.type == 'bpmn:SequenceFlow') {
return {}
}
const {
autoPlace,
create,
elementFactory,
translate,
modeling,
bpmnFactory,
selection
} = this
// 删除功能
function removeElement(e) {
modeling.removeElements([element])
}
function clickElement(e) {}
function appendTask(event, element) {
if (autoPlace) {
const shape = elementFactory.createShape({type: 'bpmn:UserTask'})
changeElementSize(shape)
autoPlace.append(element, shape)
} else {
appendTaskStart(event, element)
}
}
function appendTaskStart(event, element) {
const shape = elementFactory.createShape({type: 'bpmn:UserTask'})
changeElementSize(shape)
create.start(event, shape, element)
}
function editElement() {
// 创建编辑图标
return {
group: 'edit',
className: 'icon-custom icon-custom-edit',
title: translate('编辑'),
action: {
click: clickElement
}
}
}
function deleteElement() {
return {
group: 'edit',
className: 'icon-custom icon-custom-delete',
title: translate('删除'),
action: {
click: removeElement
}
}
}
function appendAndClickAnnotation(color) {
return function(event, element) {
const businessObject = bpmnFactory.create('bpmn:TextAnnotation')
if (color) {
businessObject.color = color
}
const shape = elementFactory.createShape({
type: 'bpmn:TextAnnotation',
businessObject
})
autoPlace.append(element, shape)
}
}
function createSignTask(append, isSequential) {
return function(event, element) {
let loopCharacteristics = bpmnFactory.create(
'bpmn:MultiInstanceLoopCharacteristics'
)
const businessObject = bpmnFactory.create('bpmn:UserTask', {
loopCharacteristics: loopCharacteristics
})
businessObject['custom'] = 1
businessObject.name = '会签并行'
if (isSequential) {
loopCharacteristics.isSequential = true
businessObject.name = '会签串行'
}
const shape = elementFactory.createShape({
type: 'bpmn:UserTask',
businessObject
})
changeElementSize(shape)
if (append) {
autoPlace.append(element, shape)
} else {
create.start(event, shape)
}
}
}
function createSubprocessCollapsed(append) {
return function (event, element) {
const businessObject = bpmnFactory.create('bpmn:CallActivity');
businessObject['custom'] = 1
businessObject.name = "外部子流程";
const shape = elementFactory.createShape({
type: 'bpmn:CallActivity',
businessObject
});
changeElementSize(shape);
if (append) {
autoPlace.append(element, shape);
} else {
create.start(event, shape);
}
}
}
// 内部子流程
function createSubprocessExpanded(append) {
return function(event, element) {
var subProcess = elementFactory.createShape({
type: 'bpmn:SubProcess',
x: 0,
y: 0,
isExpanded: true
})
var startEvent = elementFactory.createShape({
type: 'bpmn:StartEvent',
x: 40,
y: 82,
parent: subProcess
})
changeElementSize(startEvent);
changeElementSize(subProcess);
if (append) {
// 获取位置
let position = getNewShapePosition(element,subProcess);
// 创建内部子流程元素
modeling.createShape(subProcess, position, element.parent)
// 获取位置
position.x = position.x - subProcess.width/2 + 56;
// 创建内部子流程第一个开始事件shape
modeling.createShape(startEvent, position, subProcess)
// 连线
modeling.connect(element, subProcess);
} else {
create.start(event, [subProcess, startEvent])
}
// 默认选中内部子流程第一个节点
selection.select([startEvent]);
}
}
function createEndEvent(append) {
return function(event, element) {
const shape = elementFactory.createShape({type: 'bpmn:EndEvent'})
changeElementSize(shape)
if (append) {
autoPlace.append(element, shape)
} else {
create.start(event, shape)
}
}
}
function createGateWay(type, append) {
return function(event, element) {
const shape1 = elementFactory.createShape({type: type})
changeElementSize(shape1)
if (append) {
autoPlace.append(element, shape1)
if (type != 'bpmn:ExclusiveGateway') {
const shape2 = elementFactory.createShape({type: type})
changeElementSize(shape2)
autoPlace.append(element, shape2)
}
} else {
create.start(event, shape1)
}
}
}
// 创建同步
return {
'append.user-task': {
group: 'model',
className: 'bpmn-icon-user-task',
title: translate('用户任务'),
action: {
click: appendTask,
dragstart: appendTaskStart
}
},
'append.sign-task': {
group: 'model',
className: 'bpmn-icon-parallel-mi-marker',
title: translate('会签并行'),
action: {
click: createSignTask(true, false),
dragstart: createSignTask(false, false)
}
},
'append.sign-task-sequential': {
group: 'model',
className: 'bpmn-icon-sequential-mi-marker',
title: translate('会签串行'),
action: {
click: createSignTask(true, true),
dragstart: createSignTask(false, true)
}
},
'append.gateway2': {
group: 'model',
className: 'bpmn-icon-gateway-xor',
title: translate('条件网关'),
action: {
click: createGateWay('bpmn:ExclusiveGateway', true),
dragstart: createGateWay('bpmn:ExclusiveGateway', false)
}
},
'append.parallelGateway': {
group: 'model',
className: 'bpmn-icon-gateway-parallel',
title: translate('同步网关'),
action: {
click: createGateWay('bpmn:ParallelGateway', true),
dragstart: createGateWay('bpmn:ParallelGateway', false)
}
},
'append.inclusiveGateway': {
group: 'model',
className: 'bpmn-icon-gateway-or',
title: translate('条件同步网关'),
action: {
click: createGateWay('bpmn:InclusiveGateway', true),
dragstart: createGateWay('bpmn:InclusiveGateway', false)
}
},
'create.subprocess-collapsed': {
group: 'model',
className: 'bpmn-icon-subprocess-collapsed',
title: translate('外部子流程'),
action: {
click: createSubprocessCollapsed(true),
dragstart: createSubprocessCollapsed(false)
}
},
'create.subprocess-expanded': {
group: 'model',
className: 'bpmn-icon-subprocess-expanded',
title: translate('内部子流程'),
action: {
click: createSubprocessExpanded(true),
dragstart: createSubprocessExpanded(false)
}
},
'append.end-event2': {
group: 'model',
className: 'bpmn-icon-end-event-none',
title: translate('结束'),
action: {
click: createEndEvent(true),
dragstart: createEndEvent(false)
}
}
}
}
}
CustomContextPad.$inject = [
'config',
'contextPad',
'create',
'elementFactory',
'injector',
'translate',
'modeling',
'bpmnFactory',
'selection'
]