|
|
|
@ -1,172 +1,26 @@
|
|
|
|
import React, { useState, useEffect } from 'react';
|
|
|
|
import React from 'react';
|
|
|
|
import { NodeEditorProps } from './index';
|
|
|
|
import { NodeEditorProps } from './index';
|
|
|
|
import { Input, Select, Typography, Table, Button } from '@arco-design/web-react';
|
|
|
|
import { Typography } from '@arco-design/web-react';
|
|
|
|
import { IconUnorderedList, IconDelete } from '@arco-design/web-react/icon';
|
|
|
|
import { IconUnorderedList } from '@arco-design/web-react/icon';
|
|
|
|
|
|
|
|
import ParamsTable from './ParamsTable';
|
|
|
|
|
|
|
|
|
|
|
|
const EndNodeEditor: React.FC<NodeEditorProps> = ({
|
|
|
|
const EndNodeEditor: React.FC<NodeEditorProps> = ({
|
|
|
|
node,
|
|
|
|
node,
|
|
|
|
nodeData,
|
|
|
|
nodeData,
|
|
|
|
updateNodeData
|
|
|
|
updateNodeData
|
|
|
|
}) => {
|
|
|
|
}) => {
|
|
|
|
const [data, setData] = useState([]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
|
|
|
// 为现有数据添加key属性(如果不存在)
|
|
|
|
|
|
|
|
const dataWithKeys = nodeData.parameters.dataIns?.map((item, index) => ({
|
|
|
|
|
|
|
|
...item,
|
|
|
|
|
|
|
|
key: item.key ?? index
|
|
|
|
|
|
|
|
})) || [];
|
|
|
|
|
|
|
|
setData(dataWithKeys);
|
|
|
|
|
|
|
|
}, [nodeData]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const dataTypeOptions = [
|
|
|
|
|
|
|
|
{ label: '字符串', value: 'string' },
|
|
|
|
|
|
|
|
{ label: '数字', value: 'number' },
|
|
|
|
|
|
|
|
{ label: '布尔值', value: 'boolean' },
|
|
|
|
|
|
|
|
{ label: '数组', value: 'array' },
|
|
|
|
|
|
|
|
{ label: '对象', value: 'object' }
|
|
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const arrayTypeOptions = [
|
|
|
|
|
|
|
|
{ label: '字符串数组', value: 'string' },
|
|
|
|
|
|
|
|
{ label: '数字数组', value: 'number' },
|
|
|
|
|
|
|
|
{ label: '布尔数组', value: 'boolean' }
|
|
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const columns = [
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
title: '标识',
|
|
|
|
|
|
|
|
dataIndex: 'id',
|
|
|
|
|
|
|
|
render: (_, record) => (
|
|
|
|
|
|
|
|
<Input
|
|
|
|
|
|
|
|
value={record.id}
|
|
|
|
|
|
|
|
onChange={(value) => handleSave({ ...record, id: value })}
|
|
|
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
title: '数据类型',
|
|
|
|
|
|
|
|
dataIndex: 'dataType',
|
|
|
|
|
|
|
|
render: (_, record) => (
|
|
|
|
|
|
|
|
<Select
|
|
|
|
|
|
|
|
autoWidth={{ minWidth: 200, maxWidth: 500 }}
|
|
|
|
|
|
|
|
options={dataTypeOptions}
|
|
|
|
|
|
|
|
value={record.dataType}
|
|
|
|
|
|
|
|
onChange={(value) => handleSave({ ...record, dataType: value })}
|
|
|
|
|
|
|
|
placeholder="请选择数据类型"
|
|
|
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
title: '数组类型',
|
|
|
|
|
|
|
|
dataIndex: 'arrayType',
|
|
|
|
|
|
|
|
render: (_, record) => (
|
|
|
|
|
|
|
|
record.dataType === 'array' ? (
|
|
|
|
|
|
|
|
<Select
|
|
|
|
|
|
|
|
autoWidth={{ minWidth: 200, maxWidth: 500 }}
|
|
|
|
|
|
|
|
options={arrayTypeOptions}
|
|
|
|
|
|
|
|
value={record.arrayType}
|
|
|
|
|
|
|
|
onChange={(value) => handleSave({ ...record, arrayType: value })}
|
|
|
|
|
|
|
|
placeholder="请选择数组类型"
|
|
|
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
) : (
|
|
|
|
|
|
|
|
<span></span>
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
title: '描述',
|
|
|
|
|
|
|
|
dataIndex: 'desc',
|
|
|
|
|
|
|
|
render: (_, record) => (
|
|
|
|
|
|
|
|
<Input
|
|
|
|
|
|
|
|
value={record.desc}
|
|
|
|
|
|
|
|
onChange={(value) => handleSave({ ...record, desc: value })}
|
|
|
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
title: '默认值',
|
|
|
|
|
|
|
|
dataIndex: 'defaultValue',
|
|
|
|
|
|
|
|
render: (_, record) => (
|
|
|
|
|
|
|
|
<Input
|
|
|
|
|
|
|
|
value={record.defaultValue}
|
|
|
|
|
|
|
|
onChange={(value) => handleSave({ ...record, defaultValue: value })}
|
|
|
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
title: '操作',
|
|
|
|
|
|
|
|
dataIndex: 'op',
|
|
|
|
|
|
|
|
render: (_, record) => (
|
|
|
|
|
|
|
|
<Button onClick={() => removeRow(record.key)} type="text" status="danger">
|
|
|
|
|
|
|
|
<IconDelete />
|
|
|
|
|
|
|
|
</Button>
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const handleSave = (row) => {
|
|
|
|
|
|
|
|
const newData = [...data];
|
|
|
|
|
|
|
|
const index = newData.findIndex((item) => row.key === item.key);
|
|
|
|
|
|
|
|
if (index >= 0) {
|
|
|
|
|
|
|
|
newData.splice(index, 1, { ...newData[index], ...row });
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
newData.push(row);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
setData(newData);
|
|
|
|
|
|
|
|
// 更新节点数据
|
|
|
|
|
|
|
|
updateNodeData('parameters', {
|
|
|
|
|
|
|
|
...nodeData.parameters,
|
|
|
|
|
|
|
|
dataIns: newData
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const removeRow = (key) => {
|
|
|
|
|
|
|
|
const newData = data.filter((item) => item.key !== key);
|
|
|
|
|
|
|
|
setData(newData);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 更新节点数据
|
|
|
|
|
|
|
|
updateNodeData('parameters', {
|
|
|
|
|
|
|
|
...nodeData.parameters,
|
|
|
|
|
|
|
|
dataIns: newData
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const addRow = () => {
|
|
|
|
|
|
|
|
const newKey = Date.now();
|
|
|
|
|
|
|
|
const newRow = {
|
|
|
|
|
|
|
|
key: newKey,
|
|
|
|
|
|
|
|
id: '',
|
|
|
|
|
|
|
|
dataType: '',
|
|
|
|
|
|
|
|
arrayType: '',
|
|
|
|
|
|
|
|
desc: '',
|
|
|
|
|
|
|
|
defaultValue: ''
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
const newData = [...data, newRow];
|
|
|
|
|
|
|
|
setData(newData);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 更新节点数据
|
|
|
|
|
|
|
|
updateNodeData('parameters', {
|
|
|
|
|
|
|
|
...nodeData.parameters,
|
|
|
|
|
|
|
|
dataIns: newData
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<>
|
|
|
|
<Typography.Title heading={5}><IconUnorderedList style={{ marginRight: 5 }} />输入参数</Typography.Title>
|
|
|
|
<Typography.Title heading={5}><IconUnorderedList style={{ marginRight: 5 }} />输入参数</Typography.Title>
|
|
|
|
<Table columns={columns} data={data} pagination={false} />
|
|
|
|
<ParamsTable
|
|
|
|
<Button
|
|
|
|
initialData={nodeData.parameters.dataIns || []}
|
|
|
|
style={{ height: 45 }}
|
|
|
|
onUpdateData={(data) => {
|
|
|
|
long
|
|
|
|
updateNodeData('parameters', {
|
|
|
|
type="outline"
|
|
|
|
...nodeData.parameters,
|
|
|
|
onClick={addRow}
|
|
|
|
dataIns: data
|
|
|
|
>
|
|
|
|
});
|
|
|
|
+ 添加
|
|
|
|
}}
|
|
|
|
</Button>
|
|
|
|
/>
|
|
|
|
</>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|