优化 bpm 高亮流程图的前端

This commit is contained in:
YunaiV 2022-01-20 01:14:10 +08:00
parent 348762ae6a
commit 5332e543d2
2 changed files with 83 additions and 57 deletions

View File

@ -14,25 +14,34 @@ export default {
name: "MyProcessViewer", name: "MyProcessViewer",
componentName: "MyProcessViewer", componentName: "MyProcessViewer",
props: { props: {
value: String, // xml value: { // BPMN XML
prefix: {
type: String, type: String,
default: "camunda"
}, },
taskData: { prefix: { // 使
type: String,
default: "camunda",
},
activityData: { //
type: Array, type: Array,
default: () => [] default: () => [],
},
processInstanceData: { //
type: Object,
},
taskData: { // UserTask
type: Array,
default: () => [],
} }
}, },
data() { data() {
return { return {
xml: '', xml: '',
tasks: [], activityList: [],
}; };
}, },
mounted() { mounted() {
this.xml = this.value; this.xml = this.value;
this.tasks = this.taskData; this.activityList = this.activityData;
// //
this.initBpmnModeler(); this.initBpmnModeler();
this.createNewDiagram(this.xml); this.createNewDiagram(this.xml);
@ -49,8 +58,8 @@ export default {
this.xml = newValue; this.xml = newValue;
this.createNewDiagram(this.xml); this.createNewDiagram(this.xml);
}, },
taskData: function (newTaskData) { activityData: function (newActivityData) {
this.tasks = newTaskData; this.activityList = newActivityData;
this.createNewDiagram(this.xml); this.createNewDiagram(this.xml);
} }
}, },
@ -83,8 +92,9 @@ export default {
} }
}, },
/* 高亮流程图 */ /* 高亮流程图 */
// TODO endActivity https://www.jdon.com/workflow/multi-events.html
async highlightDiagram() { async highlightDiagram() {
let activityList = this.tasks; let activityList = this.activityList;
if (activityList.length === 0) { if (activityList.length === 0) {
return; return;
} }
@ -99,6 +109,7 @@ export default {
if (!activity) { if (!activity) {
return; return;
} }
// TODO
if (activity.task) { if (activity.task) {
const result = activity.task.result; const result = activity.task.result;
if (result === 1) { if (result === 1) {
@ -111,16 +122,17 @@ export default {
canvas.addMarker(n.id, 'highlight-cancel'); canvas.addMarker(n.id, 'highlight-cancel');
} }
} }
n.outgoing?.forEach(nn => { n.outgoing?.forEach(nn => {
let targetTask = activityList.find(m => m.key === nn.targetRef.id) let targetActivity = activityList.find(m => m.key === nn.targetRef.id)
if (targetTask) { if (targetActivity) {
canvas.addMarker(nn.id, targetTask.endTime ? 'highlight' : 'highlight-todo'); debugger
canvas.addMarker(nn.id, targetActivity.endTime ? 'highlight' : 'highlight-todo');
} else if (nn.targetRef.$type === 'bpmn:ExclusiveGateway') { } else if (nn.targetRef.$type === 'bpmn:ExclusiveGateway') {
// canvas.addMarker(nn.id, 'highlight'); 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
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');
@ -133,28 +145,33 @@ export default {
}); });
} else if (n.$type === 'bpmn:ExclusiveGateway') { // } else if (n.$type === 'bpmn:ExclusiveGateway') { //
n.outgoing?.forEach(nn => { n.outgoing?.forEach(nn => {
let targetTask = activityList.find(m => m.key === nn.targetRef.id) let targetTask = activityList.find(m => m.key === nn.targetRef.id);
if (targetTask) { if (targetTask) {
canvas.addMarker(nn.id, targetTask.endTime ? 'highlight' : 'highlight-todo'); canvas.addMarker(nn.id, targetTask.endTime ? 'highlight' : 'highlight-todo');
} }
}) })
} else if (n.$type === 'bpmn:ParallelGateway') { // } else if (n.$type === 'bpmn:ParallelGateway') { //
if (activity) { if (!activity) {
canvas.addMarker(n.id, activity.endTime ? 'highlight' : 'highlight-todo') return
n.outgoing?.forEach(nn => {
const targetTask = activityList.find(m => m.key === nn.targetRef.id)
if (targetTask) {
canvas.addMarker(nn.id, targetTask.endTime ? 'highlight' : 'highlight-todo')
canvas.addMarker(nn.targetRef.id, targetTask.endTime ? 'highlight' : 'highlight-todo')
}
})
} }
// bpmn:ParallelGateway
canvas.addMarker(n.id, this.getActivityHighlightCss(activity));
n.outgoing?.forEach(nn => {
// 线
const targetActivity = activityList.find(m => m.key === nn.targetRef.id)
if (targetActivity) {
canvas.addMarker(nn.id, this.getActivityHighlightCss(targetActivity)); // bpmn:SequenceFlow线
// ... ... bpm:UserTask bpm:UserTask
canvas.addMarker(nn.targetRef.id, this.getActivityHighlightCss(targetActivity));
}
})
} else if (n.$type === 'bpmn:StartEvent') { // } else if (n.$type === 'bpmn:StartEvent') { //
n.outgoing?.forEach(nn => { // outgoing bpmn:SequenceFlow线 n.outgoing?.forEach(nn => { // outgoing bpmn:SequenceFlow线
let fromTask = activityList.find(m => m.key === nn.targetRef.id) // 线
if (fromTask) { let targetActivity = activityList.find(m => m.key === nn.targetRef.id);
canvas.addMarker(nn.id, 'highlight'); if (targetActivity) {
canvas.addMarker(n.id, 'highlight'); canvas.addMarker(nn.id, 'highlight'); // bpmn:SequenceFlow线
canvas.addMarker(n.id, 'highlight'); // bpmn:StartEvent
} }
}); });
} else if (n.$type === 'bpmn:EndEvent') { // } else if (n.$type === 'bpmn:EndEvent') { //
@ -169,10 +186,19 @@ export default {
} }
}) })
}, },
getActivityHighlightCss(activity) {
return activity.endTime ? 'highlight' : 'highlight-todo';
},
getTaskHighlightCss(task) {
if (!task) {
return '';
}
return '';
},
initModelListeners() { initModelListeners() {
const EventBus = this.bpmnModeler.get("eventBus"); const EventBus = this.bpmnModeler.get("eventBus");
const that = this; const that = this;
// , . - , //
EventBus.on('element.hover', function(eventObj) { EventBus.on('element.hover', function(eventObj) {
let element = eventObj ? eventObj.element : null; let element = eventObj ? eventObj.element : null;
that.elementHover(element); that.elementHover(element);
@ -209,6 +235,32 @@ export default {
<style> <style>
/** 处理中 */
.highlight-todo.djs-connection > .djs-visual > path {
stroke: orange !important;
stroke-dasharray: 4px !important;
fill-opacity: 0.2 !important;
}
.highlight-todo.djs-shape .djs-visual > :nth-child(1) {
fill: orange !important;
stroke: orange !important;
stroke-dasharray: 4px !important;
fill-opacity: 0.2 !important;
}
/deep/.highlight-todo.djs-connection > .djs-visual > path {
stroke: orange !important;
stroke-dasharray: 4px !important;
fill-opacity: 0.2 !important;
marker-end: url(#sequenceflow-end-_E7DFDF-_E7DFDF-803g1kf6zwzmcig1y2ulm5egr);
}
/deep/.highlight-todo.djs-shape .djs-visual > :nth-child(1) {
fill: orange !important;
stroke: orange !important;
stroke-dasharray: 4px !important;
fill-opacity: 0.2 !important;
}
/** 通过 */ /** 通过 */
.highlight.djs-shape .djs-visual > :nth-child(1) { .highlight.djs-shape .djs-visual > :nth-child(1) {
fill: green !important; fill: green !important;
@ -248,32 +300,6 @@ export default {
stroke: green !important; stroke: green !important;
} }
/** 处理中 */
.highlight-todo.djs-connection > .djs-visual > path {
stroke: orange !important;
stroke-dasharray: 4px !important;
fill-opacity: 0.2 !important;
}
.highlight-todo.djs-shape .djs-visual > :nth-child(1) {
fill: orange !important;
stroke: orange !important;
stroke-dasharray: 4px !important;
fill-opacity: 0.2 !important;
}
/deep/.highlight-todo.djs-connection > .djs-visual > path {
stroke: orange !important;
stroke-dasharray: 4px !important;
fill-opacity: 0.2 !important;
marker-end: url(#sequenceflow-end-_E7DFDF-_E7DFDF-803g1kf6zwzmcig1y2ulm5egr);
}
/deep/.highlight-todo.djs-shape .djs-visual > :nth-child(1) {
fill: orange !important;
stroke: orange !important;
stroke-dasharray: 4px !important;
fill-opacity: 0.2 !important;
}
/** 不通过 */ /** 不通过 */
.highlight-reject.djs-shape .djs-visual > :nth-child(1) { .highlight-reject.djs-shape .djs-visual > :nth-child(1) {
fill: red !important; fill: red !important;

View File

@ -74,7 +74,7 @@
<div slot="header" class="clearfix"> <div slot="header" class="clearfix">
<span class="el-icon-picture-outline">流程图</span> <span class="el-icon-picture-outline">流程图</span>
</div> </div>
<my-process-viewer key="designer" v-model="bpmnXML" v-bind="bpmnControlForm" :taskData="activityList" /> <my-process-viewer key="designer" v-model="bpmnXML" v-bind="bpmnControlForm" :activityData="activityList"/>
</el-card> </el-card>
<!-- 对话框(转派审批人) --> <!-- 对话框(转派审批人) -->