feat: 优化保存/提交按钮样式与完善保存/提交后的确认逻辑

pull/631/head
GoldenZqqq 2024-12-27 11:50:56 +08:00
parent 6cf3de0166
commit 40c2cb72ff
1 changed files with 112 additions and 49 deletions

View File

@ -44,8 +44,8 @@
<!-- 右侧按钮 -->
<div class="w-200px flex items-center justify-end gap-2">
<el-button @click="handleSave"> </el-button>
<el-button type="primary" @click="handleDeploy"> </el-button>
<el-button v-if="route.params.id" type="success" @click="handleDeploy"> </el-button>
<el-button type="primary" @click="handleSave"> </el-button>
</div>
</div>
@ -90,8 +90,10 @@ import { BpmModelType, BpmModelFormType } from '@/utils/constants'
import BasicInfo from './BasicInfo.vue'
import FormDesign from './FormDesign.vue'
import ProcessDesign from './ProcessDesign.vue'
import { useTagsViewStore } from '@/store/modules/tagsView'
const router = useRouter()
const { delView } = useTagsViewStore() //
const route = useRoute()
const message = useMessage()
const userStore = useUserStoreWithOut()
@ -102,24 +104,24 @@ const formDesignRef = ref()
const processDesignRef = ref()
/** 步骤校验函数 */
const validateStep1 = async () => {
const validateBasic = async () => {
await basicInfoRef.value?.validate()
}
const validateStep2 = async () => {
const validateForm = async () => {
await formDesignRef.value?.validate()
}
const validateStep3 = async () => {
const validateProcess = async () => {
await processDesignRef.value?.validate()
}
//
const currentStep = ref(0)
const steps = [
{ title: '基本信息', validator: validateStep1 },
{ title: '表单设计', validator: validateStep2 },
{ title: '流程设计', validator: validateStep3 }
{ title: '基本信息', validator: validateBasic },
{ title: '表单设计', validator: validateForm },
{ title: '流程设计', validator: validateProcess }
]
//
@ -166,71 +168,124 @@ const initData = async () => {
userList.value = await UserApi.getSimpleUserList()
}
/** 校验所有步骤数据是否完整 */
const validateAllSteps = async () => {
try {
//
await basicInfoRef.value?.validate()
if (!formData.value.key || !formData.value.name || !formData.value.category) {
currentStep.value = 0
throw new Error('请完善基本信息')
}
//
await formDesignRef.value?.validate()
if (formData.value.formType === 10 && !formData.value.formId) {
currentStep.value = 1
throw new Error('请选择流程表单')
}
if (
formData.value.formType === 20 &&
(!formData.value.formCustomCreatePath || !formData.value.formCustomViewPath)
) {
currentStep.value = 1
throw new Error('请完善自定义表单信息')
}
//
await processDesignRef.value?.validate()
const bpmnXml = processDesignRef.value?.getXmlString()
if (!bpmnXml) {
currentStep.value = 2
throw new Error('请设计流程')
}
return true
} catch (error) {
throw error
}
}
/** 保存操作 */
const handleSave = async () => {
try {
//
for (const step of steps) {
if (step.validator) {
await step.validator()
}
}
//
await validateAllSteps()
//
if (currentStep.value === 2) {
await nextTick()
const bpmnXml = processDesignRef.value?.getXmlString()
// XML
if (!bpmnXml) {
throw new Error('请设计流程')
}
formData.value.bpmnXml = bpmnXml
}
//
const bpmnXml = processDesignRef.value?.getXmlString()
formData.value.bpmnXml = bpmnXml
if (formData.value.id) {
//
await ModelApi.updateModel(formData.value)
message.success('修改成功')
//
try {
await message.confirm('修改流程成功,是否发布流程?')
//
await handleDeploy()
} catch {
//
}
} else {
//
const result = await ModelApi.createModel(formData.value)
formData.value.id = result.id
formData.value.id = result
message.success('新增成功')
try {
await message.confirm('创建流程成功,是否继续编辑?')
//
await nextTick()
//
delView(unref(router.currentRoute))
//
await router.push({
name: 'BpmModelUpdate',
params: { id: formData.value.id }
})
} catch {
//
await router.push({ name: 'BpmModel' })
}
}
} catch (error) {
} catch (error: any) {
console.error('保存失败:', error)
message.error(error.message || '保存失败')
throw error
message.warning(error.message || '请完善所有步骤的必填信息')
}
}
/** 发布操作 */
const handleDeploy = async () => {
try {
await message.confirm('是否确认发布该流程?')
//
if (!formData.value.id) {
await message.confirm('是否确认发布该流程?')
}
//
await validateAllSteps()
//
const bpmnXml = processDesignRef.value?.getXmlString()
formData.value.bpmnXml = bpmnXml
//
await handleSave()
if (formData.value.id) {
await ModelApi.updateModel(formData.value)
} else {
const result = await ModelApi.createModel(formData.value)
formData.value.id = result.id
}
//
await ModelApi.deployModel(formData.value.id)
message.success('发布成功')
//
router.push({ name: 'BpmModel' })
} catch (error) {
} catch (error: any) {
console.error('发布失败:', error)
if (error instanceof Error) {
// ,
const failedStep = steps.findIndex((step) => {
try {
step.validator && step.validator()
return false
} catch {
return true
}
})
if (failedStep !== -1) {
currentStep.value = failedStep
message.warning('请完善必填信息')
} else {
message.error(error.message || '发布失败')
}
}
message.warning(error.message || '发布失败')
}
}
@ -243,7 +298,7 @@ const handleStepClick = async (index: number) => {
return
}
}
//
if (index > currentStep.value) {
try {
@ -271,6 +326,14 @@ const handleDesignSuccess = (bpmnXml?: string) => {
onMounted(async () => {
await initData()
})
//
onBeforeUnmount(() => {
//
basicInfoRef.value = null
formDesignRef.value = null
processDesignRef.value = null
})
</script>
<style lang="scss" scoped>