Commit 34a0f0ea9db57d96a92a784da90f6b1e9cda6de9

Authored by YunaiV
1 parent 21376c80

增加 bpmn 流程图的高亮

yudao-admin-ui/src/components/bpmnProcessDesigner/package/designer/ProcessViewer.vue
... ... @@ -117,7 +117,7 @@ export default {
117 117 // 再次基础上,增加不同审批结果的颜色等等
118 118 let canvas = this.bpmnModeler.get('canvas');
119 119 let todoActivity = activityList.find(m => !m.endTime) // 找到待办的任务
120   - let endActivity = activityList[activityList.length - 1] // 找到结束任务
  120 + let endActivity = activityList[activityList.length - 1] // 获得最后一个任务
121 121 // debugger
122 122 console.log(this.bpmnModeler.getDefinitions().rootElements[0].flowElements);
123 123 this.bpmnModeler.getDefinitions().rootElements[0].flowElements?.forEach(n => {
... ... @@ -129,23 +129,27 @@ export default {
129 129 // 处理用户任务的高亮
130 130 const task = this.taskList.find(m => m.id === activity.taskId); // 找到活动对应的 taskId
131 131 if (task) {
132   - canvas.addMarker(n.id, this.getTaskHighlightCss(task));
  132 + canvas.addMarker(n.id, this.getResultCss(task.result));
  133 + // 如果非通过,就不走后面的线条了
  134 + if (task.result !== 2) {
  135 + return;
  136 + }
133 137 }
134 138  
135 139 // 处理 outgoing 出线
136 140 const outgoing = this.getActivityOutgoing(activity);
137 141 outgoing?.forEach(nn => {
138   - debugger
  142 + // debugger
139 143 let targetActivity = activityList.find(m => m.key === nn.targetRef.id)
140 144 if (targetActivity) {
141   - debugger
  145 + // debugger
142 146 canvas.addMarker(nn.id, targetActivity.endTime ? 'highlight' : 'highlight-todo');
143 147 } else if (nn.targetRef.$type === 'bpmn:ExclusiveGateway') {
144   - debugger
  148 + // debugger
145 149 canvas.addMarker(nn.id, activity.endTime ? 'highlight' : 'highlight-todo');
146 150 canvas.addMarker(nn.targetRef.id, activity.endTime ? 'highlight' : 'highlight-todo');
147 151 } else if (nn.targetRef.$type === 'bpmn:EndEvent') {
148   - debugger
  152 + // debugger
149 153 if (!todoActivity && endActivity.key === n.id) {
150 154 canvas.addMarker(nn.id, 'highlight');
151 155 canvas.addMarker(nn.targetRef.id, 'highlight');
... ... @@ -188,22 +192,17 @@ export default {
188 192 }
189 193 });
190 194 } else if (n.$type === 'bpmn:EndEvent') { // 结束节点
191   - if (endActivity.key !== n.id) { // 保证 endActivity 就是 EndEvent
  195 + if (!this.processInstance || this.processInstance.result === 1) {
192 196 return;
193 197 }
194   - // 在并行网关后,跟着多个任务,如果其中一个任务完成,endActivity 的 endTime 就会存在值
195   - // 所以,通过 todoActivity 在做一次判断
196   - if (endActivity.endTime && !todoActivity) {
197   - canvas.addMarker(n.id, 'highlight');
198   - }
  198 + canvas.addMarker(n.id, this.getResultCss(this.processInstance.result));
199 199 }
200 200 })
201 201 },
202 202 getActivityHighlightCss(activity) {
203 203 return activity.endTime ? 'highlight' : 'highlight-todo';
204 204 },
205   - getTaskHighlightCss(task) {
206   - const result = task.result;
  205 + getResultCss(result) {
207 206 if (result === 1) {
208 207 return 'highlight-todo';
209 208 } else if (result === 2) {
... ... @@ -253,12 +252,43 @@ export default {
253 252 !this.overlays && (this.overlays = this.bpmnModeler.get("overlays"));
254 253 // 展示信息
255 254 if (!this.elementOverlayIds[element.id] && element.type !== "bpmn:Process") {
256   - this.elementOverlayIds[element.id] = this.overlays.add(element, {
257   - position: { left: 0, bottom: 0 },
258   - html: `<div class="element-overlays">
  255 + let html = `<div class="element-overlays">
259 256 <p>Elemet id: ${element.id}</p>
260 257 <p>Elemet type: ${element.type}</p>
261   - </div>`
  258 + </div>`; // 默认值
  259 + if (element.type === 'bpmn:StartEvent' && this.processInstance) {
  260 + html = `<p>发起人:${this.processInstance.startUser.nickname}</p>
  261 + <p>部门:${this.processInstance.startUser.deptName}</p>
  262 + <p>创建时间:${this.parseTime(this.processInstance.createTime)}`;
  263 + } else if (element.type === 'bpmn:UserTask') {
  264 + // debugger
  265 + const activity = this.activityList.find(m => m.key === element.id);
  266 + if (!activity) {
  267 + return;
  268 + }
  269 + let task = this.taskList.find(m => m.id === activity.taskId); // 找到活动对应的 taskId
  270 + if (!task) {
  271 + return;
  272 + }
  273 + html = `<p>审批人:${task.assigneeUser.nickname}</p>
  274 + <p>部门:${task.assigneeUser.deptName}</p>
  275 + <p>结果:${this.getDictDataLabel(this.DICT_TYPE.BPM_PROCESS_INSTANCE_RESULT, task.result)}</p>
  276 + <p>创建时间:${this.parseTime(task.createTime)}</p>`;
  277 + if (task.endTime) {
  278 + html += `<p>结束时间:${this.parseTime(task.endTime)}</p>`
  279 + }
  280 + if (task.comment) {
  281 + html += `<p>审批建议:${task.comment}</p>`
  282 + }
  283 + } else if (element.type === 'bpmn:EndEvent' && this.processInstance) {
  284 + html = `<p>结果:${this.getDictDataLabel(this.DICT_TYPE.BPM_PROCESS_INSTANCE_RESULT, this.processInstance.result)}</p>`;
  285 + if (this.processInstance.endTime) {
  286 + html += `<p>结束时间:${this.parseTime(this.processInstance.endTime)}</p>`
  287 + }
  288 + }
  289 + this.elementOverlayIds[element.id] = this.overlays.add(element, {
  290 + position: { left: 0, bottom: 0 },
  291 + html: `<div class="element-overlays">${html}</div>`
262 292 });
263 293 }
264 294 },
... ... @@ -275,26 +305,26 @@ export default {
275 305  
276 306 /** 处理中 */
277 307 .highlight-todo.djs-connection > .djs-visual > path {
278   - stroke: orange !important;
  308 + stroke: #1890ff !important;
279 309 stroke-dasharray: 4px !important;
280 310 fill-opacity: 0.2 !important;
281 311 }
282 312 .highlight-todo.djs-shape .djs-visual > :nth-child(1) {
283   - fill: orange !important;
284   - stroke: orange !important;
  313 + fill: #1890ff !important;
  314 + stroke: #1890ff !important;
285 315 stroke-dasharray: 4px !important;
286 316 fill-opacity: 0.2 !important;
287 317 }
288 318  
289 319 /deep/.highlight-todo.djs-connection > .djs-visual > path {
290   - stroke: orange !important;
  320 + stroke: #1890ff !important;
291 321 stroke-dasharray: 4px !important;
292 322 fill-opacity: 0.2 !important;
293 323 marker-end: url(#sequenceflow-end-_E7DFDF-_E7DFDF-803g1kf6zwzmcig1y2ulm5egr);
294 324 }
295 325 /deep/.highlight-todo.djs-shape .djs-visual > :nth-child(1) {
296   - fill: orange !important;
297   - stroke: orange !important;
  326 + fill: #1890ff !important;
  327 + stroke: #1890ff !important;
298 328 stroke-dasharray: 4px !important;
299 329 fill-opacity: 0.2 !important;
300 330 }
... ... @@ -415,4 +445,13 @@ export default {
415 445 /deep/.highlight-cancel.djs-connection > .djs-visual > path {
416 446 stroke: grey !important;
417 447 }
  448 +
  449 +.element-overlays {
  450 + box-sizing: border-box;
  451 + padding: 8px;
  452 + background: rgba(0, 0, 0, 0.6);
  453 + border-radius: 4px;
  454 + color: #fafafa;
  455 + width: 200px;
  456 +}
418 457 </style>
... ...