1
This commit is contained in:
parent
ad399901d5
commit
603cd19420
@ -4,6 +4,7 @@ import { Row, Col, Menu, Tabs, Card, Button, message } from 'antd';
|
||||
import { BetaSchemaForm, ProForm, ProFormGroup, ProFormText, ProFormTextArea } from '@ant-design/pro-form';
|
||||
import type { NodeDesignData } from './types';
|
||||
import * as service from './service';
|
||||
import { useLocation } from 'react-router-dom';
|
||||
|
||||
// Tab 配置
|
||||
const TAB_CONFIG = [
|
||||
@ -14,6 +15,9 @@ const TAB_CONFIG = [
|
||||
];
|
||||
|
||||
const NodeDesignForm: React.FC = () => {
|
||||
const location = useLocation();
|
||||
const nodeData = location.state?.nodeData;
|
||||
|
||||
// 缓存节点定义数据
|
||||
const [nodeDefinitions, setNodeDefinitions] = useState<NodeDesignData[]>([]);
|
||||
const [loading, setLoading] = useState(false);
|
||||
@ -32,8 +36,10 @@ const NodeDesignForm: React.FC = () => {
|
||||
setLoading(true);
|
||||
const data = await service.getNodeDefinitionsDefined();
|
||||
setNodeDefinitions(data);
|
||||
// 默认选中第一个节点
|
||||
if (data.length > 0) {
|
||||
// 如果是修改模式,设置当前节点为选中状态
|
||||
if (nodeData) {
|
||||
setSelectedNode(nodeData);
|
||||
} else if (data.length > 0) {
|
||||
setSelectedNode(data[0]);
|
||||
}
|
||||
} catch (error) {
|
||||
@ -44,19 +50,22 @@ const NodeDesignForm: React.FC = () => {
|
||||
};
|
||||
|
||||
loadNodeDefinitions();
|
||||
}, []);
|
||||
}, [nodeData]);
|
||||
|
||||
// 获取当前节点可用的 Tab 列表
|
||||
const getAvailableTabs = (node: NodeDefinitionData | null) => {
|
||||
const getAvailableTabs = (node: NodeDesignData | null) => {
|
||||
if (!node) return [];
|
||||
return TAB_CONFIG.filter(tab => {
|
||||
const value = node[tab.schemaKey as keyof NodeDefinitionData];
|
||||
const value = node[tab.schemaKey as keyof NodeDesignData];
|
||||
return value !== null && value !== undefined;
|
||||
});
|
||||
};
|
||||
|
||||
// 处理节点选择
|
||||
const handleNodeSelect = (nodeCode: string) => {
|
||||
// 如果是修改模式,不允许选择其他节点
|
||||
if (nodeData) return;
|
||||
|
||||
const node = nodeDefinitions.find(n => n.nodeCode === nodeCode);
|
||||
if (node) {
|
||||
setSelectedNode(node);
|
||||
@ -323,6 +332,7 @@ const NodeDesignForm: React.FC = () => {
|
||||
|
||||
return (
|
||||
<PageContainer
|
||||
title={nodeData ? `修改节点设计 - ${nodeData.nodeName}` : '新建节点设计'}
|
||||
loading={loading}
|
||||
extra={[
|
||||
<Button
|
||||
@ -350,6 +360,7 @@ const NodeDesignForm: React.FC = () => {
|
||||
items={nodeDefinitions.map(node => ({
|
||||
key: node.nodeCode,
|
||||
label: `${node.nodeName}(${node.nodeCode})`,
|
||||
disabled: nodeData ? node.nodeCode !== nodeData.nodeCode : false // 只在修改模式下禁用不匹配的节点
|
||||
}))}
|
||||
onClick={({ key }) => handleNodeSelect(key)}
|
||||
style={{
|
||||
|
||||
Loading…
Reference in New Issue
Block a user