|
@@ -7,18 +7,18 @@
|
|
|
</template>
|
|
|
|
|
|
<script setup lang="ts">
|
|
|
-import {createVNode, getCurrentInstance, inject, nextTick, onMounted, provide, reactive, ref, render, watch} from "vue";
|
|
|
-import {Graph, Markup, Shape} from '@antv/x6'
|
|
|
-import {WorkflowFunc} from "@/views/workflow/types";
|
|
|
+import {createVNode, getCurrentInstance, nextTick, onMounted, reactive, ref, render, watch} from "vue";
|
|
|
+import {Graph, Shape} from '@antv/x6'
|
|
|
import {getNodeDefault, lineStyle} from "@/views/workflow/config";
|
|
|
import nodeAdd from './node-add.vue'
|
|
|
import {register} from "@antv/x6-vue-shape";
|
|
|
import WorkflowNode from "./node-index.vue";
|
|
|
import {handleEdge, handleNode} from "@/views/workflow/handle";
|
|
|
-import { Snapline } from '@antv/x6-plugin-snapline'
|
|
|
+import {Snapline} from '@antv/x6-plugin-snapline'
|
|
|
import {ContextMenuTool} from "./context-menu-tool";
|
|
|
+import {useWorkflowStore} from "@/stores/modules/workflow";
|
|
|
+import {NodeType} from "@/views/workflow/types";
|
|
|
|
|
|
-const workflowFuncInject = inject('workflowFunc', {} as WorkflowFunc)
|
|
|
register({
|
|
|
shape: 'workflow-node',
|
|
|
component: WorkflowNode,
|
|
@@ -53,7 +53,7 @@ Graph.registerPortLayout('end', (portsPositionArgs, elemBBox) => {
|
|
|
Graph.registerPortLayout('more', (portsPositionArgs, elemBBox) => {
|
|
|
return portsPositionArgs.map((_, index) => {
|
|
|
nextTick(() => {
|
|
|
- workflowFuncInject.layoutPort(_.nodeId, _.portId)
|
|
|
+ WorkflowStore.layoutPort(_.nodeId, _.portId)
|
|
|
if (edgeTimer) {
|
|
|
clearTimeout(edgeTimer)
|
|
|
}
|
|
@@ -71,7 +71,8 @@ Graph.registerPortLayout('more', (portsPositionArgs, elemBBox) => {
|
|
|
})
|
|
|
Graph.registerNodeTool('contextmenu', ContextMenuTool, true)
|
|
|
Graph.registerEdgeTool('contextmenu', ContextMenuTool, true)
|
|
|
-const emits = defineEmits(['init'])
|
|
|
+const WorkflowStore = useWorkflowStore()
|
|
|
+const emits = defineEmits([])
|
|
|
const props = defineProps({
|
|
|
data: <any>{}
|
|
|
})
|
|
@@ -145,6 +146,7 @@ const initChart = () => {
|
|
|
}
|
|
|
}
|
|
|
})
|
|
|
+ WorkflowStore.init(state.graph)
|
|
|
initNodes()
|
|
|
state.graph.zoomToFit({ maxScale: 1 })
|
|
|
state.graph.centerContent() // 居中显示
|
|
@@ -155,15 +157,14 @@ const initChart = () => {
|
|
|
}),
|
|
|
)
|
|
|
initWatch()
|
|
|
- emits('init', state.graph)
|
|
|
}
|
|
|
const initNodes = () => {
|
|
|
props.data.nodes.forEach(v => {
|
|
|
- state.graph.addNode(handleNode(v, state.graph))
|
|
|
+ state.graph.addNode(handleNode(v))
|
|
|
})
|
|
|
if (props.data.nodes.length === 0) {
|
|
|
- const node = getNodeDefault('root')
|
|
|
- state.graph.addNode(handleNode(node, state.graph))
|
|
|
+ const node = getNodeDefault(NodeType.Root)
|
|
|
+ state.graph.addNode(handleNode(node))
|
|
|
}
|
|
|
}
|
|
|
const initEdges = () => {
|
|
@@ -173,7 +174,7 @@ const initEdges = () => {
|
|
|
targetNode.setData({
|
|
|
edgeSource: v.port || v.source
|
|
|
}, {deep: false})
|
|
|
- state.graph.addEdge(handleEdge(v, state.graph))
|
|
|
+ state.graph.addEdge(handleEdge(v))
|
|
|
})
|
|
|
state.isInitEdges = true
|
|
|
}
|
|
@@ -182,7 +183,7 @@ const initWatch = () => {
|
|
|
state.graph.on('node:click', ({ e, x, y, node, view, port }) => {
|
|
|
setTimeout(() => {
|
|
|
if (!state.isPort) {
|
|
|
- workflowFuncInject.nodeClick(node)
|
|
|
+ WorkflowStore.nodePanel(node)
|
|
|
}
|
|
|
}, 50)
|
|
|
})
|