refactor: 通过ExtensionElements获取多实例类型

pull/610/head
Lesan 2024-12-04 15:21:22 +08:00
parent 175d6ba0cb
commit eb6f3a3e49
3 changed files with 79 additions and 69 deletions

View File

@ -36,7 +36,7 @@
key="multiInstance" key="multiInstance"
> >
<template #title><Icon icon="ep:help-filled" />多实例会签配置</template> <template #title><Icon icon="ep:help-filled" />多实例会签配置</template>
<element-multi-instance :business-object="elementBusinessObject" :type="elementType" /> <element-multi-instance :id="elementId" :business-object="elementBusinessObject" :type="elementType" />
</el-collapse-item> </el-collapse-item>
<el-collapse-item name="listeners" key="listeners"> <el-collapse-item name="listeners" key="listeners">
<template #title><Icon icon="ep:bell-filled" />执行监听器</template> <template #title><Icon icon="ep:bell-filled" />执行监听器</template>

View File

@ -246,7 +246,7 @@ const resetCustomConfigList = () => {
elExtensionElements.value.values?.filter( elExtensionElements.value.values?.filter(
(ex) => ex.$type === `${prefix}:AssignEmptyUserIds` (ex) => ex.$type === `${prefix}:AssignEmptyUserIds`
)?.[0] || bpmnInstances().moddle.create(`${prefix}:AssignEmptyUserIds`, { value: '' }) )?.[0] || bpmnInstances().moddle.create(`${prefix}:AssignEmptyUserIds`, { value: '' })
assignEmptyUserIds.value = assignEmptyUserIdsEl.value.value.split(',').map((item) => { assignEmptyUserIds.value = assignEmptyUserIdsEl.value.value?.split(',').map((item) => {
// //
let num = Number(item) let num = Number(item)
return num > Number.MAX_SAFE_INTEGER || num < -Number.MAX_SAFE_INTEGER ? item : num return num > Number.MAX_SAFE_INTEGER || num < -Number.MAX_SAFE_INTEGER ? item : num

View File

@ -106,7 +106,8 @@ defineOptions({ name: 'ElementMultiInstance' })
const props = defineProps({ const props = defineProps({
businessObject: Object, businessObject: Object,
type: String type: String,
id: String
}) })
const prefix = inject('prefix') const prefix = inject('prefix')
const loopCharacteristics = ref('') const loopCharacteristics = ref('')
@ -296,25 +297,17 @@ const changeConfig = (config) => {
/** /**
* -----新版本多实例----- * -----新版本多实例-----
*/ */
const approveMethod = ref(1) const approveMethod = ref()
const approveRatio = ref(100) const approveRatio = ref(100)
const getElementLoopNew = ({ loopCharacteristics }) => { const otherExtensions = ref()
if (!loopCharacteristics) { const getElementLoopNew = () => {
approveMethod.value = ApproveMethodType.RANDOM_SELECT_ONE_APPROVE const extensionElements = bpmnElement.value.businessObject?.extensionElements ?? []
return approveMethod.value = extensionElements.values.filter(
} (ex) => ex.$type === `${prefix}:ApproveMethod`
if (loopCharacteristics.isSequential) { )?.[0]?.value
approveMethod.value = ApproveMethodType.SEQUENTIAL_APPROVE
} else { otherExtensions.value =
if (loopCharacteristics.completionCondition.body === '${ nrOfCompletedInstances > 0 }') { extensionElements.values.filter((ex) => ex.$type !== `${prefix}:ApproveMethod`) ?? []
approveMethod.value = ApproveMethodType.ANY_APPROVE
}
if (
loopCharacteristics.completionCondition.body.includes('nrOfCompletedInstances/nrOfInstances')
) {
approveMethod.value = ApproveMethodType.APPROVE_BY_RATIO
}
}
} }
const onApproveMethodChange = () => { const onApproveMethodChange = () => {
approveRatio.value = 100 approveRatio.value = 100
@ -324,57 +317,70 @@ const onApproveRatioChange = () => {
updateLoopCharacteristics() updateLoopCharacteristics()
} }
const updateLoopCharacteristics = () => { const updateLoopCharacteristics = () => {
// ApproveMethodmultiInstanceLoopCharacteristics
if (approveMethod.value === ApproveMethodType.RANDOM_SELECT_ONE_APPROVE) { if (approveMethod.value === ApproveMethodType.RANDOM_SELECT_ONE_APPROVE) {
bpmnInstances().modeling.updateProperties(toRaw(bpmnElement.value), { bpmnInstances().modeling.updateProperties(toRaw(bpmnElement.value), {
loopCharacteristics: null loopCharacteristics: null
}) })
return } else {
} if (approveMethod.value === ApproveMethodType.APPROVE_BY_RATIO) {
if (approveMethod.value === ApproveMethodType.APPROVE_BY_RATIO) { multiLoopInstance.value = bpmnInstances().moddle.create(
multiLoopInstance.value = bpmnInstances().moddle.create( 'bpmn:MultiInstanceLoopCharacteristics',
'bpmn:MultiInstanceLoopCharacteristics', { isSequential: false, collection: '${coll_userList}' }
{ isSequential: false, collection: '${coll_userList}' } )
) multiLoopInstance.value.completionCondition = bpmnInstances().moddle.create(
multiLoopInstance.value.completionCondition = bpmnInstances().moddle.create( 'bpmn:FormalExpression',
'bpmn:FormalExpression', {
{ body: '${ nrOfCompletedInstances/nrOfInstances >= ' + approveRatio.value / 100 + '}'
body: '${ nrOfCompletedInstances/nrOfInstances >= ' + approveRatio.value / 100 + '}' }
} )
) }
} if (approveMethod.value === ApproveMethodType.ANY_APPROVE) {
if (approveMethod.value === ApproveMethodType.ANY_APPROVE) { multiLoopInstance.value = bpmnInstances().moddle.create(
multiLoopInstance.value = bpmnInstances().moddle.create( 'bpmn:MultiInstanceLoopCharacteristics',
'bpmn:MultiInstanceLoopCharacteristics', { isSequential: false, collection: '${coll_userList}' }
{ isSequential: false, collection: '${coll_userList}' } )
) multiLoopInstance.value.completionCondition = bpmnInstances().moddle.create(
multiLoopInstance.value.completionCondition = bpmnInstances().moddle.create( 'bpmn:FormalExpression',
'bpmn:FormalExpression', {
{ body: '${ nrOfCompletedInstances > 0 }'
body: '${ nrOfCompletedInstances > 0 }' }
} )
) }
} if (approveMethod.value === ApproveMethodType.SEQUENTIAL_APPROVE) {
if (approveMethod.value === ApproveMethodType.SEQUENTIAL_APPROVE) { multiLoopInstance.value = bpmnInstances().moddle.create(
multiLoopInstance.value = bpmnInstances().moddle.create( 'bpmn:MultiInstanceLoopCharacteristics',
'bpmn:MultiInstanceLoopCharacteristics', { isSequential: true, collection: '${coll_userList}' }
{ isSequential: true, collection: '${coll_userList}' } )
) multiLoopInstance.value.loopCardinality = bpmnInstances().moddle.create(
multiLoopInstance.value.loopCardinality = bpmnInstances().moddle.create( 'bpmn:FormalExpression',
'bpmn:FormalExpression', {
{ body: '1'
body: '1' }
} )
) multiLoopInstance.value.completionCondition = bpmnInstances().moddle.create(
multiLoopInstance.value.completionCondition = bpmnInstances().moddle.create( 'bpmn:FormalExpression',
'bpmn:FormalExpression', {
{ body: '${ nrOfCompletedInstances >= nrOfInstances }'
body: '${ nrOfCompletedInstances >= nrOfInstances }' }
} )
) }
bpmnInstances().modeling.updateProperties(toRaw(bpmnElement.value), {
loopCharacteristics: toRaw(multiLoopInstance.value)
})
} }
// ApproveMethodExtensionElements
const extensions = bpmnInstances().moddle.create('bpmn:ExtensionElements', {
values: [
...otherExtensions.value,
bpmnInstances().moddle.create(`${prefix}:ApproveMethod`, {
value: approveMethod.value
})
]
})
bpmnInstances().modeling.updateProperties(toRaw(bpmnElement.value), { bpmnInstances().modeling.updateProperties(toRaw(bpmnElement.value), {
loopCharacteristics: toRaw(multiLoopInstance.value) extensionElements: extensions
}) })
} }
@ -384,11 +390,15 @@ onBeforeUnmount(() => {
}) })
watch( watch(
() => props.businessObject, () => props.id,
(val) => { (val) => {
bpmnElement.value = bpmnInstances().bpmnElement if (val) {
// getElementLoop(val) nextTick(() => {
getElementLoopNew(val) bpmnElement.value = bpmnInstances().bpmnElement
// getElementLoop(val)
getElementLoopNew()
})
}
}, },
{ immediate: true } { immediate: true }
) )