|
@@ -1,51 +1,110 @@
|
|
|
<template>
|
|
<template>
|
|
|
- <div class="w-full h-full">
|
|
|
|
|
- <Workflow :workflow="workflow" @click:node="handleNodeClick" @drop="handleDrop" />
|
|
|
|
|
- </div>
|
|
|
|
|
|
|
+ <div class="w-full h-full">
|
|
|
|
|
+ <Workflow :workflow="workflow" @click:node="handleNodeClick" @create:node="handleNodeCreate" @drop="handleDrop"
|
|
|
|
|
+ @run="handleRunWorkflow" />
|
|
|
|
|
+ <RunWork v-model:visible="runVisible" />
|
|
|
|
|
+ <Setter :data="nodeID" v-model:visible="setterVisible" />
|
|
|
|
|
+ </div>
|
|
|
</template>
|
|
</template>
|
|
|
|
|
|
|
|
<script setup lang="ts">
|
|
<script setup lang="ts">
|
|
|
-import { ref } from 'vue'
|
|
|
|
|
|
|
+import { startNode, endNode, httpNode, conditionNode, databaseNode, codeNode, } from '@repo/nodes'
|
|
|
import { Workflow, type IWorkflow, type XYPosition } from '@repo/workflow'
|
|
import { Workflow, type IWorkflow, type XYPosition } from '@repo/workflow'
|
|
|
|
|
+import Setter from "@/components/setter/index.vue"
|
|
|
|
|
+import RunWork from '@/components/RunWork.vue'
|
|
|
|
|
+import type { SourceType } from '@repo/nodes'
|
|
|
|
|
+import { ref } from 'vue'
|
|
|
|
|
|
|
|
const workflow = ref<IWorkflow>({
|
|
const workflow = ref<IWorkflow>({
|
|
|
- id: '1',
|
|
|
|
|
- nodes: [
|
|
|
|
|
- {
|
|
|
|
|
- id: 'node-1',
|
|
|
|
|
- type: 'canvas-node',
|
|
|
|
|
- position: { x: 100, y: 100 },
|
|
|
|
|
- width: 100,
|
|
|
|
|
- height: 100,
|
|
|
|
|
- data: { label: 'Node 1', inputs: [], outputs: [] }
|
|
|
|
|
- },
|
|
|
|
|
- {
|
|
|
|
|
- id: 'node-2',
|
|
|
|
|
- type: 'canvas-node',
|
|
|
|
|
- width: 100,
|
|
|
|
|
- height: 100,
|
|
|
|
|
- position: { x: 400, y: 100 },
|
|
|
|
|
- data: { label: 'Node 1', inputs: [], outputs: [] }
|
|
|
|
|
- }
|
|
|
|
|
- ],
|
|
|
|
|
- edges: [
|
|
|
|
|
- {
|
|
|
|
|
- id: 'edge-1-2',
|
|
|
|
|
- source: 'node-1',
|
|
|
|
|
- target: 'node-2',
|
|
|
|
|
- type: 'canvas-edge',
|
|
|
|
|
- data: {
|
|
|
|
|
- label: 'Edge 1-2'
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- ]
|
|
|
|
|
|
|
+ id: '1',
|
|
|
|
|
+ nodes: [
|
|
|
|
|
+ startNode, // 初始化节点,
|
|
|
|
|
+ endNode, // 初始化节点,
|
|
|
|
|
+ // httpNode,
|
|
|
|
|
+ // conditionNode,
|
|
|
|
|
+ // databaseNode,
|
|
|
|
|
+ // codeNode
|
|
|
|
|
+ ],
|
|
|
|
|
+ edges: [
|
|
|
|
|
+ // {
|
|
|
|
|
+ // id: 'edge-1-2',
|
|
|
|
|
+ // source: 'start-node',
|
|
|
|
|
+ // target: 'http-node',
|
|
|
|
|
+ // type: 'canvas-edge',
|
|
|
|
|
+ // data: {
|
|
|
|
|
+ // label: 'Edge 1-2'
|
|
|
|
|
+ // }
|
|
|
|
|
+ // },
|
|
|
|
|
+ // {
|
|
|
|
|
+ // id: 'edge-1-6',
|
|
|
|
|
+ // source: 'http-node',
|
|
|
|
|
+ // target: 'condition-node',
|
|
|
|
|
+ // type: 'canvas-edge',
|
|
|
|
|
+ // data: {
|
|
|
|
|
+ // label: 'Edge 1-2'
|
|
|
|
|
+ // }
|
|
|
|
|
+ // },
|
|
|
|
|
+ // {
|
|
|
|
|
+ // id: 'edge-1-5',
|
|
|
|
|
+ // source: 'condition-node',
|
|
|
|
|
+ // target: 'data-node',
|
|
|
|
|
+ // type: 'canvas-edge',
|
|
|
|
|
+ // data: {
|
|
|
|
|
+ // label: 'Edge 1-2'
|
|
|
|
|
+ // }
|
|
|
|
|
+ // },
|
|
|
|
|
+ // {
|
|
|
|
|
+ // id: 'edge-1-3',
|
|
|
|
|
+ // source: 'database-node',
|
|
|
|
|
+ // target: 'code-node',
|
|
|
|
|
+ // type: 'canvas-edge',
|
|
|
|
|
+ // data: {
|
|
|
|
|
+ // label: 'Edge 1-2'
|
|
|
|
|
+ // }
|
|
|
|
|
+ // },
|
|
|
|
|
+
|
|
|
|
|
+ // {
|
|
|
|
|
+ // id: 'edge-1-4',
|
|
|
|
|
+ // source: 'code-node',
|
|
|
|
|
+ // target: 'end-node',
|
|
|
|
|
+ // type: 'canvas-edge',
|
|
|
|
|
+ // data: {
|
|
|
|
|
+ // label: 'Edge 1-2'
|
|
|
|
|
+ // }
|
|
|
|
|
+ // }
|
|
|
|
|
+ ]
|
|
|
})
|
|
})
|
|
|
|
|
+const nodeID = ref('')
|
|
|
|
|
+const setterVisible = ref(false)
|
|
|
|
|
+const runVisible = ref(false)
|
|
|
|
|
+const handleRunWorkflow = () => {
|
|
|
|
|
+ runVisible.value = true
|
|
|
|
|
+ console.log('run workflow')
|
|
|
|
|
+}
|
|
|
|
|
+const handleNodeCreate = (value: SourceType) => {
|
|
|
|
|
+ console.log(value)
|
|
|
|
|
+
|
|
|
|
|
+ const nodeMap: Record<string, any> = {
|
|
|
|
|
+ 'http': httpNode,
|
|
|
|
|
+ 'condition': conditionNode,
|
|
|
|
|
+ 'code': codeNode,
|
|
|
|
|
+ 'database': databaseNode
|
|
|
|
|
+ }
|
|
|
|
|
+ const nodeToAdd = nodeMap[value.type]
|
|
|
|
|
|
|
|
|
|
+ // 如果存在对应节点则添加
|
|
|
|
|
+ if (nodeToAdd) {
|
|
|
|
|
+ workflow.value.nodes.push(nodeToAdd)
|
|
|
|
|
+ }
|
|
|
|
|
+ console.log(workflow.value.nodes, 'workflow.nodes')
|
|
|
|
|
+}
|
|
|
const handleNodeClick = (id: string, position: XYPosition) => {
|
|
const handleNodeClick = (id: string, position: XYPosition) => {
|
|
|
- console.log('click node', id, position)
|
|
|
|
|
|
|
+ console.log('click node', id, position)
|
|
|
|
|
+ nodeID.value = id
|
|
|
|
|
+ setterVisible.value = true
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
const handleDrop = (position: XYPosition, event: DragEvent) => {
|
|
const handleDrop = (position: XYPosition, event: DragEvent) => {
|
|
|
- console.log('drag and drop at', position, event)
|
|
|
|
|
|
|
+ console.log('drag and drop at', position, event)
|
|
|
}
|
|
}
|
|
|
</script>
|
|
</script>
|