Browse Source

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

dap 11 months ago
parent
commit
3b8ecadc78

+ 24 - 1
src/components/BpmnView/index.vue

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

+ 16 - 5
src/views/workflow/processDefinition/components/processPreview.vue

@@ -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);
+    });
+  }
 };
 /**
  * 对外暴露子组件方法

+ 2 - 2
src/views/workflow/processDefinition/index.vue

@@ -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');
   }