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