Skip to content

Commit eb6f3a3

Browse files
committed
refactor: 通过ExtensionElements获取多实例类型
1 parent 175d6ba commit eb6f3a3

File tree

3 files changed

+79
-69
lines changed

3 files changed

+79
-69
lines changed

src/components/bpmnProcessDesigner/package/penal/PropertiesPanel.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
key="multiInstance"
3737
>
3838
<template #title><Icon icon="ep:help-filled" />多实例(会签配置)</template>
39-
<element-multi-instance :business-object="elementBusinessObject" :type="elementType" />
39+
<element-multi-instance :id="elementId" :business-object="elementBusinessObject" :type="elementType" />
4040
</el-collapse-item>
4141
<el-collapse-item name="listeners" key="listeners">
4242
<template #title><Icon icon="ep:bell-filled" />执行监听器</template>

src/components/bpmnProcessDesigner/package/penal/custom-config/components/UserTask.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ const resetCustomConfigList = () => {
246246
elExtensionElements.value.values?.filter(
247247
(ex) => ex.$type === `${prefix}:AssignEmptyUserIds`
248248
)?.[0] || bpmnInstances().moddle.create(`${prefix}:AssignEmptyUserIds`, { value: '' })
249-
assignEmptyUserIds.value = assignEmptyUserIdsEl.value.value.split(',').map((item) => {
249+
assignEmptyUserIds.value = assignEmptyUserIdsEl.value.value?.split(',').map((item) => {
250250
// 如果数字超出了最大安全整数范围,则将其作为字符串处理
251251
let num = Number(item)
252252
return num > Number.MAX_SAFE_INTEGER || num < -Number.MAX_SAFE_INTEGER ? item : num

src/components/bpmnProcessDesigner/package/penal/multi-instance/ElementMultiInstance.vue

Lines changed: 77 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ defineOptions({ name: 'ElementMultiInstance' })
106106
107107
const props = defineProps({
108108
businessObject: Object,
109-
type: String
109+
type: String,
110+
id: String
110111
})
111112
const prefix = inject('prefix')
112113
const loopCharacteristics = ref('')
@@ -296,25 +297,17 @@ const changeConfig = (config) => {
296297
/**
297298
* -----新版本多实例-----
298299
*/
299-
const approveMethod = ref(1)
300+
const approveMethod = ref()
300301
const approveRatio = ref(100)
301-
const getElementLoopNew = ({ loopCharacteristics }) => {
302-
if (!loopCharacteristics) {
303-
approveMethod.value = ApproveMethodType.RANDOM_SELECT_ONE_APPROVE
304-
return
305-
}
306-
if (loopCharacteristics.isSequential) {
307-
approveMethod.value = ApproveMethodType.SEQUENTIAL_APPROVE
308-
} else {
309-
if (loopCharacteristics.completionCondition.body === '${ nrOfCompletedInstances > 0 }') {
310-
approveMethod.value = ApproveMethodType.ANY_APPROVE
311-
}
312-
if (
313-
loopCharacteristics.completionCondition.body.includes('nrOfCompletedInstances/nrOfInstances')
314-
) {
315-
approveMethod.value = ApproveMethodType.APPROVE_BY_RATIO
316-
}
317-
}
302+
const otherExtensions = ref()
303+
const getElementLoopNew = () => {
304+
const extensionElements = bpmnElement.value.businessObject?.extensionElements ?? []
305+
approveMethod.value = extensionElements.values.filter(
306+
(ex) => ex.$type === `${prefix}:ApproveMethod`
307+
)?.[0]?.value
308+
309+
otherExtensions.value =
310+
extensionElements.values.filter((ex) => ex.$type !== `${prefix}:ApproveMethod`) ?? []
318311
}
319312
const onApproveMethodChange = () => {
320313
approveRatio.value = 100
@@ -324,57 +317,70 @@ const onApproveRatioChange = () => {
324317
updateLoopCharacteristics()
325318
}
326319
const updateLoopCharacteristics = () => {
320+
// 根据ApproveMethod生成multiInstanceLoopCharacteristics节点
327321
if (approveMethod.value === ApproveMethodType.RANDOM_SELECT_ONE_APPROVE) {
328322
bpmnInstances().modeling.updateProperties(toRaw(bpmnElement.value), {
329323
loopCharacteristics: null
330324
})
331-
return
332-
}
333-
if (approveMethod.value === ApproveMethodType.APPROVE_BY_RATIO) {
334-
multiLoopInstance.value = bpmnInstances().moddle.create(
335-
'bpmn:MultiInstanceLoopCharacteristics',
336-
{ isSequential: false, collection: '${coll_userList}' }
337-
)
338-
multiLoopInstance.value.completionCondition = bpmnInstances().moddle.create(
339-
'bpmn:FormalExpression',
340-
{
341-
body: '${ nrOfCompletedInstances/nrOfInstances >= ' + approveRatio.value / 100 + '}'
342-
}
343-
)
344-
}
345-
if (approveMethod.value === ApproveMethodType.ANY_APPROVE) {
346-
multiLoopInstance.value = bpmnInstances().moddle.create(
347-
'bpmn:MultiInstanceLoopCharacteristics',
348-
{ isSequential: false, collection: '${coll_userList}' }
349-
)
350-
multiLoopInstance.value.completionCondition = bpmnInstances().moddle.create(
351-
'bpmn:FormalExpression',
352-
{
353-
body: '${ nrOfCompletedInstances > 0 }'
354-
}
355-
)
356-
}
357-
if (approveMethod.value === ApproveMethodType.SEQUENTIAL_APPROVE) {
358-
multiLoopInstance.value = bpmnInstances().moddle.create(
359-
'bpmn:MultiInstanceLoopCharacteristics',
360-
{ isSequential: true, collection: '${coll_userList}' }
361-
)
362-
multiLoopInstance.value.loopCardinality = bpmnInstances().moddle.create(
363-
'bpmn:FormalExpression',
364-
{
365-
body: '1'
366-
}
367-
)
368-
multiLoopInstance.value.completionCondition = bpmnInstances().moddle.create(
369-
'bpmn:FormalExpression',
370-
{
371-
body: '${ nrOfCompletedInstances >= nrOfInstances }'
372-
}
373-
)
325+
} else {
326+
if (approveMethod.value === ApproveMethodType.APPROVE_BY_RATIO) {
327+
multiLoopInstance.value = bpmnInstances().moddle.create(
328+
'bpmn:MultiInstanceLoopCharacteristics',
329+
{ isSequential: false, collection: '${coll_userList}' }
330+
)
331+
multiLoopInstance.value.completionCondition = bpmnInstances().moddle.create(
332+
'bpmn:FormalExpression',
333+
{
334+
body: '${ nrOfCompletedInstances/nrOfInstances >= ' + approveRatio.value / 100 + '}'
335+
}
336+
)
337+
}
338+
if (approveMethod.value === ApproveMethodType.ANY_APPROVE) {
339+
multiLoopInstance.value = bpmnInstances().moddle.create(
340+
'bpmn:MultiInstanceLoopCharacteristics',
341+
{ isSequential: false, collection: '${coll_userList}' }
342+
)
343+
multiLoopInstance.value.completionCondition = bpmnInstances().moddle.create(
344+
'bpmn:FormalExpression',
345+
{
346+
body: '${ nrOfCompletedInstances > 0 }'
347+
}
348+
)
349+
}
350+
if (approveMethod.value === ApproveMethodType.SEQUENTIAL_APPROVE) {
351+
multiLoopInstance.value = bpmnInstances().moddle.create(
352+
'bpmn:MultiInstanceLoopCharacteristics',
353+
{ isSequential: true, collection: '${coll_userList}' }
354+
)
355+
multiLoopInstance.value.loopCardinality = bpmnInstances().moddle.create(
356+
'bpmn:FormalExpression',
357+
{
358+
body: '1'
359+
}
360+
)
361+
multiLoopInstance.value.completionCondition = bpmnInstances().moddle.create(
362+
'bpmn:FormalExpression',
363+
{
364+
body: '${ nrOfCompletedInstances >= nrOfInstances }'
365+
}
366+
)
367+
}
368+
bpmnInstances().modeling.updateProperties(toRaw(bpmnElement.value), {
369+
loopCharacteristics: toRaw(multiLoopInstance.value)
370+
})
374371
}
375372
373+
// 添加ApproveMethod到ExtensionElements
374+
const extensions = bpmnInstances().moddle.create('bpmn:ExtensionElements', {
375+
values: [
376+
...otherExtensions.value,
377+
bpmnInstances().moddle.create(`${prefix}:ApproveMethod`, {
378+
value: approveMethod.value
379+
})
380+
]
381+
})
376382
bpmnInstances().modeling.updateProperties(toRaw(bpmnElement.value), {
377-
loopCharacteristics: toRaw(multiLoopInstance.value)
383+
extensionElements: extensions
378384
})
379385
}
380386
@@ -384,11 +390,15 @@ onBeforeUnmount(() => {
384390
})
385391
386392
watch(
387-
() => props.businessObject,
393+
() => props.id,
388394
(val) => {
389-
bpmnElement.value = bpmnInstances().bpmnElement
390-
// getElementLoop(val)
391-
getElementLoopNew(val)
395+
if (val) {
396+
nextTick(() => {
397+
bpmnElement.value = bpmnInstances().bpmnElement
398+
// getElementLoop(val)
399+
getElementLoopNew()
400+
})
401+
}
392402
},
393403
{ immediate: true }
394404
)

0 commit comments

Comments
 (0)