import React, { useEffect, useState } from 'react'; import { Tabs } from 'antd'; import { Cell } from '@antv/x6'; import type { WorkflowNodeDefinition, ConfigurableNodeDefinition } from "../nodes/types"; import { Sheet, SheetContent, SheetHeader, SheetTitle, } from "@/components/ui/sheet"; import { Button } from "@/components/ui/button"; import { convertJsonSchemaToColumns } from '@/utils/jsonSchemaUtils'; import { BetaSchemaForm } from '@ant-design/pro-components'; interface NodeConfigModalProps { visible: boolean; node: Cell | null; nodeDefinition: WorkflowNodeDefinition | null; onOk: (values: any) => void; onCancel: () => void; } interface FormData { configs?: Record; inputMapping?: Record; outputMapping?: Record; } const NodeConfigModal: React.FC = ({ visible, node, nodeDefinition, onOk, onCancel, }) => { const [formData, setFormData] = useState({}); const [activeTab, setActiveTab] = useState('config'); // 判断是否为可配置节点 const isConfigurableNode = (def: WorkflowNodeDefinition): def is ConfigurableNodeDefinition => { return 'inputMappingSchema' in def || 'outputMappingSchema' in def; }; useEffect(() => { if (nodeDefinition && node) { // 从节点数据中获取现有配置 const nodeData = node.getData() || {}; // 准备默认的基本信息配置 const defaultConfig = { nodeName: nodeDefinition.nodeName, // 默认节点名称 nodeCode: nodeDefinition.nodeCode, // 默认节点编码 description: nodeDefinition.description // 默认节点描述 }; // 合并默认值和已保存的配置 setFormData({ configs: { ...defaultConfig, ...(nodeData.configs || {}) }, inputMapping: nodeData.inputMapping || {}, outputMapping: nodeData.outputMapping || {}, }); } else { setFormData({}); } }, [nodeDefinition, node]); const handleSubmit = () => { onOk(formData); }; const handleConfigChange = (values: Record) => { setFormData(prev => ({ ...prev, configs: values })); }; const handleInputMappingChange = (values: Record) => { setFormData(prev => ({ ...prev, inputMapping: values })); }; const handleOutputMappingChange = (values: Record) => { setFormData(prev => ({ ...prev, outputMapping: values })); }; if (!nodeDefinition) { return null; } // 构建Tabs配置 const tabItems = [ { key: 'config', label: '基本配置', children: (
handleConfigChange(allValues)} submitter={false} />
), }, ]; // 如果是可配置节点,添加输入和输出映射TAB if (isConfigurableNode(nodeDefinition)) { if (nodeDefinition.inputMappingSchema) { tabItems.push({ key: 'input', label: '输入映射', children: (
handleInputMappingChange(allValues)} submitter={false} />
), }); } if (nodeDefinition.outputMappingSchema) { tabItems.push({ key: 'output', label: '输出映射', children: (
handleOutputMappingChange(allValues)} submitter={false} />
), }); } } return ( !open && onCancel()}> 编辑节点 - {nodeDefinition.nodeName}
); }; export default NodeConfigModal;