feat: 实现基础组件只允许修改默认值的功能

master
钟良源 4 weeks ago
parent 92ba1ac67d
commit dd5d72740e

@ -75,7 +75,8 @@ const BasicNodeEditor: React.FC<NodeEditorProps> = ({
const getCompInfo = () => { const getCompInfo = () => {
const flatData = getCurrentProjectStoreData(); const flatData = getCurrentProjectStoreData();
setCurrentCompInfo(flatData.find((item: any) => item.id === nodeData.compId)); const compInfo = flatData.find((item: any) => item.id === nodeData.compId);
setCurrentCompInfo(compInfo);
}; };
const getCompInstance = async () => { const getCompInstance = async () => {
const res: any = await queryInstance(nodeData.compId); const res: any = await queryInstance(nodeData.compId);
@ -93,6 +94,10 @@ const BasicNodeEditor: React.FC<NodeEditorProps> = ({
getCompInfo(); getCompInfo();
getCompInstance(); getCompInstance();
}, []); }, []);
// 判断是否为基础组件(基础组件只允许修改默认值)
const isBaseComponent = nodeData.type === 'BASIC';
return ( return (
<Form layout="vertical"> <Form layout="vertical">
<Form.Item label="节点标题"> <Form.Item label="节点标题">
@ -124,7 +129,6 @@ const BasicNodeEditor: React.FC<NodeEditorProps> = ({
<Select <Select
value={nodeData?.component?.compIdentifier || ''} value={nodeData?.component?.compIdentifier || ''}
onChange={(value) => { onChange={(value) => {
console.log(value);
updateNodeData('component', { updateNodeData('component', {
...nodeData.component, ...nodeData.component,
compIdentifier: value, compIdentifier: value,
@ -143,6 +147,7 @@ const BasicNodeEditor: React.FC<NodeEditorProps> = ({
dataIns: data dataIns: data
}); });
}} }}
readonly={isBaseComponent}
/> />
<Typography.Title heading={5}><IconUnorderedList style={{ marginRight: 5 }} /></Typography.Title> <Typography.Title heading={5}><IconUnorderedList style={{ marginRight: 5 }} /></Typography.Title>
<ParamsTable <ParamsTable
@ -153,6 +158,7 @@ const BasicNodeEditor: React.FC<NodeEditorProps> = ({
dataOuts: data dataOuts: data
}); });
}} }}
readonly={isBaseComponent}
/> />
</Form> </Form>
); );

