feat(web): 增加节点分组

This commit is contained in:
v-zhangjc9
2025-07-12 19:09:47 +08:00
parent 528e66c497
commit 60f6b79167
3 changed files with 40 additions and 22 deletions

View File

@@ -1,14 +1,14 @@
import {PlusCircleFilled, RollbackOutlined, SaveFilled} from '@ant-design/icons'
import {Background, BackgroundVariant, Controls, MiniMap, ReactFlow} from '@xyflow/react'
import {Button, Dropdown, message, Popconfirm, Space} from 'antd'
import {arrToMap, randomId} from 'licia'
import {arrToMap, isEqual, randomId, unique} from 'licia'
import {useEffect} from 'react'
import {useNavigate} from 'react-router'
import styled from 'styled-components'
import '@xyflow/react/dist/style.css'
import {commonInfo} from '../../util/amis.tsx'
import {checkAddConnection, checkAddNode, checkSave} from './FlowChecker.tsx'
import NodeRegistry from './NodeRegistry.tsx'
import {NodeRegistry, NodeRegistryMap} from './NodeRegistry.tsx'
import {useContextStore} from './store/ContextStore.ts'
import {useDataStore} from './store/DataStore.ts'
import {useFlowStore} from './store/FlowStore.ts'
@@ -88,7 +88,13 @@ function FlowEditor(props: FlowEditorProps) {
<Space className="toolbar">
<Dropdown
menu={{
items: Object.keys(NodeRegistry).map(key => ({key: key, label: NodeRegistry[key]!.name})),
items: unique(NodeRegistry.map(i => i.group))
.map(group => ({
type: 'group',
label: group,
children: NodeRegistry.filter(i => isEqual(group, i.group))
.map(i => ({key: i.key, label: i.name}))
})),
onClick: ({key}) => {
try {
if (commonInfo.debug) {
@@ -97,7 +103,7 @@ function FlowEditor(props: FlowEditorProps) {
checkAddNode(key, nodes, edges)
let nodeId = randomId(10, 'qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM')
let define = NodeRegistry[key]
let define = NodeRegistryMap[key]
setDataById(
nodeId,
@@ -171,7 +177,7 @@ function FlowEditor(props: FlowEditorProps) {
}
}}
// @ts-ignore
nodeTypes={arrToMap(Object.keys(NodeRegistry), key => NodeRegistry[key]!.component)}
nodeTypes={arrToMap(Object.keys(NodeRegistryMap), key => NodeRegistryMap[key]!.component)}
>
<Controls/>
<MiniMap/>