From 36157a8f24502d84e31696a5a258da33580a3bba Mon Sep 17 00:00:00 2001 From: GoldenZqqq <1361001127@qq.com> Date: Wed, 25 Dec 2024 14:33:21 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E6=B5=81=E7=A8=8B=E6=97=B6=E6=97=A0=E6=B3=95=E9=80=9A=E8=BF=87?= =?UTF-8?q?=E7=AC=AC=E4=B8=89=E6=AD=A5=E7=9A=84bpm=E5=BF=85=E5=A1=AB?= =?UTF-8?q?=E6=A0=A1=E9=AA=8C=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/bpm/model/form/ProcessDesign.vue | 22 ++++++----- src/views/bpm/model/form/index.vue | 46 +++++++++++----------- 2 files changed, 35 insertions(+), 33 deletions(-) diff --git a/src/views/bpm/model/form/ProcessDesign.vue b/src/views/bpm/model/form/ProcessDesign.vue index 7ee58092..2e8f94c9 100644 --- a/src/views/bpm/model/form/ProcessDesign.vue +++ b/src/views/bpm/model/form/ProcessDesign.vue @@ -50,7 +50,7 @@ const modelData = computed({ watch( () => props.modelValue, (newVal) => { - if (newVal.bpmnXml) { + if (newVal?.bpmnXml) { xmlString.value = newVal.bpmnXml } }, @@ -61,24 +61,29 @@ watch( const handleDesignSuccess = (bpmnXml?: string) => { if (bpmnXml) { xmlString.value = bpmnXml - emit('update:modelValue', { + modelData.value = { ...modelData.value, bpmnXml - }) + } emit('success', bpmnXml) } } /** 表单校验 */ const validate = async () => { - // 修改场景下,如果已有 modelData.bpmnXml 则不需要重新校验 - if (modelData.value.id && modelData.value.bpmnXml) { + // 获取最新的XML数据 + const currentXml = xmlString.value || modelData.value?.bpmnXml + + // 如果是修改场景且有XML数据(无论是新的还是原有的) + if (modelData.value.id && currentXml) { return true } - // 新增场景或无 bpmnXml 时才校验 - if (!xmlString.value) { + + // 新增场景必须有XML数据 + if (!currentXml) { throw new Error('请设计流程') } + return true } @@ -89,8 +94,7 @@ const showDesigner = computed(() => { /** 获取当前XML字符串 */ const getXmlString = () => { - // 优先返回最新的 xmlString - return xmlString.value || modelData.value?.bpmnXml + return xmlString.value || modelData.value?.bpmnXml || '' } defineExpose({ diff --git a/src/views/bpm/model/form/index.vue b/src/views/bpm/model/form/index.vue index 47016ac3..f6c2ef2a 100644 --- a/src/views/bpm/model/form/index.vue +++ b/src/views/bpm/model/form/index.vue @@ -169,19 +169,24 @@ const initData = async () => { /** 保存操作 */ const handleSave = async () => { 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 + // 保存前确保所有步骤的数据都已经验证通过 + for (const step of steps) { + if (step.validator) { + await step.validator() } } - + + // 如果是在第三步,需要先获取最新的流程设计数据 + if (currentStep.value === 2) { + await nextTick() + const bpmnXml = processDesignRef.value?.getXmlString() + // 确保有XML数据 + if (!bpmnXml) { + throw new Error('请设计流程') + } + formData.value.bpmnXml = bpmnXml + } + if (formData.value.id) { await ModelApi.updateModel(formData.value) message.success('修改成功') @@ -193,6 +198,7 @@ const handleSave = async () => { } catch (error) { console.error('保存失败:', error) message.error(error.message || '保存失败') + throw error } } @@ -200,24 +206,14 @@ const handleSave = async () => { const handleDeploy = async () => { try { await message.confirm('是否确认发布该流程?') - // 发布时才进行全部校验 - for (const step of steps) { - if (step.validator) { - await step.validator() - } - } - // 如果是第三步,需要先获取最新的流程设计数据 - if (currentStep.value === 2) { - const bpmnXml = processDesignRef.value?.getXmlString() - if (bpmnXml) { - formData.value.bpmnXml = bpmnXml - } - } + // 先保存所有数据 await handleSave() + // 发布 await ModelApi.deployModel(formData.value.id) message.success('发布成功') router.push({ name: 'BpmModel' }) } catch (error) { + console.error('发布失败:', error) if (error instanceof Error) { // 校验失败时,跳转到对应步骤 const failedStep = steps.findIndex((step) => { @@ -231,6 +227,8 @@ const handleDeploy = async () => { if (failedStep !== -1) { currentStep.value = failedStep message.warning('请完善必填信息') + } else { + message.error(error.message || '发布失败') } } }