Blame view

src/views/workflow/components/processViewer.vue 15 KB
1
<!--
2
 * @Description:
3 4 5
 * @Autor: renchao
 * @LastEditTime: 2023-05-17 10:41:15
-->
任超 committed
6
<template>
7 8
  <div>
    <div class="process-viewer">
xiaomiao committed
9 10 11 12 13 14
      <div
        v-show="!isLoading"
        ref="processCanvas"
        class="process-canvas"
        style="height: 280px"
      />
15 16
      <!-- 自定义箭头样式,用于成功状态下流程连线箭头 -->
      <defs ref="customSuccessDefs">
xiaomiao committed
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
        <marker
          id="sequenceflow-end-white-success"
          view-box="0 0 20 20"
          ref-x="11"
          ref-y="10"
          marker-width="10"
          marker-height="10"
          orient="auto"
        >
          <path
            class="success-arrow"
            d="M 1 5 L 11 10 L 1 15 Z"
            style="
              stroke-width: 1px;
              stroke-linecap: round;
              stroke-dasharray: 10000, 1;
            "
          />
35
        </marker>
xiaomiao committed
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
        <marker
          id="conditional-flow-marker-white-success"
          view-box="0 0 20 20"
          ref-x="-1"
          ref-y="10"
          marker-width="10"
          marker-height="10"
          orient="auto"
        >
          <path
            class="success-conditional"
            d="M 0 10 L 8 6 L 16 10 L 8 14 Z"
            style="
              stroke-width: 1px;
              stroke-linecap: round;
              stroke-dasharray: 10000, 1;
            "
          />
54 55 56 57
        </marker>
      </defs>
      <!-- 自定义箭头样式,用于失败状态下流程连线箭头 -->
      <defs ref="customFailDefs">
xiaomiao committed
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
        <marker
          id="sequenceflow-end-white-fail"
          view-box="0 0 20 20"
          ref-x="11"
          ref-y="10"
          marker-width="10"
          marker-height="10"
          orient="auto"
        >
          <path
            class="fail-arrow"
            d="M 1 5 L 11 10 L 1 15 Z"
            style="
              stroke-width: 1px;
              stroke-linecap: round;
              stroke-dasharray: 10000, 1;
            "
          />
76
        </marker>
xiaomiao committed
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
        <marker
          id="conditional-flow-marker-white-fail"
          view-box="0 0 20 20"
          ref-x="-1"
          ref-y="10"
          marker-width="10"
          marker-height="10"
          orient="auto"
        >
          <path
            class="fail-conditional"
            d="M 0 10 L 8 6 L 16 10 L 8 14 Z"
            style="
              stroke-width: 1px;
              stroke-linecap: round;
              stroke-dasharray: 10000, 1;
            "
          />
95 96 97
        </marker>
      </defs>

xiaomiao committed
98
      <div style="position: absolute; top: 0px; left: 0px; width: 100%">
99 100
        <el-row type="flex" justify="end">
          <el-button-group key="scale-control" size="medium">
xiaomiao committed
101 102 103 104 105 106 107 108 109 110
            <el-button
              size="medium"
              type="default"
              :plain="true"
              :disabled="defaultZoom <= 0.3"
              icon="el-icon-zoom-out"
              @click="processZoomOut()"
            />
            <el-button size="medium" type="default" style="width: 90px">{{
              Math.floor(this.defaultZoom * 10 * 10) + "%"
111
            }}</el-button>
xiaomiao committed
112 113 114 115 116 117 118 119 120 121 122 123 124 125
            <el-button
              size="medium"
              type="default"
              :plain="true"
              :disabled="defaultZoom >= 3.9"
              icon="el-icon-zoom-in"
              @click="processZoomIn()"
            />
            <el-button
              size="medium"
              type="default"
              icon="el-icon-c-scale-to-original"
              @click="processReZoom()"
            />
126 127 128 129 130
            <slot />
          </el-button-group>
        </el-row>
      </div>
    </div>
任超 committed
131
    <!-- 已完成节点悬浮弹窗 -->
132 133
    <div class="information-list">
      <el-select v-model="selectValue" @change="handleSelect">
