Commit 2ba2f3bb authored by 刘殿昕's avatar 刘殿昕

如何判定流程闭环?结构复杂的话动态规划显然不是一个好办法

parent 602241be
...@@ -5,39 +5,17 @@ ...@@ -5,39 +5,17 @@
<div class="node-container"> <div class="node-container">
<p class="label_head">节点类型</p> <p class="label_head">节点类型</p>
<p class="label_explanation">请拖拽添加到流程中</p> <p class="label_explanation">请拖拽添加到流程中</p>
<el-input-number <el-input-number v-model="scale_num" @change="handleChange" :step="10" :step-strictly="true" :min="50" :max="150" label="描述文字"></el-input-number>
v-model="scale_num" <span class="node-item" v-for="(item, index) in nodeItemList" :key="index" @mousedown="evt => nodeItemMouseDown(evt, item.value)">{{item.label}}</span>
@change="handleChange"
:step="10"
:step-strictly="true"
:min="50"
:max="150"
label="描述文字"
></el-input-number>
<span
class="node-item"
v-for="(item, index) in nodeItemList"
:key="index"
@mousedown="evt => nodeItemMouseDown(evt, item.value)"
>{{item.label}}</span>
</div> </div>
<div class="flow-container" :class="`scale${scale_num}`" ref="flowContainer"> <div class="flow-container" :class="`scale${scale_num}`" ref="flowContainer">
<super-flow <super-flow ref="superFlow" :node-list="nodeList" :link-list="linkList" :link-menu="linkMenu" :link-base-style="linkBaseStyle" :link-style="linkStyle" :link-desc="linkDesc" :origin="origin">
ref="superFlow"
:node-list="nodeList"
:link-list="linkList"
:link-menu="linkMenu"
:link-base-style="linkBaseStyle"
:link-style="linkStyle"
:link-desc="linkDesc"
:origin="origin"
>
<template v-slot:node="{meta}"> <template v-slot:node="{meta}">
<div <div :class="{'flow-node-begin': meta.type == 0, 'flow-node-end': meta.type == 1, 'flow-node-default': meta.type == 2}" :id="meta.id">
:class="{'flow-node-begin': meta.type == 'begin', 'flow-node-end': meta.type == 'end', 'flow-node-default': meta.type == 'default'}" <div @click="clickItem(meta)">
:id="meta.id" {{meta.name}}
@click="clickItem(meta)" </div>
>{{meta.name}}</div> </div>
</template> </template>
</super-flow> </super-flow>
</div> </div>
...@@ -48,7 +26,7 @@ ...@@ -48,7 +26,7 @@
<script> <script>
const drawerType = { const drawerType = {
node: 0, node: 0,
link: 1, link: 1
}; };
export default { export default {
data() { data() {
...@@ -90,14 +68,14 @@ export default { ...@@ -90,14 +68,14 @@ export default {
} else { } else {
this.$refs.linkSetting.clearValidate(); this.$refs.linkSetting.clearValidate();
} }
}, }
}, },
linkSetting: { linkSetting: {
desc: "", desc: ""
}, },
nodeSetting: { nodeSetting: {
name: "", name: "",
desc: "", desc: ""
}, },
dragConf: { dragConf: {
isDown: false, isDown: false,
...@@ -107,7 +85,7 @@ export default { ...@@ -107,7 +85,7 @@ export default {
clientX: 0, clientX: 0,
clientY: 0, clientY: 0,
ele: null, ele: null,
info: null, info: null
}, },
nodeItemList: [ nodeItemList: [
{ {
...@@ -118,9 +96,9 @@ export default { ...@@ -118,9 +96,9 @@ export default {
meta: { meta: {
label: "开始开始开始开始开始", label: "开始开始开始开始开始",
name: "开始开始开始开始开始", name: "开始开始开始开始开始",
type: "begin", type: 0
}, }
}, }
}, },
{ {
label: "结束", label: "结束",
...@@ -130,9 +108,9 @@ export default { ...@@ -130,9 +108,9 @@ export default {
meta: { meta: {
label: "结束", label: "结束",
name: "结束", name: "结束",
type: "end", type: 1
}, }
}, }
}, },
{ {
label: "普通节点", label: "普通节点",
...@@ -142,27 +120,27 @@ export default { ...@@ -142,27 +120,27 @@ export default {
meta: { meta: {
label: "普通节点", label: "普通节点",
name: "普通节点", name: "普通节点",
type: "default", type: 2
}, }
}, }
}, }
], ],
linkMenu: [ linkMenu: [
[ [
{ {
label: "删除", label: "删除",
selected: (link) => { selected: link => {
console.log(link); console.log(link);
link.remove(); link.remove();
}, }
}, },
{ {
label: "编辑", label: "编辑",
selected: (link) => { selected: link => {
this.drawerConf.open(drawerType.link, link); this.drawerConf.open(drawerType.link, link);
}, }
}, }
], ]
], ],
linkBaseStyle: { linkBaseStyle: {
color: "#666666", // line 颜色 color: "#666666", // line 颜色
...@@ -172,8 +150,8 @@ export default { ...@@ -172,8 +150,8 @@ export default {
font: "14px Arial", // line 描述文字 字体设置 参考 canvas font font: "14px Arial", // line 描述文字 字体设置 参考 canvas font
dotted: false, // 是否是虚线 dotted: false, // 是否是虚线
lineDash: [4, 4], // 虚线时生效 lineDash: [4, 4], // 虚线时生效
background: "rgba(255,255,255,0.6)", // 描述文字背景色 background: "rgba(255,255,255,0.6)" // 描述文字背景色
}, }
}; };
}, },
mounted() { mounted() {
...@@ -213,7 +191,7 @@ export default { ...@@ -213,7 +191,7 @@ export default {
top, top,
right, right,
bottom, bottom,
left, left
} = this.$refs.flowContainer.getBoundingClientRect(); } = this.$refs.flowContainer.getBoundingClientRect();
// 判断鼠标是否进入 flow container // 判断鼠标是否进入 flow container
if ( if (
...@@ -232,7 +210,6 @@ export default { ...@@ -232,7 +210,6 @@ export default {
clientY = bottom; clientY = bottom;
} }
// 获取拖动元素左上角相对 super flow 区域原点坐标 // 获取拖动元素左上角相对 super flow 区域原点坐标
console.log(top, right, bottom, left, clientX, clientY);
const coordinate = this.$refs.superFlow.getMouseCoordinate( const coordinate = this.$refs.superFlow.getMouseCoordinate(
clientX - conf.offsetLeft, clientX - conf.offsetLeft,
clientY - conf.offsetTop clientY - conf.offsetTop
...@@ -240,7 +217,7 @@ export default { ...@@ -240,7 +217,7 @@ export default {
// 添加节点 // 添加节点
this.$refs.superFlow.addNode({ this.$refs.superFlow.addNode({
coordinate, coordinate,
...conf.info, ...conf.info
}); });
conf.isMove = false; conf.isMove = false;
} }
...@@ -251,7 +228,6 @@ export default { ...@@ -251,7 +228,6 @@ export default {
}, },
nodeItemMouseDown(evt, info) { nodeItemMouseDown(evt, info) {
info.meta.id = parseInt(Math.random() * 1000 * 1000); info.meta.id = parseInt(Math.random() * 1000 * 1000);
console.log(evt, info);
const { clientX, clientY, currentTarget } = evt; const { clientX, clientY, currentTarget } = evt;
const { top, left } = evt.currentTarget.getBoundingClientRect(); const { top, left } = evt.currentTarget.getBoundingClientRect();
const conf = this.dragConf; const conf = this.dragConf;
...@@ -263,7 +239,7 @@ export default { ...@@ -263,7 +239,7 @@ export default {
clientY: clientY, clientY: clientY,
info, info,
ele, ele,
isDown: true, isDown: true
}); });
ele.style.position = "fixed"; ele.style.position = "fixed";
ele.style.margin = "0"; ele.style.margin = "0";
...@@ -275,10 +251,10 @@ export default { ...@@ -275,10 +251,10 @@ export default {
console.log(item); console.log(item);
}, },
getData() { getData() {
console.log(this.$refs.superFlow.toJSON()); return this.$refs.superFlow.toJSON();
},
handleChange() {},
}, },
handleChange() {}
}
}; };
</script> </script>
...@@ -296,6 +272,7 @@ export default { ...@@ -296,6 +272,7 @@ export default {
height: 800px; height: 800px;
background-color: #f5f5f5; background-color: #f5f5f5;
@list-width: 200px; @list-width: 200px;
position: relative;
> .node-container { > .node-container {
width: @list-width; width: @list-width;
position: absolute; position: absolute;
...@@ -326,6 +303,10 @@ export default { ...@@ -326,6 +303,10 @@ export default {
box-shadow: none; box-shadow: none;
border: none; border: none;
background-color: transparent; background-color: transparent;
border-radius: 8px;
&:focus {
box-shadow: 1px 1px 8px rgba(0, 0, 0, 0.8);
}
.flow-node-begin { .flow-node-begin {
width: 100%; width: 100%;
height: 100%; height: 100%;
...@@ -338,9 +319,6 @@ export default { ...@@ -338,9 +319,6 @@ export default {
text-overflow: ellipsis; text-overflow: ellipsis;
border-radius: 8px; border-radius: 8px;
border: 2px solid #444; border: 2px solid #444;
&:focus {
border: 2px solid #0f0;
}
} }
.flow-node-end { .flow-node-end {
width: 100%; width: 100%;
...@@ -353,9 +331,6 @@ export default { ...@@ -353,9 +331,6 @@ export default {
text-overflow: ellipsis; text-overflow: ellipsis;
border-radius: 8px; border-radius: 8px;
border: 2px solid #f80; border: 2px solid #f80;
&:focus {
border: 2px solid #0f0;
}
} }
.flow-node-default { .flow-node-default {
width: 100%; width: 100%;
...@@ -368,9 +343,6 @@ export default { ...@@ -368,9 +343,6 @@ export default {
text-overflow: ellipsis; text-overflow: ellipsis;
border-radius: 8px; border-radius: 8px;
border: 2px solid #3a9; border: 2px solid #3a9;
&:focus {
border: 2px solid #0f0;
}
} }
} }
} }
...@@ -391,9 +363,6 @@ export default { ...@@ -391,9 +363,6 @@ export default {
&:hover { &:hover {
box-shadow: 1px 1px 8px rgba(0, 0, 0, 0.4); box-shadow: 1px 1px 8px rgba(0, 0, 0, 0.4);
} }
&:focus {
background-color: chocolate;
}
} }
</style> </style>
......
<template> <template>
<div> <div class="design_contain">
<div>
<el-button @click="getData">获取参数</el-button> <el-button @click="getData">获取参数</el-button>
</div> <WorkFlow ref="workFlow" />
</div> </div>
</template> </template>
<script> <script>
import WorkFlow from "@/components/work-flow/super-flow";
export default { export default {
components: {
WorkFlow
},
methods: { methods: {
getData() {} getData() {
let self = this;
let data = self.$refs.workFlow.getData();
console.log(data);
let start_num = 0;
let end_num = 0;
let start_id = "";
let end_id = "";
let start_before = 0;
let end_after = 0;
data.nodeList.forEach(item => {
if (item.meta.type == 0) {
start_num++;
start_id = item.id;
}
if (item.meta.type == 1) {
end_num++;
end_id = item.id;
}
});
data.linkList.forEach(item => {
if (start_id == item.endId) {
start_before++;
}
if (end_id == item.startId) {
end_after++;
}
});
if (start_num != 1 || end_num != 1) {
this.$message({
message: "开始节点与结束节点均应有且只有一个",
type: "warning"
});
} else if (start_before != 0) {
this.$message({
message: "开始节点前面不应连接其它节点",
type: "warning"
});
} else if (end_after != 0) {
this.$message({
message: "结束节点后面不应连接其它节点",
type: "warning"
});
}
}
} }
}; };
</script> </script>
<style scoped>
.design_contain {
width: 100%;
padding: 0 20px;
margin-bottom: 20px;
}
</style>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment