Commit 7bc36a09fbe9ac550b4484cbc5d8719d1ed124cb

Authored by YunaiV
1 parent 38221a3e

增加流程图的预览界面

yudao-admin-ui/src/components/bpmnProcessDesigner/package/designer/ProcessViewer.vue 0 → 100644
  1 +<template>
  2 + <div class="my-process-designer">
  3 + <div class="my-process-designer__container">
  4 + <div class="my-process-designer__canvas" ref="bpmn-canvas"></div>
  5 + </div>
  6 + </div>
  7 +</template>
  8 +
  9 +<script>
  10 +import BpmnViewer from "bpmn-js/lib/Viewer";
  11 +import DefaultEmptyXML from "./plugins/defaultEmpty";
  12 +
  13 +export default {
  14 + name: "MyProcessViewer",
  15 + componentName: "MyProcessViewer",
  16 + props: {
  17 + value: String, // xml 字符串
  18 + prefix: {
  19 + type: String,
  20 + default: "camunda"
  21 + }
  22 + },
  23 + data() {
  24 + return {};
  25 + },
  26 + mounted() {
  27 + this.initBpmnModeler();
  28 + this.createNewDiagram(this.value);
  29 + this.$once("hook:beforeDestroy", () => {
  30 + if (this.bpmnModeler) this.bpmnModeler.destroy();
  31 + this.$emit("destroy", this.bpmnModeler);
  32 + this.bpmnModeler = null;
  33 + });
  34 + },
  35 + watch: {
  36 + value: function (newValue) { // 在 xmlString 发生变化时,重新创建,从而绘制流程图
  37 + this.createNewDiagram(newValue);
  38 + }
  39 + },
  40 + methods: {
  41 + initBpmnModeler() {
  42 + if (this.bpmnModeler) return;
  43 + this.bpmnModeler = new BpmnViewer({
  44 + container: this.$refs["bpmn-canvas"]
  45 + })
  46 + },
  47 + /* 创建新的流程图 */
  48 + async createNewDiagram(xml) {
  49 + // 将字符串转换成图显示出来
  50 + let newId = `Process_${new Date().getTime()}`;
  51 + let newName = `业务流程_${new Date().getTime()}`;
  52 + let xmlString = xml || DefaultEmptyXML(newId, newName, this.prefix);
  53 + try {
  54 + console.log(this.bpmnModeler.importXML);
  55 + let { warnings } = await this.bpmnModeler.importXML(xmlString);
  56 + if (warnings && warnings.length) {
  57 + warnings.forEach(warn => console.warn(warn));
  58 + }
  59 + } catch (e) {
  60 + console.error(`[Process Designer Warn]: ${e?.message || e}`);
  61 + }
  62 + }
  63 + }
  64 +};
  65 +</script>
yudao-admin-ui/src/components/bpmnProcessDesigner/package/designer/index2.js 0 → 100644
  1 +import MyProcessViewer from "./ProcessViewer.vue";
  2 +
  3 +MyProcessViewer.install = function(Vue) {
  4 + Vue.component(MyProcessViewer.name, MyProcessViewer);
  5 +};
  6 +
  7 +export default MyProcessViewer;
yudao-admin-ui/src/components/bpmnProcessDesigner/package/index.js
1 import MyProcessDesigner from "./designer"; 1 import MyProcessDesigner from "./designer";
2 import MyProcessPenal from "./penal"; 2 import MyProcessPenal from "./penal";
  3 +import MyProcessViewer from './designer/index2';
