兰宝车间质量管理系统-前端
dap
2024-05-15 3b8ecadc78d6a247c1bd736fe37dfb7ff53badd4
refactor: 流程定义-流程图片改为bpmn组件预览
已修改3个文件
50 ■■■■ 文件已修改
src/components/BpmnView/index.vue 25 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/workflow/processDefinition/components/processPreview.vue 21 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/workflow/processDefinition/index.vue 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/components/BpmnView/index.vue
@@ -76,6 +76,28 @@
  });
};
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 @@
  }
};
defineExpose({
  init
  init,
  initXml
});
</script>
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);
    });
  }
};
/**
 * 对外暴露子组件方法
src/views/workflow/processDefinition/index.vue
@@ -403,10 +403,10 @@
//预览图片
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');
  }