@ -48,11 +48,13 @@ interface TableDataItem {
interface ParamsTableProps { interface ParamsTableProps {
initialData: TableDataItem[]; initialData: TableDataItem[];
onUpdateData: (data: TableDataItem[]) => void; onUpdateData: (data: TableDataItem[]) => void;
readonly?: boolean; // 只读模式,用于基础组件(仅允许修改默认值)
} }
const ParamsTable: React.FC<ParamsTableProps> = ({ const ParamsTable: React.FC<ParamsTableProps> = ({
initialData, initialData,
onUpdateData onUpdateData,
readonly = false
}) => { }) => {
const [data, setData] = useState<TableDataItem[]>([]); const [data, setData] = useState<TableDataItem[]>([]);
const { gloBalVarList } = useSelector((state: any) => state.ideContainer); const { gloBalVarList } = useSelector((state: any) => state.ideContainer);
@ -102,7 +104,7 @@ const ParamsTable: React.FC<ParamsTableProps> = ({
title: '标识', title: '标识',
dataIndex: 'id', dataIndex: 'id',
render: (_: any, record: TableDataItem) => ( render: (_: any, record: TableDataItem) => (
record.id === 'maxTime' ? ( record.id === 'maxTime' || readonly ? (
<EllipsisWithPopover text={record.id} maxWidth={100} /> <EllipsisWithPopover text={record.id} maxWidth={100} />
) : ( ) : (
<Popover <Popover
@ -123,10 +125,11 @@ const ParamsTable: React.FC<ParamsTableProps> = ({
{ {
title: '数据类型', title: '数据类型',
dataIndex: 'dataType', dataIndex: 'dataType',
render: (_: any, record: TableDataItem) => ( render: (_: any, record: TableDataItem) => {
record.id === 'maxTime' ? ( if (record.id === 'maxTime' || readonly) {
<span>{record.dataType === 'INTEGER' ? '整数' : record.dataType}</span> return <span>{record.dataType === 'INTEGER' ? '整数' : record.dataType}</span>;
) : ( }
return (
<Select <Select
autoWidth={{ minWidth: 150, maxWidth: 200 }} autoWidth={{ minWidth: 150, maxWidth: 200 }}
options={dataTypeOptions} options={dataTypeOptions}
@ -134,14 +137,15 @@ const ParamsTable: React.FC<ParamsTableProps> = ({
onChange={(value) => handleSave({ ...record, dataType: value })} onChange={(value) => handleSave({ ...record, dataType: value })}
placeholder="请选择数据类型" placeholder="请选择数据类型"
/> />
) );
) }
}, },
{ {
title: '数组类型', title: '数组类型',
dataIndex: 'arrayType', dataIndex: 'arrayType',
render: (_: any, record: TableDataItem) => ( render: (_: any, record: TableDataItem) => {
record.dataType === 'ARRAY' ? ( if (record.dataType === 'ARRAY' && !readonly) {
return (
<Select <Select
autoWidth={{ minWidth: 150, maxWidth: 200 }} autoWidth={{ minWidth: 150, maxWidth: 200 }}
options={arrayTypeOptions} options={arrayTypeOptions}
@ -149,16 +153,19 @@ const ParamsTable: React.FC<ParamsTableProps> = ({
onChange={(value) => handleSave({ ...record, arrayType: value })} onChange={(value) => handleSave({ ...record, arrayType: value })}
placeholder="请选择数组类型" placeholder="请选择数组类型"
/> />
) : ( );
<div style={{ minWidth: 70, maxWidth: 100 }}>-</div> }
) if (record.dataType === 'ARRAY' && readonly) {
) return <span>{record.arrayType}</span>;
}
return <div style={{ minWidth: 70, maxWidth: 100 }}>-</div>;
}
}, },
{ {
title: '描述', title: '描述',
dataIndex: 'desc', dataIndex: 'desc',
render: (_: any, record: TableDataItem) => ( render: (_: any, record: TableDataItem) => (
record.id === 'maxTime' ? ( record.id === 'maxTime' || readonly ? (
<EllipsisWithPopover text={record.desc} maxWidth={120} /> <EllipsisWithPopover text={record.desc} maxWidth={120} />
) : ( ) : (
<Popover <Popover
@ -252,7 +259,7 @@ const ParamsTable: React.FC<ParamsTableProps> = ({
title: '操作', title: '操作',
dataIndex: 'op', dataIndex: 'op',
render: (_: any, record: TableDataItem) => ( render: (_: any, record: TableDataItem) => (
record.id !== 'maxTime' && !readonly && record.id !== 'maxTime' &&
<Button onClick={() => removeRow(record.key)} type="text" status="danger" style={{ maxWidth: 40 }}> <Button onClick={() => removeRow(record.key)} type="text" status="danger" style={{ maxWidth: 40 }}>
<IconDelete /> <IconDelete />
</Button> </Button>
@ -297,6 +304,7 @@ const ParamsTable: React.FC<ParamsTableProps> = ({
return ( return (
<> <>
<Table columns={columns} data={data} pagination={false} /> <Table columns={columns} data={data} pagination={false} />
{!readonly && (
<Button <Button
style={{ height: 45 }} style={{ height: 45 }}
long long
@ -305,6 +313,7 @@ const ParamsTable: React.FC<ParamsTableProps> = ({
> >
+ +
</Button> </Button>
)}
</> </>
); );
}; };

Loading…
Cancel
Save