fix: 修复新增流程时无法通过第三步的bpm必填校验问题

pull/631/head
GoldenZqqq 2024-12-25 14:33:21 +08:00
parent a82862be47
commit 36157a8f24
2 changed files with 35 additions and 33 deletions

View File

@ -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({

View File

@ -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 || '发布失败')
}
}
}