feat(flowEditor): 添加节点编辑功能和数据保存功能
- 新增节点双击事件,打开节点编辑弹窗 - 实现节点编辑逻辑,支持不同类型的节点 - 添加保存节点和边数据到服务器的功能 - 优化节点和边变化时的数据处理master
parent
1a7b31a35e
commit
4234aa75d9
@ -0,0 +1,111 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { Node } from '@xyflow/react';
|
||||
import { Modal, Button } from '@arco-design/web-react';
|
||||
|
||||
interface NodeEditModalProps {
|
||||
node: Node | any;
|
||||
isOpen: boolean;
|
||||
onSave: (data: any) => void;
|
||||
onClose: () => void;
|
||||
}
|
||||
|
||||
const NodeEditModal: React.FC<NodeEditModalProps> = ({
|
||||
node,
|
||||
isOpen,
|
||||
onSave,
|
||||
onClose
|
||||
}) => {
|
||||
const [title, setTitle] = useState('');
|
||||
const [visible, setVisible] = React.useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
if (node) {
|
||||
setTitle(node.data?.title || '');
|
||||
}
|
||||
}, [node]);
|
||||
|
||||
useEffect(() => {
|
||||
setVisible(isOpen);
|
||||
}, [isOpen]);
|
||||
|
||||
if (!isOpen || !node) return null;
|
||||
|
||||
const handleSave = () => {
|
||||
setVisible(false);
|
||||
onSave({ title });
|
||||
};
|
||||
|
||||
const handleClose = () => {
|
||||
setVisible(false);
|
||||
onClose();
|
||||
};
|
||||
|
||||
// 根据节点类型渲染不同的内容
|
||||
const renderContent = () => {
|
||||
const nodeType = node?.type || 'basic';
|
||||
|
||||
switch (nodeType) {
|
||||
case 'start':
|
||||
return (
|
||||
<div>
|
||||
<h4>开始节点设置</h4>
|
||||
<div>
|
||||
<label>节点标题:</label>
|
||||
<input
|
||||
type="text"
|
||||
value={title}
|
||||
onChange={(e) => setTitle(e.target.value)}
|
||||
style={{ width: '100%', padding: '8px', margin: '10px 0' }}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
case 'end':
|
||||
return (
|
||||
<div>
|
||||
<h4>结束节点设置</h4>
|
||||
<div>
|
||||
<label>节点标题:</label>
|
||||
<input
|
||||
type="text"
|
||||
value={title}
|
||||
onChange={(e) => setTitle(e.target.value)}
|
||||
style={{ width: '100%', padding: '8px', margin: '10px 0' }}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
case 'basic':
|
||||
default:
|
||||
return (
|
||||
<div>
|
||||
<h4>基础节点设置</h4>
|
||||
<div>
|
||||
<label>节点标题:</label>
|
||||
<input
|
||||
type="text"
|
||||
value={title}
|
||||
onChange={(e) => setTitle(e.target.value)}
|
||||
style={{ width: '100%', padding: '8px', margin: '10px 0' }}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Modal
|
||||
title={'节点标题:' + title}
|
||||
visible={visible}
|
||||
onOk={() => handleSave()}
|
||||
onCancel={() => handleClose()}
|
||||
autoFocus={false}
|
||||
focusLock={true}
|
||||
>
|
||||
{renderContent()}
|
||||
</Modal>
|
||||
);
|
||||
};
|
||||
|
||||
export default NodeEditModal;
|
||||
Loading…
Reference in New Issue