diff --git a/src/renderer/src/validation/flowValidation.ts b/src/renderer/src/validation/flowValidation.ts index d2b89af..443b909 100644 --- a/src/renderer/src/validation/flowValidation.ts +++ b/src/renderer/src/validation/flowValidation.ts @@ -122,6 +122,20 @@ export function validateFlow(flow: FlowDefinition, catalog: Catalog): FlowValida ...(flow.variables ?? []).map((item) => item.name), ...flow.nodes.map((node) => node.options?.outputVar).filter(Boolean) as string[] ]); + // 循环容器在运行时向子节点注入迭代变量,静态校验时视为已定义 + const LOOP_VARS: Record = { + logic_control_array_for_v3: ["item", "index", "value"], + logic_control_dictionary_for_v1: ["item", "index", "value"], + logic_control_count_for: ["index"] + }; + for (const node of flow.nodes) { + const vars = LOOP_VARS[node.componentId]; + if (vars) { + const custom = String(node.values?.count_index ?? "").trim(); + for (const name of vars) definedVars.add(name); + if (node.componentId === "logic_control_count_for" && /^[A-Za-z_]\w*$/.test(custom)) definedVars.add(custom); + } + } const variableRef = /\$\{\s*([A-Za-z_\u4e00-\u9fa5][\w\u4e00-\u9fa5]*)\s*(?:\.[A-Za-z_]\w*)?\s*\}/g; for (const node of flow.nodes) { const component = componentMap.get(node.componentId);