This commit is contained in:
asp_ly 2024-12-19 20:15:12 +08:00
parent 603cd19420
commit e6bd17d9d0

View File

@ -55,6 +55,20 @@ const NodeDesignForm: React.FC = () => {
// 获取当前节点可用的 Tab 列表 // 获取当前节点可用的 Tab 列表
const getAvailableTabs = (node: NodeDesignData | null) => { const getAvailableTabs = (node: NodeDesignData | null) => {
if (!node) return []; if (!node) return [];
// 如果是修改模式从nodeDefinitions中找到对应的节点定义
if (nodeData) {
const nodeDefinition = nodeDefinitions.find(def => def.nodeCode === nodeData.nodeType);
if (nodeDefinition) {
return TAB_CONFIG.filter(tab => {
// 使用节点定义中的schema
const value = nodeDefinition[tab.schemaKey as keyof NodeDesignData];
return value !== null && value !== undefined;
});
}
}
// 新建模式
return TAB_CONFIG.filter(tab => { return TAB_CONFIG.filter(tab => {
const value = node[tab.schemaKey as keyof NodeDesignData]; const value = node[tab.schemaKey as keyof NodeDesignData];
return value !== null && value !== undefined; return value !== null && value !== undefined;
@ -212,15 +226,48 @@ const NodeDesignForm: React.FC = () => {
// 渲染 Tab 内容 // 渲染 Tab 内容
const renderTabContent = (schemaKey: string) => { const renderTabContent = (schemaKey: string) => {
if (!selectedNode) return null; if (!selectedNode) return null;
const schema = selectedNode[schemaKey as keyof NodeDesignData];
// 获取schema和初始值
let schema;
let initialValues = {};
if (nodeData) {
// 编辑模式
const nodeDefinition = nodeDefinitions.find(def => def.nodeCode === nodeData.nodeType);
if (!nodeDefinition) return null;
if (schemaKey === 'uiVariables') {
// UI配置使用nodeDefinitions中的schema定义使用nodeData中的实际数据作为初始值
schema = nodeDefinition.uiVariables;
initialValues = nodeData.uiVariables || {};
} else {
// 其他配置使用schema中的定义
schema = nodeDefinition[schemaKey as keyof NodeDesignData];
// 只在非UI配置时使用默认值
initialValues = getDefaultValues(schema);
}
} else {
// 新建模式
schema = selectedNode[schemaKey as keyof NodeDesignData];
initialValues = getDefaultValues(schema);
}
if (!schema) return null; if (!schema) return null;
console.log(`Rendering ${schemaKey}:`, {
schema,
initialValues
});
const formColumns = convertToProFormSchema(schema);
return ( return (
<BetaSchemaForm <BetaSchemaForm
key={`${selectedNode.nodeCode}-${schemaKey}`}
formRef={schemaKey === 'uiVariables' ? uiFormRef : undefined} formRef={schemaKey === 'uiVariables' ? uiFormRef : undefined}
layoutType="Form" layoutType="Form"
initialValues={getDefaultValues(schema)} initialValues={initialValues}
columns={convertToProFormSchema(schema)} columns={formColumns}
submitter={false} submitter={false}
/> />
); );