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

This commit is contained in:
GoldenZqqq
2024-12-27 14:58:43 +08:00
parent e50cd2231c
commit a8c1fd4473
5 changed files with 84 additions and 14 deletions

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>