feat: Simple设计器同步获取bpmnXml数据相关逻辑

pull/631/head
GoldenZqqq 2024-12-27 14:58:43 +08:00
parent e50cd2231c
commit a8c1fd4473
5 changed files with 84 additions and 14 deletions

View File

@ -1,6 +1,7 @@
<template>
<div v-loading="loading" class="overflow-auto">
<SimpleProcessModel
ref="simpleProcessModelRef"
v-if="processNodeTree"
:flow-node="processNodeTree"
:readonly="false"
@ -134,7 +135,7 @@ const saveSimpleFlowModel = async (simpleModelNode: SimpleFlowNode) => {
}
}
// showText
// <EFBFBD><EFBFBD><EFBFBD> showText
const validateNode = (node: SimpleFlowNode | undefined, errorNodes: SimpleFlowNode[]) => {
if (node) {
const { type, showText, conditionNodes } = node
@ -225,4 +226,19 @@ onMounted(async () => {
loading.value = false
}
})
const simpleProcessModelRef = ref()
/** 获取当前流程数据 */
const getCurrentFlowData = async () => {
if (simpleProcessModelRef.value) {
return await simpleProcessModelRef.value.getCurrentFlowData()
}
return undefined
}
defineExpose({
getCurrentFlowData,
updateModel
})
</script>

View File

@ -125,14 +125,19 @@ const validateNode = (node: SimpleFlowNode | undefined, errorNodes: SimpleFlowNo
}
/** 获取当前流程数据 */
const getCurrentFlowData = () => {
errorNodes = []
validateNode(processNodeTree.value, errorNodes)
if (errorNodes.length > 0) {
errorDialogVisible.value = true
const getCurrentFlowData = async () => {
try {
errorNodes = []
validateNode(processNodeTree.value, errorNodes)
if (errorNodes.length > 0) {
errorDialogVisible.value = true
return undefined
}
return processNodeTree.value
} catch (error) {
console.error('获取流程数据失败:', error)
return undefined
}
return processNodeTree.value
}
defineExpose({

View File

@ -76,17 +76,31 @@ const validate = async () => {
const getXmlString = async () => {
try {
if (modelData.value.type === BpmModelType.BPMN) {
console.warn('bpmnEditorRef.value', bpmnEditorRef.value)
// BPMN
if (bpmnEditorRef.value) {
const { xml } = await bpmnEditorRef.value.saveXML()
if (xml) {
//
modelData.value = {
...modelData.value,
bpmnXml: xml
}
}
return xml
}
} else {
// Simple
if (simpleEditorRef.value) {
const flowData = simpleEditorRef.value.getCurrentFlowData()
return flowData ? JSON.stringify(flowData) : undefined
const flowData = await simpleEditorRef.value.getCurrentFlowData()
if (flowData) {
const jsonData = JSON.stringify(flowData)
//
modelData.value = {
...modelData.value,
bpmnXml: jsonData
}
return jsonData
}
}
}
return undefined

View File

@ -213,8 +213,16 @@ const handleSave = async () => {
await validateAllSteps()
//
const bpmnXml = processDesignRef.value?.getXmlString()
formData.value.bpmnXml = bpmnXml
const bpmnXml = await processDesignRef.value?.getXmlString()
if (!bpmnXml) {
throw new Error('获取流程数据失败')
}
//
formData.value = {
...formData.value,
bpmnXml: bpmnXml
}
if (formData.value.id) {
//
@ -245,6 +253,8 @@ const handleSave = async () => {
params: { id: formData.value.id }
})
} catch {
//
delView(unref(router.currentRoute))
//
await router.push({ name: 'BpmModel' })
}
@ -267,8 +277,16 @@ const handleDeploy = async () => {
await validateAllSteps()
//
const bpmnXml = processDesignRef.value?.getXmlString()
formData.value.bpmnXml = bpmnXml
const bpmnXml = await processDesignRef.value?.getXmlString()
if (!bpmnXml) {
throw new Error('获取流程数据失败')
}
//
formData.value = {
...formData.value,
bpmnXml: bpmnXml
}
//
if (formData.value.id) {

View File

@ -36,5 +36,22 @@ watch([() => props.modelKey, () => props.modelName], ([newKey, newName]) => {
const handleSuccess = (data?: any) => {
emit('success', data)
}
/** 获取当前流程数据 */
const getCurrentFlowData = async () => {
try {
if (designerRef.value) {
return await designerRef.value.getCurrentFlowData()
}
return undefined
} catch (error) {
console.error('获取流程数据失败:', error)
return undefined
}
}
defineExpose({
getCurrentFlowData
})
</script>
<style lang="scss" scoped></style>