Преглед на файлове

连接桩子节点位置

CzRger преди 4 месеца
родител
ревизия
24b6874542
променени са 3 файла, в които са добавени 12 реда и са изтрити 5 реда
  1. 4 0
      src/views/workflow/chart/index.vue
  2. 7 5
      src/views/workflow/chart/node-add.vue
  3. 1 0
      src/views/workflow/types.ts

+ 4 - 0
src/views/workflow/chart/index.vue

@@ -159,6 +159,10 @@ const initNodes = () => {
 }
 const initEdges = () => {
   props.data.edges.forEach(v => {
+    const targetNode = state.graph.getCellById(v.target)
+    targetNode.setData({
+      edgeSource: v.port || v.source
+    })
     state.graph.addEdge(handleEdge(v))
   })
 }

+ 7 - 5
src/views/workflow/chart/node-add.vue

@@ -41,10 +41,8 @@ const props = defineProps({
 const {proxy}: any = getCurrentInstance()
 const state: any = reactive({})
 const onAddNode = (type) => {
-  console.log(props.port)
   const node = getNodeDefault(type)
-  console.log(props.node.getChildren())
-  const sons = props.graph.getSuccessors(props.node, {breadthFirst: true, deep: false, distance: 1})
+  const sons = props.graph.getSuccessors(props.node, {breadthFirst: true, deep: false, distance: 1}).filter(v => v.data.edgeSource === props.port.id)
   const diff = 100
   let X = 0
   let Y = 0
@@ -56,6 +54,7 @@ const onAddNode = (type) => {
       X = Math.max(x, X)
       Y = Math.max(y + height, Y)
     })
+    Y += diff
   } else {
     const {x, y} = props.node.position()
     const {width, height} = props.node.size()
@@ -64,8 +63,7 @@ const onAddNode = (type) => {
   }
 
   node.x = X
-  node.y = Y + diff
-  props.graph.addNode(handleNode(node))
+  node.y = Y
   const edge = {
     target: node.id,
     source: props.port.args.nodeId,
@@ -73,7 +71,11 @@ const onAddNode = (type) => {
   }
   if (props.port.args.type === 'more') {
     edge.port = props.port.id
+    node.data.edgeSource = props.port.id
+  } else {
+    node.data.edgeSource = `${props.node.id}_end`
   }
+  props.graph.addNode(handleNode(node))
   props.graph.addEdge(handleEdge(edge))
 }
 </script>

+ 1 - 0
src/views/workflow/types.ts

@@ -14,6 +14,7 @@ export type NodeDataStruct = {
   title: string
   type: 'test' | 'root' | 'if-else'
   ports?: NodePortStruct[]
+  edgeSource?: string
 }
 
 export type NodePortStruct = {