From 1ffd33bc206ff850a53670b6a0acbf2f8be4f4a3 Mon Sep 17 00:00:00 2001 From: dengqichen Date: Fri, 20 Dec 2024 17:24:34 +0800 Subject: [PATCH] 1 --- .../Workflow/Definition/Design/index.tsx | 48 ++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/frontend/src/pages/Workflow/Definition/Design/index.tsx b/frontend/src/pages/Workflow/Definition/Design/index.tsx index fa1b9a6e..1c358e47 100644 --- a/frontend/src/pages/Workflow/Definition/Design/index.tsx +++ b/frontend/src/pages/Workflow/Definition/Design/index.tsx @@ -1062,6 +1062,44 @@ const WorkflowDesign: React.FC = () => { message.success('节点配置已更新'); }; + // 首先添加合并 schema 的工具函数 + const mergeFormVariablesSchemas = (schemas: any[]) => { + // 初始化合并后的 schema + const mergedSchema = { + type: 'object', + properties: {}, + required: [] + }; + + schemas.forEach(schema => { + if (!schema) return; + + // 合并 properties + if (schema.properties) { + Object.entries(schema.properties).forEach(([key, property]) => { + // 如果属性已存在,检查是否完全相同 + if (mergedSchema.properties[key]) { + if (JSON.stringify(mergedSchema.properties[key]) !== JSON.stringify(property)) { + console.warn(`属性 ${key} 在不同节点中定义不一致,使用第一个定义`); + } + } else { + mergedSchema.properties[key] = property; + } + }); + } + + // 合并 required 字段 + if (schema.required) { + schema.required.forEach((field: string) => { + if (!mergedSchema.required.includes(field)) { + mergedSchema.required.push(field); + } + }); + } + }); + + return mergedSchema; + }; // 处理保存工作流 const handleSaveWorkflow = async () => { if (!graph || !definitionData) return; @@ -1111,13 +1149,21 @@ const WorkflowDesign: React.FC = () => { } })); + // 收集并合并所有节点的 formVariablesSchema + const allFormSchemas = nodes + .map(node => node.formVariablesSchema) + .filter(schema => schema); // 过滤掉空值 + + const mergedFormSchema = mergeFormVariablesSchemas(allFormSchemas); + // 构建保存数据 const saveData = { ...definitionData, graph: { nodes, edges - } + }, + formVariablesSchema: mergedFormSchema }; // 调用保存接口