refactor: 流程定义-流程图片改为bpmn组件预览

This commit is contained in:
dap 2024-05-15 11:34:58 +08:00
parent 437bc936fd
commit 3b8ecadc78
3 changed files with 42 additions and 8 deletions

View File

@ -76,6 +76,28 @@ const init = (instanceId) => {
});
};
const initXml = (xmlStr: string) => {
loading.value = true;
bpmnVisible.value = true;
nextTick(async () => {
if (modeler.value) modeler.value.destroy();
modeler.value = new BpmnViewer({
container: canvas.value,
additionalModules: [
{
//
zoomScroll: ['value', '']
},
ZoomScrollModule,
MoveCanvasModule
] as ModuleDeclaration[]
});
xml.value = xmlStr;
await createDiagram(xml.value);
loading.value = false;
});
};
const createDiagram = async (data) => {
try {
await modeler.value.importXML(data);
@ -238,7 +260,8 @@ const gateway = (id, targetRefType, targetRefId, canvas, completed) => {
}
};
defineExpose({
init
init,
initXml
});
</script>

View File

@ -1,9 +1,7 @@
<template>
<el-dialog v-model="data.visible" title="预览" width="70%" append-to-body>
<div v-if="data.type === 'png'" style="align: center">
<el-image v-if="data.type === 'png'" :src="data.url[0]">
<div>流程图加载中 <i class="el-icon-loading"></i></div>
</el-image>
<div v-if="data.type === 'png' && data.xmlStr" style="align: center">
<BpmnViewer ref="bpmnViewerRef"></BpmnViewer>
</div>
<div v-if="data.type === 'xml'" class="xml-data">
<div v-for="(xml, index) in data.url" :key="index">
@ -17,16 +15,29 @@
</template>
<script setup lang="ts">
import BpmnViewer from '@/components/BpmnView/index.vue';
const data = reactive({
visible: false,
url: new Array<string>(),
type: ''
type: '',
xmlStr: ''
});
const bpmnViewerRef = ref<InstanceType<typeof BpmnViewer>>();
//
const openDialog = (url: string[], type: string) => {
data.visible = true;
data.url = url;
data.type = type;
/** 流程图 */
if (type === 'png') {
data.xmlStr = url.join('\n');
/** 必须放在nextTick 否则第一次打开为空 */
nextTick(() => {
bpmnViewerRef.value?.initXml(data.xmlStr);
});
}
};
/**
* 对外暴露子组件方法

View File

@ -403,10 +403,10 @@ const getProcessDefinitionHitoryList = async (id: string, key: string) => {
//
const clickPreviewImg = async (id: string) => {
loading.value = true;
const resp = await definitionImage(id);
const resp = await definitionXml(id);
if (previewRef.value) {
url.value = [];
url.value.push('data:image/png;base64,' + resp.data);
url.value = resp.data.xml;
loading.value = false;
previewRef.value.openDialog(url.value, 'png');
}