feat(web): 完成流程图外部加载
This commit is contained in:
@@ -1,14 +1,5 @@
|
|||||||
import {PlusCircleFilled, SaveFilled} from '@ant-design/icons'
|
import {PlusCircleFilled, SaveFilled} from '@ant-design/icons'
|
||||||
import {
|
import {Background, BackgroundVariant, Controls, MiniMap, type Node, type NodeProps, ReactFlow} from '@xyflow/react'
|
||||||
Background,
|
|
||||||
BackgroundVariant,
|
|
||||||
Controls,
|
|
||||||
type Edge,
|
|
||||||
MiniMap,
|
|
||||||
type Node,
|
|
||||||
type NodeProps,
|
|
||||||
ReactFlow,
|
|
||||||
} from '@xyflow/react'
|
|
||||||
import {useMount} from 'ahooks'
|
import {useMount} from 'ahooks'
|
||||||
import type {Schema} from 'amis'
|
import type {Schema} from 'amis'
|
||||||
import {Button, Drawer, Dropdown, message, Space} from 'antd'
|
import {Button, Drawer, Dropdown, message, Space} from 'antd'
|
||||||
@@ -38,22 +29,6 @@ const FlowableDiv = styled.div`
|
|||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
const initialNodes: Node[] = [
|
|
||||||
{
|
|
||||||
id: 'BMFP3Eov94',
|
|
||||||
type: 'start-amis-node',
|
|
||||||
position: {x: 10, y: 100},
|
|
||||||
data: {},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 'PYK8LjduQ1',
|
|
||||||
type: 'end-amis-node',
|
|
||||||
position: {x: 500, y: 100},
|
|
||||||
data: {},
|
|
||||||
},
|
|
||||||
]
|
|
||||||
const initialEdges: Edge[] = []
|
|
||||||
|
|
||||||
function FlowEditor() {
|
function FlowEditor() {
|
||||||
const [messageApi, contextHolder] = message.useMessage()
|
const [messageApi, contextHolder] = message.useMessage()
|
||||||
const [nodeDef] = useState<{
|
const [nodeDef] = useState<{
|
||||||
@@ -79,7 +54,7 @@ function FlowEditor() {
|
|||||||
])
|
])
|
||||||
const [open, setOpen] = useState(false)
|
const [open, setOpen] = useState(false)
|
||||||
|
|
||||||
const {getData, getDataById, setDataById} = useDataStore()
|
const {data, setData, getDataById, setDataById} = useDataStore()
|
||||||
const {
|
const {
|
||||||
nodes,
|
nodes,
|
||||||
addNode,
|
addNode,
|
||||||
@@ -153,7 +128,7 @@ function FlowEditor() {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
]
|
],
|
||||||
},
|
},
|
||||||
getDataById(id),
|
getDataById(id),
|
||||||
),
|
),
|
||||||
@@ -163,6 +138,95 @@ function FlowEditor() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
useMount(() => {
|
useMount(() => {
|
||||||
|
// language=JSON
|
||||||
|
let initialData = JSON.parse(`{
|
||||||
|
"nodes": [
|
||||||
|
{
|
||||||
|
"id": "BMFP3Eov94",
|
||||||
|
"type": "start-amis-node",
|
||||||
|
"position": {
|
||||||
|
"x": 10,
|
||||||
|
"y": 100
|
||||||
|
},
|
||||||
|
"data": {},
|
||||||
|
"measured": {
|
||||||
|
"width": 256,
|
||||||
|
"height": 83
|
||||||
|
},
|
||||||
|
"selected": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "PYK8LjduQ1",
|
||||||
|
"type": "end-amis-node",
|
||||||
|
"position": {
|
||||||
|
"x": 654,
|
||||||
|
"y": 332
|
||||||
|
},
|
||||||
|
"data": {},
|
||||||
|
"measured": {
|
||||||
|
"width": 256,
|
||||||
|
"height": 83
|
||||||
|
},
|
||||||
|
"selected": false,
|
||||||
|
"dragging": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "nCm-ij5I6o",
|
||||||
|
"type": "llm-amis-node",
|
||||||
|
"position": {
|
||||||
|
"x": 318,
|
||||||
|
"y": 208
|
||||||
|
},
|
||||||
|
"data": {},
|
||||||
|
"measured": {
|
||||||
|
"width": 256,
|
||||||
|
"height": 83
|
||||||
|
},
|
||||||
|
"selected": true,
|
||||||
|
"dragging": false
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"edges": [
|
||||||
|
{
|
||||||
|
"source": "BMFP3Eov94",
|
||||||
|
"target": "nCm-ij5I6o",
|
||||||
|
"id": "xy-edge__BMFP3Eov94-nCm-ij5I6o"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"source": "nCm-ij5I6o",
|
||||||
|
"target": "PYK8LjduQ1",
|
||||||
|
"id": "xy-edge__nCm-ij5I6o-PYK8LjduQ1"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"data": {
|
||||||
|
"BMFP3Eov94": {
|
||||||
|
"inputs": {
|
||||||
|
"文件名": {
|
||||||
|
"type": "text"
|
||||||
|
},
|
||||||
|
"文件描述": {
|
||||||
|
"type": "text",
|
||||||
|
"description": "文件描述"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"nCm-ij5I6o": {
|
||||||
|
"model": "qwen3",
|
||||||
|
"outputs": {
|
||||||
|
"text": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"systemPrompt": "你是个沙雕"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}`)
|
||||||
|
let initialNodes = initialData['nodes'] ?? []
|
||||||
|
let initialEdges = initialData['edges'] ?? []
|
||||||
|
|
||||||
|
let initialNodeData = initialData['data'] ?? {}
|
||||||
|
setData(initialNodeData)
|
||||||
|
|
||||||
for (let node of initialNodes) {
|
for (let node of initialNodes) {
|
||||||
node.data = {
|
node.data = {
|
||||||
getDataById,
|
getDataById,
|
||||||
@@ -179,7 +243,10 @@ function FlowEditor() {
|
|||||||
<FlowableDiv>
|
<FlowableDiv>
|
||||||
{contextHolder}
|
{contextHolder}
|
||||||
<Space className="toolbar">
|
<Space className="toolbar">
|
||||||
<Button type="primary" onClick={() => console.log(JSON.stringify(getData()))}>
|
<Button type="primary" onClick={() => {
|
||||||
|
let saveData = {nodes, edges, data}
|
||||||
|
console.log(JSON.stringify(saveData, null, 2))
|
||||||
|
}}>
|
||||||
<SaveFilled/>
|
<SaveFilled/>
|
||||||
保存
|
保存
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
@@ -9,7 +9,9 @@ export const useDataStore = create<{
|
|||||||
}>((set, get) => ({
|
}>((set, get) => ({
|
||||||
data: {},
|
data: {},
|
||||||
getData: () => get().data,
|
getData: () => get().data,
|
||||||
setData: (data) => set(data),
|
setData: (data) => set({
|
||||||
|
data: data
|
||||||
|
}),
|
||||||
getDataById: id => get().data[id],
|
getDataById: id => get().data[id],
|
||||||
setDataById: (id, data) => {
|
setDataById: (id, data) => {
|
||||||
let updateData = get().data
|
let updateData = get().data
|
||||||
|
|||||||
Reference in New Issue
Block a user