node-add.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <template>
  2. <template v-if="port?.group === 'start'">
  3. <div class="port">
  4. <div/>
  5. </div>
  6. </template>
  7. <template v-else>
  8. <ElPopover placement="right" trigger="click">
  9. <template #reference>
  10. <div class="port">
  11. <ElTooltip
  12. placement="top"
  13. content="123"
  14. raw-content
  15. >
  16. <div/>
  17. </ElTooltip>
  18. </div>
  19. </template>
  20. <div class="node-add">
  21. <div class="node-add-item __hover" @click="onAddNode('test')">测试节点</div>
  22. <div class="node-add-item __hover" @click="onAddNode('if-else')">条件分支</div>
  23. </div>
  24. </ElPopover>
  25. </template>
  26. </template>
  27. <script setup lang="ts">
  28. import {getCurrentInstance, inject, reactive, ref} from "vue";
  29. import { ElPopover, ElTooltip } from 'element-plus';
  30. import {getNodeDefault} from "@/views/workflow/config";
  31. import {WorkflowFunc} from "@/views/workflow/types";
  32. import {handleEdge, handleNode} from "@/views/workflow/handle";
  33. const emits = defineEmits([])
  34. const props = defineProps({
  35. port: <any>{},
  36. node: <any>{},
  37. graph: <any>{},
  38. })
  39. const {proxy}: any = getCurrentInstance()
  40. const state: any = reactive({})
  41. const onAddNode = (type) => {
  42. const node = getNodeDefault(type)
  43. const sons = props.graph.getSuccessors(props.node, {breadthFirst: true, deep: false, distance: 1}).filter(v => v.data.edgeSource === props.port.id)
  44. console.log(sons)
  45. const diff = 100
  46. let X = 0
  47. let Y = 0
  48. if (sons.length > 0) {
  49. sons.forEach(s => {
  50. const {x, y} = s.position()
  51. const {width, height} = s.size()
  52. X = Math.max(x, X)
  53. Y = Math.max(y + height, Y)
  54. })
  55. Y += diff
  56. } else {
  57. const {x, y} = props.node.position()
  58. const {width, height} = props.node.size()
  59. X = x + width + diff
  60. Y = y
  61. }
  62. node.x = X
  63. node.y = Y
  64. const edge = {
  65. target: node.id,
  66. source: props.port.args.nodeId,
  67. port: '',
  68. }
  69. console.log(props.port)
  70. if (props.port.args.type === 'more') {
  71. edge.port = props.port.id
  72. node.data.edgeSource = props.port.id
  73. } else {
  74. node.data.edgeSource = `${props.node.id}_end`
  75. }
  76. console.log(node)
  77. console.log(edge)
  78. props.graph.addNode(handleNode(node))
  79. props.graph.addEdge(handleEdge(edge))
  80. }
  81. </script>
  82. <style lang="scss" scoped>
  83. .port {
  84. width: 100%;
  85. height: 100%;
  86. >div {
  87. width: 100%;
  88. height: 100%;
  89. border: 1px solid #8f8f8f;
  90. background-color: #ffffff;
  91. border-radius: 50%;
  92. }
  93. }
  94. .node-add {
  95. width: 100px;
  96. }
  97. </style>