fix:流程图组件抽取

This commit is contained in:
shijing 2025-03-27 16:04:11 +08:00
parent 94cbc15ed7
commit d854913b09
1 changed files with 119 additions and 106 deletions

View File

@ -1,11 +1,7 @@
<template> <template>
<el-drawer <div v-if="visible">
v-model="visible"
:title="workflowName"
:size="'90%'"
>
<svg id="mySvg" v-if="visible"></svg> <svg id="mySvg" v-if="visible"></svg>
</el-drawer> </div>
</template> </template>
<script> <script>
@ -15,50 +11,67 @@ import * as d3 from "d3";
export default { export default {
name: "degraD3", name: "degraD3",
props: { props: {
code: { nodes: {
type: String, type:Array,
default: "", default:()=>[]
}, },
edges:{
type:Array,
default:()=>[]
},
rankdir:{
type: String,
default: "DL",
}
}, },
data() { data() {
return { return {
mySvgHeight: null, g:null,
visible:false, visible:false,
isSaving: false, isSaving: false,
params:{} type:""
}; };
}, },
mounted() { watch: {
nodes: {
handler(val) {
console.log(val);
this.updateGraph();
},
deep: true,
},
edges: {
handler(val) {
console.log(val);
this.updateGraph();
},
deep: true,
},
}, },
mounted() {},
methods: { methods: {
open(type=""){ open(){
this.visible = true; this.visible = true;
if(type=='batch'){
this.params.batch = this.code;
}else if(type=='routepack'){
this.params.routepack = this.code;
}
this.handleWatch(); this.handleWatch();
}, },
handleWatch() { handleWatch() {
let that = this; let that = this;
that.limitedWatch = true;
that.$nextTick(() => { that.$nextTick(() => {
var g = new dagreD3.graphlib.Graph().setGraph({ if(that.g!==null){
rankdir: "LR", that.updataGraph();
nodesep: 40, }else{
edgesep: 25, //线 that.g = new dagreD3.graphlib.Graph().setGraph({
ranksep: 20, // rankdir: that.rankdir,
marginx: 80, nodesep: 40,
marginy: 10, edgesep: 25, //线
}); ranksep: 20, //
//state marginx: 80,
that.$API.wpm.batchlog.dag.req(that.params).then((res) => { marginy: 10,
let nodes = res.nodes; });
// //
nodes.forEach((item) => { that.nodes.forEach((item) => {
if(item.id&& item.label){ if(item.id&& item.label){
g.setNode(item.id, { that.g.setNode(item.id, {
// //
label: item.label, label: item.label,
// //
@ -70,81 +83,81 @@ export default {
rx: 5, // rx: 5, //
ry: 5, ry: 5,
}); });
} }
}); });
//线 //线
let transitionList = res.edges; that.edges.forEach((transition0) => {
transitionList.forEach((transition0) => { that.g.setEdge(transition0.source,transition0.target,{
g.setEdge( label: transition0.label,//
transition0.source, style: "fill:#ffffff;stroke:#c0c1c3;stroke-width:1.5px", // 线
transition0.target, });
{ });
// //
label: transition0.label, let render = new dagreD3.render();
// // svg g.
style: "fill:#ffffff;stroke:#c0c1c3;stroke-width:1.5px", // 线 let svg = d3.select("#mySvg");
} let inner = svg.append("g");
); that.inner = inner;
// let condition_expression = transition0.condition_expression; // .
// if (condition_expression.length > 0) { render(inner, that.g);
// let newNodeId = transition0.id let mySvgHeight =document.getElementsByClassName("nodes")[0].getBoundingClientRect().height + 50;
// g.setNode(newNodeId, { let mySvgWdith =document.getElementsByClassName("output")[0].getBoundingClientRect().width+150 ;
// label: "", document.getElementById('mySvg').setAttribute("height", mySvgHeight);
// style: "stroke: #000;fill: #afa", document.getElementById('mySvg').setAttribute("width", mySvgWdith);
// shape: "diamond", }
// }); })
// g.setEdge( },
// transition0.source_state, updataGraph(){
// newNodeId,
// { },
// // //
// label: transition0.name, updateGraph() {
// style: "fill:#ffffff;stroke:#c0c1c3;stroke-width:1.5px", let that = this;
// } //
// ); that.g.nodes().forEach(function (v) {
// condition_expression.forEach((condition_expression0) => { that.g.removeNode(v);
// g.setEdge( });
// newNodeId, that.g.edges().forEach(function (e) {
// condition_expression0.target_state, that.g.removeEdge(e);
// { });
// label: condition_expression0.label,
// style: //
// "fill:#ffffff;stroke:#c0c1c3;stroke-width:1.5px", that.nodes.forEach((item) => {
// } if (item.id && item.label) {
// ); that.g.setNode(item.id, {
// }); label: item.label,
// }else { shape: item.shape,
// g.setEdge( toolText: item.label,
// transition0.source, style: "fill:#fff;stroke:#000",
// transition0.target, labelStyle: "fill:#000;",
// { rx: 5,
// // ry: 5,
// label: transition0.label, });
// // }
// style: "fill:#ffffff;stroke:#c0c1c3;stroke-width:1.5px", // 线 });
// }
// ); //
// } that.edges.forEach((transition0) => {
}); that.g.setEdge(transition0.source, transition0.target, {
// g.nodes().length - 1; label: transition0.label,
// style: "fill:#ffffff;stroke:#c0c1c3;stroke-width:1.5px",
let render = new dagreD3.render();
// svg g.
let svg = d3.select("#mySvg");
let inner = svg.append("g");
// .
render(inner, g);
let mySvgHeight =document.getElementsByClassName("nodes")[0].getBoundingClientRect().height + 50;
let mySvgWdith =document.getElementsByClassName("output")[0].getBoundingClientRect().innerwidth ;
console.log('mySvgWdith',mySvgWdith);
document.getElementById('mySvg').setAttribute("height", mySvgHeight);
document.getElementById('mySvg').setAttribute("width", mySvgWdith);
}); });
}); });
}, let render = new dagreD3.render();
//
render(that.inner, that.g);
// SVG
let mySvgHeight = document.getElementsByClassName("nodes")[0]?.getBoundingClientRect().height + 50;
let mySvgWdith = document.getElementsByClassName("output")[0]?.getBoundingClientRect().width + 150;
closeMark() { //
this.limitedWatch = false; if (mySvgHeight && mySvgWdith) {
// SVG
document.getElementById('mySvg').setAttribute("height", mySvgHeight);
document.getElementById('mySvg').setAttribute("width", mySvgWdith);
} else {
console.log("元素尚未加载,无法更新 SVG 尺寸");
}
}, },
scaleUp() { scaleUp() {
var svg = document.getElementById("mySvg"); var svg = document.getElementById("mySvg");