fix:流程图组件抽取
This commit is contained in:
parent
94cbc15ed7
commit
d854913b09
|
|
@ -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");
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue