fix: 修复第三步骤流程设计中点击保存模型xml保存无效问题

pull/631/head
GoldenZqqqq 2024-12-24 22:24:54 +08:00
parent ab11818ce2
commit 53841a598f
3 changed files with 59 additions and 16 deletions

View File

@ -315,6 +315,20 @@ const props = defineProps({
} }
}) })
// value,
watch(() => props.value, (newValue) => {
if (newValue && bpmnModeler) {
createNewDiagram(newValue)
}
}, { immediate: true })
// processIdprocessName
watch([() => props.processId, () => props.processName], ([newId, newName]) => {
if (newId && newName && !props.value) {
createNewDiagram(null)
}
}, { immediate: true })
provide('configGlobal', props) provide('configGlobal', props)
let bpmnModeler: any = null let bpmnModeler: any = null
const defaultZoom = ref(1) const defaultZoom = ref(1)
@ -666,18 +680,17 @@ const previewProcessJson = () => {
} }
/* ------------------------------------------------ 芋道源码 methods ------------------------------------------------------ */ /* ------------------------------------------------ 芋道源码 methods ------------------------------------------------------ */
const processSave = async () => { const processSave = async () => {
// console.log(bpmnModeler, 'bpmnModelerbpmnModelerbpmnModelerbpmnModeler') try {
const { err, xml } = await bpmnModeler.saveXML() const { err, xml } = await bpmnModeler.saveXML()
// console.log(err, 'errerrerrerrerr')
// console.log(xml, 'xmlxmlxmlxmlxml')
//
if (err) { if (err) {
// this.$modal.msgError('') ElMessage.error('保存流程设计失败,请重试!')
alert('保存模型失败,请重试!')
return return
} }
// save
emit('save', xml) emit('save', xml)
} catch (error) {
console.error(error)
ElMessage.error('保存流程设计失败,请重试!')
}
} }
/** 高亮显示 */ /** 高亮显示 */
// const highlightedCode = (previewType, previewResult) => { // const highlightedCode = (previewType, previewResult) => {

View File

@ -6,6 +6,7 @@
:model-id="modelData.id" :model-id="modelData.id"
:model-key="modelData.key" :model-key="modelData.key"
:model-name="modelData.name" :model-name="modelData.name"
:value="modelData.bpmnXml"
@success="handleDesignSuccess" @success="handleDesignSuccess"
/> />
</template> </template>
@ -17,6 +18,7 @@
:model-id="modelData.id" :model-id="modelData.id"
:model-key="modelData.key" :model-key="modelData.key"
:model-name="modelData.name" :model-name="modelData.name"
:value="modelData.bpmnXml"
@success="handleDesignSuccess" @success="handleDesignSuccess"
/> />
</template> </template>
@ -44,6 +46,13 @@ const modelData = computed({
set: (val) => emit('update:modelValue', val) set: (val) => emit('update:modelValue', val)
}) })
// modelValue,XML
watch(() => props.modelValue, (newVal) => {
if (newVal.bpmnXml) {
xmlString.value = newVal.bpmnXml
}
}, { immediate: true, deep: true })
/** 处理设计器保存成功 */ /** 处理设计器保存成功 */
const handleDesignSuccess = (bpmnXml?: string) => { const handleDesignSuccess = (bpmnXml?: string) => {
if (bpmnXml) { if (bpmnXml) {
@ -52,8 +61,8 @@ const handleDesignSuccess = (bpmnXml?: string) => {
...modelData.value, ...modelData.value,
bpmnXml bpmnXml
}) })
}
emit('success', bpmnXml) emit('success', bpmnXml)
}
} }
/** 表单校验 */ /** 表单校验 */
@ -61,14 +70,16 @@ const validate = async () => {
if (!xmlString.value) { if (!xmlString.value) {
throw new Error('请设计流程') throw new Error('请设计流程')
} }
return true
} }
/** 是否显示设计器 */ /** 是否显示设计器 */
const showDesigner = computed(() => { const showDesigner = computed(() => {
return Boolean(modelData.value.id || (modelData.value.key && modelData.value.name)) return Boolean(modelData.value.key && modelData.value.name)
}) })
defineExpose({ defineExpose({
validate validate,
getXmlString: () => xmlString.value
}) })
</script> </script>

View File

@ -173,6 +173,19 @@ const initData = async () => {
/** 保存操作 */ /** 保存操作 */
const handleSave = async () => { const handleSave = async () => {
try { try {
//
if (typeof steps[currentStep.value].validator === 'function') {
await steps[currentStep.value].validator()
}
//
if (currentStep.value === 2) {
const bpmnXml = processDesignRef.value?.getXmlString()
if (bpmnXml) {
formData.value.bpmnXml = bpmnXml
}
}
if (formData.value.id) { if (formData.value.id) {
await ModelApi.updateModel(formData.value) await ModelApi.updateModel(formData.value)
message.success('修改成功') message.success('修改成功')
@ -183,6 +196,7 @@ const handleSave = async () => {
} }
} catch (error) { } catch (error) {
console.error('保存失败:', error) console.error('保存失败:', error)
message.error(error.message || '保存失败')
} }
} }
@ -196,6 +210,13 @@ const handleDeploy = async () => {
await step.validator() await step.validator()
} }
} }
//
if (currentStep.value === 2) {
const bpmnXml = processDesignRef.value?.getXmlString()
if (bpmnXml) {
formData.value.bpmnXml = bpmnXml
}
}
await handleSave() await handleSave()
await ModelApi.deployModel(formData.value.id) await ModelApi.deployModel(formData.value.id)
message.success('发布成功') message.success('发布成功')
@ -250,8 +271,6 @@ const handleDesignSuccess = (bpmnXml?: string) => {
if (bpmnXml) { if (bpmnXml) {
formData.value.bpmnXml = bpmnXml formData.value.bpmnXml = bpmnXml
} }
handleSave() //
message.success('保存成功')
} }
/** 初始化 */ /** 初始化 */