xiaomiao committed
134 135 136 137 138 139
        <el-option
          v-for="item in selectOptions"
          :key="item.value"
          :label="item.label"
          :value="item.value"
        >
140 141
        </el-option>
      </el-select>
xiaomiao committed
142 143 144 145 146 147 148 149 150 151 152 153 154 155
      <el-table
        height="190"
        :data="taskCommentList"
        size="mini"
        border
        header-cell-class-name="table-header-gray"
      >
        <el-table-column
          label="序号"
          header-align="center"
          align="center"
          type="index"
          width="55px"
        />
xiaomiao committed
156 157
        <el-table-column label="流程状态" header-align="center" align="center">
          <template slot-scope="scope">
xiaomiao committed
158 159
            <div v-if="scope.row.endTime">已完结</div>
            <div v-else>正在办理</div>
xiaomiao committed
160 161
          </template>
        </el-table-column>
xiaomiao committed
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196
        <el-table-column
          label="环节名称"
          prop="name"
          minWidth="100"
          align="center"
        />
        <el-table-column
          label="办理人"
          prop="agent"
          minWidth="120"
          align="center"
        />
        <el-table-column
          label="转入时间"
          prop="createTime"
          :formatter="formatDate"
          width="160"
          align="center"
        />
        <el-table-column
          label="认领时间"
          prop="claimTime"
          :formatter="formatDate"
          width="160"
          align="center"
        />
        <el-table-column
          label="转出时间"
          prop="endTime"
          :formatter="formatDate"
          width="160"
          align="center"
        />
        <el-table-column label="操作方式" prop="controls" align="center" />
        <el-table-column label="意见" prop="idea" align="center" />
197
      </el-table>
任超 committed
198 199 200 201
    </div>
  </div>
