1
This commit is contained in:
parent
69d79bc185
commit
06f3eb428e
@ -229,6 +229,11 @@ const NodeDesignForm: React.FC = () => {
|
||||
const [selectedNode, setSelectedNode] = useState<NodeDesignDataResponse | null>(null);
|
||||
const [activeTab, setActiveTab] = useState<string>('panel');
|
||||
const [form] = Form.useForm();
|
||||
const [isEdit, setIsEdit] = useState(false);
|
||||
const [editData, setEditData] = useState<NodeDesignDataResponse | null>(null);
|
||||
|
||||
// 从路由参数获取 id
|
||||
const { id } = useParams();
|
||||
|
||||
// 加载节点定义数据
|
||||
useEffect(() => {
|
||||
@ -252,6 +257,38 @@ const NodeDesignForm: React.FC = () => {
|
||||
loadNodeDefinitions();
|
||||
}, []);
|
||||
|
||||
// 如果有 id,加载节点详情
|
||||
useEffect(() => {
|
||||
const loadNodeDetail = async () => {
|
||||
if (!id) return;
|
||||
|
||||
try {
|
||||
setLoading(true);
|
||||
const data = await service.getNodeDefinition(id);
|
||||
if (data) {
|
||||
setIsEdit(true);
|
||||
setEditData(data);
|
||||
// 设置基本信息表单值
|
||||
form.setFieldsValue({
|
||||
'base.nodeType': data.nodeType,
|
||||
'base.nodeCode': data.nodeCode,
|
||||
'base.nodeName': data.nodeName,
|
||||
'base.category': data.category,
|
||||
'base.description': data.description
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('加载节点详情失败:', error);
|
||||
message.error('加载节点详情失败');
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
loadNodeDetail();
|
||||
}, [id, form]);
|
||||
|
||||
|
||||
// 获取当前节点可用的 Tab 列表
|
||||
const getAvailableTabs = (node: NodeDesignDataResponse | null) => {
|
||||
if (!node) return [];
|
||||
@ -263,10 +300,14 @@ const NodeDesignForm: React.FC = () => {
|
||||
|
||||
// 处理节点选择
|
||||
const handleNodeSelect = (node: NodeDesignDataResponse) => {
|
||||
console.log('选择节点:', node);
|
||||
console.log('当前编辑状态:', isEdit);
|
||||
console.log('当前编辑数据:', editData);
|
||||
|
||||
setSelectedNode(node);
|
||||
// 更新表单数据
|
||||
form.setFieldsValue({
|
||||
'base.nodeType': node.nodeCode, // 使用 nodeCode 作为节点类型
|
||||
'base.nodeType': node.nodeType,
|
||||
'base.nodeCode': node.nodeCode,
|
||||
'base.nodeName': node.nodeName,
|
||||
'base.category': node.category,
|
||||
@ -342,7 +383,68 @@ const NodeDesignForm: React.FC = () => {
|
||||
if (!selectedNode) return null;
|
||||
const currentTab = TAB_CONFIG.find(tab => tab.key === activeTab);
|
||||
if (!currentTab) return null;
|
||||
return selectedNode[currentTab.schemaKey as keyof NodeDesignDataResponse];
|
||||
|
||||
const schema = selectedNode[currentTab.schemaKey as keyof NodeDesignDataResponse];
|
||||
console.log('当前 schema:', schema);
|
||||
console.log('是否编辑模式:', isEdit);
|
||||
console.log('编辑数据:', editData);
|
||||
|
||||
// 如果是编辑模式且有保存的数据,合并到 schema
|
||||
if (isEdit && editData?.uiVariables) {
|
||||
console.log('开始合并 UI 配置数据');
|
||||
const mergeUiVariables = (schemaObj: any, uiData: any, parentPath = ''): any => {
|
||||
if (!schemaObj || typeof schemaObj !== 'object') return schemaObj;
|
||||
console.log('正在处理 schema:', schemaObj);
|
||||
console.log('UI 数据:', uiData);
|
||||
console.log('当前路径:', parentPath);
|
||||
|
||||
const result = {...schemaObj};
|
||||
|
||||
if (result.properties) {
|
||||
Object.keys(result.properties).forEach(key => {
|
||||
const currentPath = parentPath ? `${parentPath}.${key}` : key;
|
||||
console.log('处理属性:', currentPath);
|
||||
|
||||
// 处理嵌套对象
|
||||
if (result.properties[key].type === 'object') {
|
||||
const nestedValue = currentPath.split('.').reduce((obj, key) => obj?.[key], uiData);
|
||||
console.log('嵌套对象的值:', nestedValue);
|
||||
if (nestedValue !== undefined) {
|
||||
result.properties[key].default = nestedValue;
|
||||
}
|
||||
}
|
||||
// 处理基本类型
|
||||
else {
|
||||
const value = currentPath.split('.').reduce((obj, key) => obj?.[key], uiData);
|
||||
console.log('属性值:', value);
|
||||
if (value !== undefined) {
|
||||
result.properties[key].default = value;
|
||||
}
|
||||
}
|
||||
|
||||
// 递归处理嵌套属性
|
||||
result.properties[key] = mergeUiVariables(
|
||||
result.properties[key],
|
||||
uiData,
|
||||
currentPath
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
if (result.items) {
|
||||
result.items = mergeUiVariables(result.items, uiData, parentPath);
|
||||
}
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
const mergedSchema = mergeUiVariables(schema, editData.uiVariables);
|
||||
console.log('合并后的 schema:', mergedSchema);
|
||||
return mergedSchema;
|
||||
}
|
||||
|
||||
console.log('使用原始 schema');
|
||||
return schema;
|
||||
};
|
||||
|
||||
return (
|
||||
|
||||
@ -74,6 +74,7 @@ export interface UIVariables extends BaseSchema {
|
||||
export interface NodeDesignDataResponse extends BaseResponse{
|
||||
nodeCode: string;
|
||||
nodeName: string;
|
||||
nodeType: string;
|
||||
category: string;
|
||||
panelVariablesSchema: NodeVariablesSchema | null;
|
||||
localVariablesSchema: NodeVariablesSchema | null;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user