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