</template>
<script>
xiaomiao committed
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248
import "@/styles/package/theme/index.scss";
import BpmnViewer from "bpmn-js/lib/Viewer";
import MoveCanvasModule from "diagram-js/lib/navigation/movecanvas";
export default {
  props: {
    formData: {
      type: Object,
      default: {},
    },
  },
  data() {
    return {
      dlgTitle: undefined,
      defaultZoom: 1,
      // 是否正在加载流程图
      isLoading: true,
      bpmnViewer: undefined,
      // 已完成流程元素
      processNodeInfo: undefined,
      // 当前任务id
      selectTaskId: undefined,
      // 任务节点审批记录
      taskList: [],
      taskCommentList: [],
      // 已完成任务悬浮延迟Timer
      hoverTimer: null,
      // 下拉
      selectValue: "",
      selectOptions: [],
    };
  },
  created() {
    this.$nextTick(() => {
      // 获取流程记录
      this.getCommentList();
      this.setProcessStatus(this.formData.finishedInfo);
      this.importXML(this.formData.xml);
    });
  },
  destroyed() {
    this.clearViewer();
  },
  methods: {
    formatDate(row, column) {
      let data = row[column.property];
      if (data == null) {
        return null;
任超 committed
249
      }
xiaomiao committed
250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267
      let dt = new Date(data);
      return (
        dt.getFullYear() +
        "-" +
        (dt.getMonth() + 1) +
        "-" +
        dt.getDate() +
        " " +
        dt.getHours() +
        ":" +
        dt.getMinutes() +
        ":" +
        dt.getSeconds()
      );
    },
    processReZoom() {
      this.defaultZoom = 1;
      this.bpmnViewer.get("canvas").zoom("fit-viewport", "auto");
任超 committed
268
    },
xiaomiao committed
269 270 271 272 273 274
    processZoomIn(zoomStep = 0.1) {
      const newZoom = Math.floor(this.defaultZoom * 100 + zoomStep * 100) / 100;
      if (newZoom > 4) {
        throw new Error(
          "[Process Designer Warn ]: The zoom ratio cannot be greater than 4"
        );
任超 committed
275
      }
xiaomiao committed
276 277
      this.defaultZoom = newZoom;
      this.bpmnViewer.get("canvas").zoom(this.defaultZoom);
任超 committed
278
    },
xiaomiao committed
279 280 281 282 283 284 285 286 287
    processZoomOut(zoomStep = 0.1) {
      const newZoom = Math.floor(this.defaultZoom * 100 - zoomStep * 100) / 100;
      if (newZoom < 0.2) {
        throw new Error(
          "[Process Designer Warn ]: The zoom ratio cannot be scss than 0.2"
        );
      }
      this.defaultZoom = newZoom;
      this.bpmnViewer.get("canvas").zoom(this.defaultZoom);
任超 committed
288
    },
xiaomiao committed
289 290
    getOperationTagType(type) {
      return "success";
任超 committed
291
    },
xiaomiao committed
292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356
    // 流程图预览清空
    clearViewer(a) {
      if (this.$refs.processCanvas) {
        this.$refs.processCanvas.innerHTML = "";
      }
      if (this.bpmnViewer) {
        this.bpmnViewer.destroy();
      }
      this.bpmnViewer = null;
    },
    // 添加自定义箭头
    addCustomDefs() {
      const canvas = this.bpmnViewer.get("canvas");
      const svg = canvas._svg;
      const customSuccessDefs = this.$refs.customSuccessDefs;
      const customFailDefs = this.$refs.customFailDefs;
      svg.appendChild(customSuccessDefs);
      svg.appendChild(customFailDefs);
    },
    // 任务悬浮弹窗
    onSelectElement(element) {
      this.selectTaskId = undefined;
      this.dlgTitle = undefined;
      let allfinishedTaskSet = [
        ...this.processNodeInfo.finishedTaskSet,
        ...this.processNodeInfo.unfinishedTaskSet,
      ];
      if (this.processNodeInfo == null || allfinishedTaskSet == null) return;
      if (element == null || allfinishedTaskSet.indexOf(element.id) === -1) {
        return;
      }
      this.selectTaskId = element.id;
      this.selectValue = element.id;
      this.dlgTitle = element.businessObject
        ? element.businessObject.name
        : undefined;
      // 计算当前悬浮任务审批记录,如果记录为空不显示弹窗
      this.taskCommentList = (this.taskList || []).filter((item) => {
        return item.taskDefinitionKey === this.selectTaskId;
      });
      if (this.taskCommentList.length == 0) {
        this.taskCommentList = this.taskList;
      }
    },
    // 下拉列表切换
    handleSelect(val) {
      this.taskCommentList = (this.taskList || []).filter((item) => {
        return item.taskDefinitionKey === val;
      });
      if (this.taskCommentList.length == 0) {
        this.taskCommentList = this.taskList;
      }
    },
    // 显示流程图
    async importXML(xml) {
      let xmlData = this.$x2js.xml2js(xml).definitions.process;
      this.selectOptions = xmlData.userTask.map((item) => {
        return { value: item._id, label: item._name };
      });
      this.selectOptions = [
        { value: xmlData.startEvent._id, label: "浏览记录" },
        ...this.selectOptions,
      ];
      this.selectOptions = this.selectOptions
        .map((item) => {
xiaomiao committed
357
          if (this.formData.finishedInfo.finishedTaskSet.includes(item.value)) {
xiaomiao committed
358
            return item;
xiaomiao committed
359
          }
xiaomiao committed
360 361 362 363
          if (
            this.formData.finishedInfo.unfinishedTaskSet.includes(item.value)
          ) {
            return item;
xiaomiao committed
364
          }
xiaomiao committed
365
        })
xiaomiao committed
366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392
        .filter(Boolean);
      this.selectValue = xmlData.startEvent._id;
      this.clearViewer("a");
      if (xml != null && xml !== "") {
        try {
          this.bpmnViewer = new BpmnViewer({
            additionalModules: [
              // 移动整个画布
              MoveCanvasModule,
            ],
            container: this.$refs.processCanvas,
          });
          // 任务节点悬浮事件
          this.bpmnViewer.on("element.click", ({ element }) => {
            this.onSelectElement(element);
          });
          await this.bpmnViewer.importXML(xml);
          this.isLoading = true;
          this.addCustomDefs();
        } catch (e) {
          this.clearViewer("b");
        } finally {
          this.isLoading = false;
          this.setProcessStatus(this.processNodeInfo);
          this.$nextTick(() => {
            this.processReZoom();
          });
xiaomiao committed
393
        }
xiaomiao committed
394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431
      }
    },
    // 获取流程记录
    getCommentList() {
      this.formData.allCommentList.forEach(async (item, index) => {
        // item.comments.forEach(element => {
        //   if(element.type=="COMPLETE"){
        //     this.formData.allCommentList[index].idea=element.message
        //      this.formData.allCommentList[index].controls="完成"
        //   }
        // });
        let type = item.comments[item.comments.length - 1].type;
        this.formData.allCommentList[index].idea =
          item.comments[item.comments.length - 1].message;
        // 操作方式
        let controls = "";
        switch (type) {
          case "COMPLETE":
            controls = "完成";
            break;
          case "CLAIM":
            controls = "完成";
            break;
          case "ASSIGN":
            controls = "转办";
            break;
          case "DELEGATE":
            controls = "委派";
            break;
          case "UNCLAIM":
            controls = "取消认领";
            break;
          case "STOP":
            controls = "终止";
            break;
          case "BACK":
            controls = "退回";
            break;
xiaomiao committed
432
        }
xiaomiao committed
433 434 435 436 437 438 439 440 441 442 443 444 445
        this.formData.allCommentList[index].controls = controls;
        this.formData.allCommentList[index].agent = item.assignee.name;
      });
      this.formData.handlinglist.forEach(async (item, index) => {
        if (item.assignee.name) {
          this.formData.handlinglist[index].agent = item.assignee.name;
        } else {
          let str = "";
          item.countersign.forEach((item) => {
            str += item.name + ",";
          });
          str = str.slice(0, -1);
          this.formData.allCommentList[index].agent = str;
xiaomiao committed
446
        }
xiaomiao committed
447 448 449 450 451 452 453 454 455
      });
      this.taskList = [
        ...this.formData.allCommentList,
        ...this.formData.handlinglist,
      ];
      //  this.taskList =this.formData.allCommentList;
      //  处理数据之后赋值
      this.taskCommentList = this.taskList;
    },
456

xiaomiao committed
457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485
    // 设置流程图元素状态
    setProcessStatus(processNodeInfo) {
      this.processNodeInfo = processNodeInfo;
      if (
        this.isLoading ||
        this.processNodeInfo == null ||
        this.bpmnViewer == null
      )
        return;
      const {
        finishedTaskSet,
        rejectedTaskSet,
        unfinishedTaskSet,
        finishedSequenceFlowSet,
      } = this.processNodeInfo;
      const canvas = this.bpmnViewer.get("canvas");
      const elementRegistry = this.bpmnViewer.get("elementRegistry");
      if (Array.isArray(finishedSequenceFlowSet)) {
        finishedSequenceFlowSet.forEach((item) => {
          if (item != null) {
            canvas.addMarker(item, "success");
            const element = elementRegistry.get(item);
            const conditionExpression =
              element.businessObject.conditionExpression;
            if (conditionExpression) {
              canvas.addMarker(item, "condition-expression");
            }
          }
        });
任超 committed
486
      }
xiaomiao committed
487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507
      if (Array.isArray(finishedTaskSet)) {
        finishedTaskSet.forEach((item) => canvas.addMarker(item, "success"));
      }
      if (Array.isArray(unfinishedTaskSet)) {
        unfinishedTaskSet.forEach((item) => canvas.addMarker(item, "primary"));
      }
      if (Array.isArray(rejectedTaskSet)) {
        rejectedTaskSet.forEach((item) => {
          if (item != null) {
            const element = elementRegistry.get(item);
            if (element.type.includes("Task")) {
              canvas.addMarker(item, "danger");
            } else {
              canvas.addMarker(item, "warning");
            }
          }
        });
      }
    },
  },
};
508 509
</script>
<style scoped lang="scss">
xiaomiao committed
510 511 512
.information-list {
  height: 220px;
  margin-top: 10px;
513

xiaomiao committed
514 515 516
  p {
    font-size: 16px;
    line-height: 24px;
517
  }
xiaomiao committed
518 519 520 521 522 523 524 525
}
/deep/.bjs-powered-by {
  display: none;
}
// /deep/.information-list {
//   height: 170px;
//   overflow: visible;
// }
xiaomiao committed
526
</style>