3 4
4 -const components = [MyProcessDesigner, MyProcessPenal]; 5 +const components = [MyProcessDesigner, MyProcessPenal, MyProcessViewer];
5 6
6 const install = function(Vue) { 7 const install = function(Vue) {
7 components.forEach(component => { 8 components.forEach(component => {
yudao-admin-ui/src/router/index.js
@@ -176,6 +176,19 @@ export const constantRoutes = [ @@ -176,6 +176,19 @@ export const constantRoutes = [
176 } 176 }
177 ] 177 ]
178 }, 178 },
  179 + {
  180 + path: '/bpm',
  181 + component: Layout,
  182 + hidden: true, // TODO 芋艿:未来可删除,暂时作为一个测试页
  183 + children: [
  184 + {
  185 + path: 'manager/model/view',
  186 + component: (resolve) => require(['@/views/bpm/model/modelViewer'], resolve),
  187 + name: '流程模型-浏览',
  188 + meta: { title: '流程模型-浏览' }
  189 + }
  190 + ]
  191 + },
179 ] 192 ]
180 193
181 export default new Router({ 194 export default new Router({
yudao-admin-ui/src/views/bpm/model/index.vue
@@ -34,7 +34,13 @@ @@ -34,7 +34,13 @@
34 <!-- 列表 --> 34 <!-- 列表 -->
35 <el-table v-loading="loading" :data="list"> 35 <el-table v-loading="loading" :data="list">
36 <el-table-column label="流程标识" align="center" prop="key" /> 36 <el-table-column label="流程标识" align="center" prop="key" />
37 - <el-table-column label="流程名称" align="center" prop="name" /> 37 + <el-table-column label="流程名称" align="center" prop="name">
  38 + <template slot-scope="scope">
  39 + <el-button type="text" @click="handleBpmnDetail(scope.row)">
  40 + <span>{{ scope.row.name }}</span>
  41 + </el-button>
  42 + </template>
  43 + </el-table-column>
38 <el-table-column label="流程分类" align="center" prop="category"> 44 <el-table-column label="流程分类" align="center" prop="category">
39 <template slot-scope="scope"> 45 <template slot-scope="scope">
40 <span>{{ getDictDataLabel(DICT_TYPE.BPM_MODEL_CATEGORY, scope.row.category) }}</span> 46 <span>{{ getDictDataLabel(DICT_TYPE.BPM_MODEL_CATEGORY, scope.row.category) }}</span>
@@ -69,15 +75,18 @@ @@ -69,15 +75,18 @@
69 75
70 <!-- 流程表单配置详情 --> 76 <!-- 流程表单配置详情 -->
71 <el-dialog title="表单详情" :visible.sync="detailOpen" width="50%" append-to-body> 77 <el-dialog title="表单详情" :visible.sync="detailOpen" width="50%" append-to-body>
72 - <div class="test-form">  
73 - <parser :key="new Date().getTime()" :form-conf="detailForm" />  
74 - </div> 78 + <parser :key="new Date().getTime()" :form-conf="detailForm" />
  79 + </el-dialog>
  80 +
  81 + <!-- 流程模型图的预览 -->
  82 + <el-dialog title="流程图" :visible.sync="showBpmnOpen" width="80%" append-to-body>
  83 + <my-process-viewer key="designer" v-model="bpmnXML" v-bind="bpmnControlForm" />
75 </el-dialog> 84 </el-dialog>
76 </div> 85 </div>
77 </template> 86 </template>
78 87
79 <script> 88 <script>
80 -import {deleteModel, deployModel, getModelPage} from "@/api/bpm/model"; 89 +import {deleteModel, deployModel, getModelPage, getModel} from "@/api/bpm/model";
81 import {DICT_TYPE, getDictDatas} from "@/utils/dict"; 90 import {DICT_TYPE, getDictDatas} from "@/utils/dict";
82 import {getForm} from "@/api/bpm/form"; 91 import {getForm} from "@/api/bpm/form";
83 import {decodeFields} from "@/utils/formGenerator"; 92 import {decodeFields} from "@/utils/formGenerator";
@@ -107,7 +116,9 @@ export default { @@ -107,7 +116,9 @@ export default {
107 // BPMN 数据 116 // BPMN 数据
108 showBpmnOpen: false, 117 showBpmnOpen: false,
109 bpmnXML: null, 118 bpmnXML: null,
110 - bpmnData: {}, 119 + bpmnControlForm: {
  120 + prefix: "activiti"
  121 + },
111 122
112 // 流程表单详情 123 // 流程表单详情
113 detailOpen: false, 124 detailOpen: false,
@@ -205,6 +216,22 @@ export default { @@ -205,6 +216,22 @@ export default {
205 this.detailOpen = true 216 this.detailOpen = true
206 }) 217 })
207 }, 218 },
  219 + /** 流程图的详情按钮操作 */
  220 + handleBpmnDetail(row) {
  221 + getModel(row.id).then(response => {
  222 + this.bpmnXML = response.data.bpmnXml
  223 + // 弹窗打开
  224 + this.showBpmnOpen = true
  225 + })
  226 + },
208 } 227 }
209 }; 228 };
210 </script> 229 </script>
  230 +
  231 +<style lang="scss">
  232 +
  233 +.my-process-designer {
  234 + height: calc(100vh - 200px);
  235 +}
  236 +
  237 +</style>
yudao-admin-ui/src/views/bpm/model/modelViewer.vue 0 → 100644
  1 +<template>
  2 + <div class="app-container">
  3 +
  4 + <!-- 流程设计器,负责绘制流程等 -->
  5 + <my-process-viewer key="designer" v-model="xmlString" v-bind="controlForm" keyboard ref="processDesigner" />
  6 +
  7 + </div>
  8 +</template>
  9 +
  10 +<script>
  11 +import {getModel} from "@/api/bpm/model";
  12 +export default {
  13 + name: "App",
  14 + components: { },
  15 + data() {
  16 + return {
  17 + xmlString: "", // BPMN XML
  18 + controlForm: {
  19 + prefix: "activiti"
  20 + },
  21 + };
  22 + },
  23 + created() {
  24 + // 如果 modelId 非空,说明是修改流程模型
  25 + const modelId = this.$route.query && this.$route.query.modelId
  26 + if (modelId) {
  27 + getModel(modelId).then(response => {
  28 + this.xmlString = response.data.bpmnXml
  29 + })
  30 + }
  31 + }
  32 +};
  33 +</script>
  34 +
  35 +<style lang="scss">
  36 +
  37 +.my-process-designer {
  38 + height: calc(100vh - 84px);
  39 +}
  40 +
  41 +</style>