import React, { useEffect } from 'react'; import { Modal, Form, Input, InputNumber, Radio, message } from 'antd'; import type { FlowEdge } from '../types'; interface EdgeConfigModalProps { visible: boolean; edge: FlowEdge | null; onOk: (edgeId: string, condition: EdgeCondition) => void; onCancel: () => void; } export interface EdgeCondition { type: 'EXPRESSION' | 'DEFAULT'; expression?: string; priority: number; } /** * 边条件配置弹窗 * 复刻 Workflow/Design/ExpressionModal 功能 */ const EdgeConfigModal: React.FC = ({ visible, edge, onOk, onCancel }) => { const [form] = Form.useForm(); // 当edge变化时,更新表单初始值 useEffect(() => { if (visible && edge) { const condition = edge.data?.condition; form.setFieldsValue({ type: condition?.type || 'EXPRESSION', expression: condition?.expression || '', priority: condition?.priority || 10 }); } }, [visible, edge, form]); const handleOk = async () => { if (!edge) return; try { const values = await form.validateFields(); // 验证表达式 if (values.type === 'EXPRESSION') { if (!values.expression || values.expression.trim() === '') { message.error('请输入条件表达式'); return; } // 检查是否包含变量引用 ${...} const hasVariable = /\$\{[\w.]+\}/.test(values.expression); if (!hasVariable) { message.warning('表达式建议包含变量引用,格式:${变量名}'); } } onOk(edge.id, values); } catch (error) { console.error('表单验证失败:', error); } }; const handleCancel = () => { form.resetFields(); onCancel(); }; return (
表达式 默认路径 prevValues.type !== currentValues.type} > {({ getFieldValue }) => { const type = getFieldValue('type'); return type === 'EXPRESSION' ? ( ) : (
默认路径:当没有其他条件分支满足时,将执行此路径
); }}
); }; export default EdgeConfigModal;