import React, { useState, useEffect } from 'react'; import { Modal, Form, Input, Tabs, Card, Button, Space, message } from 'antd'; import { SaveOutlined, ReloadOutlined } from '@ant-design/icons'; import type { FlowNode, FlowNodeData } from '../types'; interface NodeConfigModalProps { visible: boolean; node: FlowNode | null; onCancel: () => void; onOk: (nodeId: string, updatedData: Partial) => void; } const { TextArea } = Input; const NodeConfigModal: React.FC = ({ visible, node, onCancel, onOk }) => { const [form] = Form.useForm(); const [loading, setLoading] = useState(false); const [activeTab, setActiveTab] = useState('basic'); // 重置表单数据 useEffect(() => { if (visible && node) { form.setFieldsValue({ label: node.data.label, description: node.data.nodeDefinition?.description || '', // 基础配置 timeout: node.data.configs?.timeout || 3600, retryCount: node.data.configs?.retryCount || 0, priority: node.data.configs?.priority || 'normal', // 输入映射 inputMapping: JSON.stringify(node.data.inputMapping || {}, null, 2), // 输出映射 outputMapping: JSON.stringify(node.data.outputMapping || {}, null, 2), }); } else { form.resetFields(); } }, [visible, node, form]); const handleSubmit = async () => { if (!node) return; try { const values = await form.validateFields(); setLoading(true); // 解析JSON字符串 let inputMapping = {}; let outputMapping = {}; try { inputMapping = values.inputMapping ? JSON.parse(values.inputMapping) : {}; } catch (error) { message.error('输入映射JSON格式错误'); return; } try { outputMapping = values.outputMapping ? JSON.parse(values.outputMapping) : {}; } catch (error) { message.error('输出映射JSON格式错误'); return; } const updatedData: Partial = { label: values.label, configs: { ...node.data.configs, timeout: values.timeout, retryCount: values.retryCount, priority: values.priority, }, inputMapping, outputMapping, }; onOk(node.id, updatedData); message.success('节点配置保存成功'); onCancel(); } catch (error) { console.error('保存节点配置失败:', error); } finally { setLoading(false); } }; const handleReset = () => { form.resetFields(); if (node) { form.setFieldsValue({ label: node.data.label, description: node.data.nodeDefinition?.description || '', timeout: 3600, retryCount: 0, priority: 'normal', inputMapping: '{}', outputMapping: '{}', }); } }; const renderBasicConfig = () => (