feat: 修改设计流程切换到第三步自动赋值流程标识与流程名称逻辑

pull/624/MERGE
GoldenZqqqq 2024-12-14 00:21:43 +08:00
parent 9459a7296f
commit 21c28c3665
5 changed files with 245 additions and 73 deletions

View File

@ -79,6 +79,32 @@ const processNodeTree = ref<SimpleFlowNode | undefined>()
const errorDialogVisible = ref(false)
let errorNodes: SimpleFlowNode[] = []
//
const updateModel = (key?: string, name?: string) => {
if (!processNodeTree.value) {
processNodeTree.value = {
name: name || '发起人',
type: NodeType.START_USER_NODE,
id: NodeId.START_USER_NODE_ID,
childNode: {
id: NodeId.END_EVENT_NODE_ID,
name: '结束',
type: NodeType.END_EVENT_NODE
}
}
} else if (name) {
//
processNodeTree.value.name = name
}
}
//
watch([() => props.modelKey, () => props.modelName], ([newKey, newName]) => {
if (!props.modelId && newKey && newName) {
updateModel(newKey, newName)
}
}, { immediate: true, deep: true })
const saveSimpleFlowModel = async (simpleModelNode: SimpleFlowNode) => {
if (!simpleModelNode) {
message.error('模型数据为空')

View File

@ -1,6 +1,6 @@
<template>
<div class="process-panel__container" :style="{ width: `${width}px` }">
<el-collapse v-model="activeTab">
<el-collapse v-model="activeTab" v-if="isReady">
<el-collapse-item name="base">
<!-- class="panel-tab__title" -->
<template #title>
@ -108,24 +108,16 @@ const elementBusinessObject = ref<any>({}) // 元素 businessObject 镜像,提
const conditionFormVisible = ref(false) //
const formVisible = ref(false) //
const bpmnElement = ref()
const isReady = ref(false)
provide('prefix', props.prefix)
provide('width', props.width)
const bpmnInstances = () => (window as any)?.bpmnInstances
// props.bpmnModeler initModels
const unwatchBpmn = watch(
() => props.bpmnModeler,
() => {
//
if (!props.bpmnModeler) {
console.log('缺少props.bpmnModeler')
return
}
console.log('props.bpmnModeler 有值了!!!')
const w = window as any
w.bpmnInstances = {
// bpmnInstances
const initBpmnInstances = () => {
if (!props.bpmnModeler) return false
try {
const instances = {
modeler: props.bpmnModeler,
modeling: props.bpmnModeler.get('modeling'),
moddle: props.bpmnModeler.get('moddle'),
@ -136,10 +128,46 @@ const unwatchBpmn = watch(
replace: props.bpmnModeler.get('replace'),
selection: props.bpmnModeler.get('selection')
}
//
const allInstancesExist = Object.values(instances).every(instance => instance)
if (allInstancesExist) {
const w = window as any
w.bpmnInstances = instances
return true
}
return false
} catch (error) {
console.error('初始化 bpmnInstances 失败:', error)
return false
}
}
console.log(bpmnInstances(), 'window.bpmnInstances')
getActiveElement()
unwatchBpmn()
const bpmnInstances = () => (window as any)?.bpmnInstances
// props.bpmnModeler initModels
const unwatchBpmn = watch(
() => props.bpmnModeler,
async () => {
//
if (!props.bpmnModeler) {
console.log('缺少props.bpmnModeler')
return
}
try {
// modeler
await nextTick()
if (initBpmnInstances()) {
isReady.value = true
await nextTick()
getActiveElement()
} else {
console.error('modeler 实例未完全初始化')
}
} catch (error) {
console.error('初始化失败:', error)
}
},
{
immediate: true
@ -147,6 +175,8 @@ const unwatchBpmn = watch(
)
const getActiveElement = () => {
if (!isReady.value || !props.bpmnModeler) return
// bpmn:Process
initFormOnChanged(null)
props.bpmnModeler.on('import.done', (e) => {
@ -164,8 +194,11 @@ const getActiveElement = () => {
}
})
}
//
const initFormOnChanged = (element) => {
if (!isReady.value || !bpmnInstances()) return
let activatedElement = element
if (!activatedElement) {
activatedElement =
@ -173,32 +206,36 @@ const initFormOnChanged = (element) => {
bpmnInstances().elementRegistry.find((el) => el.type === 'bpmn:Collaboration')
}
if (!activatedElement) return
console.log(`
----------
select element changed:
id: ${activatedElement.id}
type: ${activatedElement.businessObject.$type}
----------
`)
console.log('businessObject: ', activatedElement.businessObject)
bpmnInstances().bpmnElement = activatedElement
bpmnElement.value = activatedElement
elementId.value = activatedElement.id
elementType.value = activatedElement.type.split(':')[1] || ''
elementBusinessObject.value = JSON.parse(JSON.stringify(activatedElement.businessObject))
conditionFormVisible.value = !!(
elementType.value === 'SequenceFlow' &&
activatedElement.source &&
activatedElement.source.type.indexOf('StartEvent') === -1
)
formVisible.value = elementType.value === 'UserTask' || elementType.value === 'StartEvent'
try {
console.log(`
----------
select element changed:
id: ${activatedElement.id}
type: ${activatedElement.businessObject.$type}
----------
`)
console.log('businessObject: ', activatedElement.businessObject)
bpmnInstances().bpmnElement = activatedElement
bpmnElement.value = activatedElement
elementId.value = activatedElement.id
elementType.value = activatedElement.type.split(':')[1] || ''
elementBusinessObject.value = JSON.parse(JSON.stringify(activatedElement.businessObject))
conditionFormVisible.value = !!(
elementType.value === 'SequenceFlow' &&
activatedElement.source &&
activatedElement.source.type.indexOf('StartEvent') === -1
)
formVisible.value = elementType.value === 'UserTask' || elementType.value === 'StartEvent'
} catch (error) {
console.error('初始化表单数据失败:', error)
}
}
onBeforeUnmount(() => {
const w = window as any
w.bpmnInstances = null
console.log(props, 'props1')
console.log(props.bpmnModeler, 'props.bpmnModeler1')
isReady.value = false
})
watch(
@ -208,3 +245,10 @@ watch(
}
)
</script>
<style lang="scss">
.process-panel__container {
position: absolute;
top: 90px;
right: 60px;
}
</style>

View File

@ -274,6 +274,7 @@
<!-- BPMN设计器 -->
<template v-if="formData.type === BpmModelType.BPMN">
<BpmModelEditor
v-if="showDesigner"
:model-id="formData.id"
:model-key="formData.key"
:model-name="formData.name"
@ -284,6 +285,7 @@
<!-- Simple设计器 -->
<template v-else>
<SimpleModelDesign
v-if="showDesigner"
:model-id="formData.id"
:model-key="formData.key"
:model-name="formData.name"
@ -547,16 +549,43 @@ const handleDesignSuccess = (bpmnXml?: string) => {
//
const handleStepClick = async (index: number) => {
// keyname
if (index === 2 && !formData.value.id) {
//
if (!formData.value.key || !formData.value.name) {
message.warning('请先填写流程标识和流程名称')
return
if (index === 2) {
if (!formData.value.id) {
//
try {
await formRef.value?.validateField(['key', 'name'])
//
await nextTick()
} catch (error) {
message.warning('请先填写流程标识和流程名称')
return
}
}
//
await nextTick()
}
currentStep.value = index
}
//
const showDesigner = computed(() => {
return currentStep.value === 2 && Boolean(formData.value.id || (formData.value.key && formData.value.name))
})
//
watch(() => currentStep.value, async (newStep) => {
if (newStep === 2) {
await nextTick()
}
}, { immediate: false })
//
onBeforeUnmount(() => {
const w = window as any
if (w.bpmnInstances) {
w.bpmnInstances = null
}
})
</script>
<style lang="scss" scoped>

View File

@ -3,7 +3,6 @@
<!-- 流程设计器负责绘制流程等 -->
<MyProcessDesigner
key="designer"
v-if="xmlString !== undefined"
v-model="xmlString"
:value="xmlString"
v-bind="controlForm"
@ -16,8 +15,9 @@
/>
<!-- 流程属性器负责编辑每个流程节点的属性 -->
<MyProcessPenal
v-if="isModelerReady && modeler"
key="penal"
:bpmnModeler="modeler as any"
:bpmnModeler="modeler"
:prefix="controlForm.prefix"
class="process-panel"
:model="model"
@ -44,8 +44,10 @@ const props = defineProps<{
const emit = defineEmits(['success'])
const message = useMessage() //
const xmlString = ref<string>() // BPMN XML
const modeler = ref(null) // BPMN Modeler
const xmlString = ref<string>('') // BPMN XML
const modeler = shallowRef() // BPMN Modeler
const processDesigner = ref()
const isModelerReady = ref(false)
const controlForm = ref({
simulation: true,
labelEditing: false,
@ -56,11 +58,49 @@ const controlForm = ref({
})
const model = ref<ModelApi.ModelVO>() //
// bpmnInstances
const initBpmnInstances = () => {
if (!modeler.value) return false
try {
const instances = {
modeler: modeler.value,
modeling: modeler.value.get('modeling'),
moddle: modeler.value.get('moddle'),
eventBus: modeler.value.get('eventBus'),
bpmnFactory: modeler.value.get('bpmnFactory'),
elementFactory: modeler.value.get('elementFactory'),
elementRegistry: modeler.value.get('elementRegistry'),
replace: modeler.value.get('replace'),
selection: modeler.value.get('selection')
}
//
return Object.values(instances).every(instance => instance)
} catch (error) {
console.error('初始化 bpmnInstances 失败:', error)
return false
}
}
/** 初始化 modeler */
const initModeler = (item) => {
setTimeout(() => {
const initModeler = async (item) => {
try {
modeler.value = item
}, 10)
// modeler
await nextTick()
// modeler
if (initBpmnInstances()) {
isModelerReady.value = true
if (!props.modelId && props.modelKey && props.modelName) {
await updateModelData(props.modelKey, props.modelName)
}
} else {
console.error('modeler 实例未完全初始化')
}
} catch (error) {
console.error('初始化 modeler 失败:', error)
}
}
/** 获取默认的BPMN XML */
@ -97,9 +137,9 @@ const save = async (bpmnXml: string) => {
/** 初始化 */
onMounted(async () => {
if (props.modelId) {
//
try {
try {
if (props.modelId) {
//
//
const data = await ModelApi.getModel(props.modelId)
model.value = {
@ -107,30 +147,54 @@ onMounted(async () => {
bpmnXml: undefined // bpmnXml
}
xmlString.value = data.bpmnXml || getDefaultBpmnXml(data.key, data.name)
} catch (error) {
console.error('获取模型失败:', error)
message.error('获取模型失败')
} else if (props.modelKey && props.modelName) {
//
xmlString.value = getDefaultBpmnXml(props.modelKey, props.modelName)
model.value = {
key: props.modelKey,
name: props.modelName
} as ModelApi.ModelVO
}
} else if (props.modelKey && props.modelName) {
// 使keynameXML
xmlString.value = getDefaultBpmnXml(props.modelKey, props.modelName)
model.value = {
key: props.modelKey,
name: props.modelName
} as ModelApi.ModelVO
} catch (error) {
console.error('初始化失败:', error)
message.error('初始化失败')
}
})
// keyname
watch([() => props.modelKey, () => props.modelName], ([newKey, newName]) => {
if (!props.modelId && newKey && newName) {
xmlString.value = getDefaultBpmnXml(newKey, newName)
//
const updateModelData = async (key?: string, name?: string) => {
if (key && name) {
xmlString.value = getDefaultBpmnXml(key, name)
model.value = {
key: newKey,
name: newName
...model.value,
key: key,
name: name
} as ModelApi.ModelVO
//
await nextTick()
if (processDesigner.value?.refresh) {
processDesigner.value.refresh()
}
}
}, { immediate: true })
}
// keyname
watch([() => props.modelKey, () => props.modelName], async ([newKey, newName]) => {
if (!props.modelId && newKey && newName && modeler.value) {
await updateModelData(newKey, newName)
}
}, { immediate: true, deep: true })
//
onBeforeUnmount(() => {
isModelerReady.value = false
modeler.value = null
//
const w = window as any
if (w.bpmnInstances) {
w.bpmnInstances = null
}
})
</script>
<style lang="scss">
.process-panel__container {

View File

@ -5,6 +5,7 @@
:model-key="modelKey"
:model-name="modelName"
@success="handleSuccess"
ref="designerRef"
/>
</ContentWrap>
</template>
@ -15,13 +16,21 @@ defineOptions({
name: 'SimpleModelDesign'
})
defineProps<{
const props = defineProps<{
modelId?: string
modelKey?: string
modelName?: string
}>()
const emit = defineEmits(['success'])
const designerRef = ref()
//
watch([() => props.modelKey, () => props.modelName], ([newKey, newName]) => {
if (designerRef.value && newKey && newName) {
designerRef.value.updateModel(newKey, newName)
}
}, { immediate: true, deep: true })
//
const handleSuccess = (data?: any) => {