增加 bpmn 流程图的高亮

This commit is contained in:
YunaiV 2022-01-21 01:12:44 +08:00
parent 21376c80a8
commit 34a0f0ea9d

View File

@ -117,7 +117,7 @@ export default {
// //
let canvas = this.bpmnModeler.get('canvas'); let canvas = this.bpmnModeler.get('canvas');
let todoActivity = activityList.find(m => !m.endTime) // let todoActivity = activityList.find(m => !m.endTime) //
let endActivity = activityList[activityList.length - 1] // let endActivity = activityList[activityList.length - 1] //
// debugger // debugger
console.log(this.bpmnModeler.getDefinitions().rootElements[0].flowElements); console.log(this.bpmnModeler.getDefinitions().rootElements[0].flowElements);
this.bpmnModeler.getDefinitions().rootElements[0].flowElements?.forEach(n => { this.bpmnModeler.getDefinitions().rootElements[0].flowElements?.forEach(n => {
@ -129,23 +129,27 @@ export default {
// //
const task = this.taskList.find(m => m.id === activity.taskId); // taskId const task = this.taskList.find(m => m.id === activity.taskId); // taskId
if (task) { if (task) {
canvas.addMarker(n.id, this.getTaskHighlightCss(task)); canvas.addMarker(n.id, this.getResultCss(task.result));
// 线
if (task.result !== 2) {
return;
}
} }
// outgoing 线 // outgoing 线
const outgoing = this.getActivityOutgoing(activity); const outgoing = this.getActivityOutgoing(activity);
outgoing?.forEach(nn => { outgoing?.forEach(nn => {
debugger // debugger
let targetActivity = activityList.find(m => m.key === nn.targetRef.id) let targetActivity = activityList.find(m => m.key === nn.targetRef.id)
if (targetActivity) { if (targetActivity) {
debugger // debugger
canvas.addMarker(nn.id, targetActivity.endTime ? 'highlight' : 'highlight-todo'); canvas.addMarker(nn.id, targetActivity.endTime ? 'highlight' : 'highlight-todo');
} else if (nn.targetRef.$type === 'bpmn:ExclusiveGateway') { } else if (nn.targetRef.$type === 'bpmn:ExclusiveGateway') {
debugger // debugger
canvas.addMarker(nn.id, activity.endTime ? 'highlight' : 'highlight-todo'); canvas.addMarker(nn.id, activity.endTime ? 'highlight' : 'highlight-todo');
canvas.addMarker(nn.targetRef.id, activity.endTime ? 'highlight' : 'highlight-todo'); canvas.addMarker(nn.targetRef.id, activity.endTime ? 'highlight' : 'highlight-todo');
} else if (nn.targetRef.$type === 'bpmn:EndEvent') { } else if (nn.targetRef.$type === 'bpmn:EndEvent') {
debugger // debugger
if (!todoActivity && endActivity.key === n.id) { if (!todoActivity && endActivity.key === n.id) {
canvas.addMarker(nn.id, 'highlight'); canvas.addMarker(nn.id, 'highlight');
canvas.addMarker(nn.targetRef.id, 'highlight'); canvas.addMarker(nn.targetRef.id, 'highlight');
@ -188,22 +192,17 @@ export default {
} }
}); });
} else if (n.$type === 'bpmn:EndEvent') { // } else if (n.$type === 'bpmn:EndEvent') { //
if (endActivity.key !== n.id) { // endActivity EndEvent if (!this.processInstance || this.processInstance.result === 1) {
return; return;
} }
// endActivity endTime canvas.addMarker(n.id, this.getResultCss(this.processInstance.result));
// todoActivity
if (endActivity.endTime && !todoActivity) {
canvas.addMarker(n.id, 'highlight');
}
} }
}) })
}, },
getActivityHighlightCss(activity) { getActivityHighlightCss(activity) {
return activity.endTime ? 'highlight' : 'highlight-todo'; return activity.endTime ? 'highlight' : 'highlight-todo';
}, },
getTaskHighlightCss(task) { getResultCss(result) {
const result = task.result;
if (result === 1) { if (result === 1) {
return 'highlight-todo'; return 'highlight-todo';
} else if (result === 2) { } else if (result === 2) {
@ -253,12 +252,43 @@ export default {
!this.overlays && (this.overlays = this.bpmnModeler.get("overlays")); !this.overlays && (this.overlays = this.bpmnModeler.get("overlays"));
// //
if (!this.elementOverlayIds[element.id] && element.type !== "bpmn:Process") { if (!this.elementOverlayIds[element.id] && element.type !== "bpmn:Process") {
this.elementOverlayIds[element.id] = this.overlays.add(element, { let html = `<div class="element-overlays">
position: { left: 0, bottom: 0 },
html: `<div class="element-overlays">
<p>Elemet id: ${element.id}</p> <p>Elemet id: ${element.id}</p>
<p>Elemet type: ${element.type}</p> <p>Elemet type: ${element.type}</p>
</div>` </div>`; // 默认值
if (element.type === 'bpmn:StartEvent' && this.processInstance) {
html = `<p>发起人:${this.processInstance.startUser.nickname}</p>
<p>部门${this.processInstance.startUser.deptName}</p>
<p>创建时间${this.parseTime(this.processInstance.createTime)}`;
} else if (element.type === 'bpmn:UserTask') {
// debugger
const activity = this.activityList.find(m => m.key === element.id);
if (!activity) {
return;
}
let task = this.taskList.find(m => m.id === activity.taskId); // taskId
if (!task) {
return;
}
html = `<p>审批人:${task.assigneeUser.nickname}</p>
<p>部门${task.assigneeUser.deptName}</p>
<p>结果${this.getDictDataLabel(this.DICT_TYPE.BPM_PROCESS_INSTANCE_RESULT, task.result)}</p>
<p>创建时间${this.parseTime(task.createTime)}</p>`;
if (task.endTime) {
html += `<p>结束时间:${this.parseTime(task.endTime)}</p>`
}
if (task.comment) {
html += `<p>审批建议:${task.comment}</p>`
}
} else if (element.type === 'bpmn:EndEvent' && this.processInstance) {
html = `<p>结果:${this.getDictDataLabel(this.DICT_TYPE.BPM_PROCESS_INSTANCE_RESULT, this.processInstance.result)}</p>`;
if (this.processInstance.endTime) {
html += `<p>结束时间:${this.parseTime(this.processInstance.endTime)}</p>`
}
}
this.elementOverlayIds[element.id] = this.overlays.add(element, {
position: { left: 0, bottom: 0 },
html: `<div class="element-overlays">${html}</div>`
}); });
} }
}, },
@ -275,26 +305,26 @@ export default {
/** 处理中 */ /** 处理中 */
.highlight-todo.djs-connection > .djs-visual > path { .highlight-todo.djs-connection > .djs-visual > path {
stroke: orange !important; stroke: #1890ff !important;
stroke-dasharray: 4px !important; stroke-dasharray: 4px !important;
fill-opacity: 0.2 !important; fill-opacity: 0.2 !important;
} }
.highlight-todo.djs-shape .djs-visual > :nth-child(1) { .highlight-todo.djs-shape .djs-visual > :nth-child(1) {
fill: orange !important; fill: #1890ff !important;
stroke: orange !important; stroke: #1890ff !important;
stroke-dasharray: 4px !important; stroke-dasharray: 4px !important;
fill-opacity: 0.2 !important; fill-opacity: 0.2 !important;
} }
/deep/.highlight-todo.djs-connection > .djs-visual > path { /deep/.highlight-todo.djs-connection > .djs-visual > path {
stroke: orange !important; stroke: #1890ff !important;
stroke-dasharray: 4px !important; stroke-dasharray: 4px !important;
fill-opacity: 0.2 !important; fill-opacity: 0.2 !important;
marker-end: url(#sequenceflow-end-_E7DFDF-_E7DFDF-803g1kf6zwzmcig1y2ulm5egr); marker-end: url(#sequenceflow-end-_E7DFDF-_E7DFDF-803g1kf6zwzmcig1y2ulm5egr);
} }
/deep/.highlight-todo.djs-shape .djs-visual > :nth-child(1) { /deep/.highlight-todo.djs-shape .djs-visual > :nth-child(1) {
fill: orange !important; fill: #1890ff !important;
stroke: orange !important; stroke: #1890ff !important;
stroke-dasharray: 4px !important; stroke-dasharray: 4px !important;
fill-opacity: 0.2 !important; fill-opacity: 0.2 !important;
} }
@ -415,4 +445,13 @@ export default {
/deep/.highlight-cancel.djs-connection > .djs-visual > path { /deep/.highlight-cancel.djs-connection > .djs-visual > path {
stroke: grey !important; stroke: grey !important;
} }
.element-overlays {
box-sizing: border-box;
padding: 8px;
background: rgba(0, 0, 0, 0.6);
border-radius: 4px;
color: #fafafa;
width: 200px;
}
</style> </style>