diff --git a/desktop/electron-shell/electron/flows.js b/desktop/electron-shell/electron/flows.js index cea6c4a..30eb7a5 100644 --- a/desktop/electron-shell/electron/flows.js +++ b/desktop/electron-shell/electron/flows.js @@ -206,6 +206,27 @@ function topoLayers(nodes) { return layers; } +// 执行顺序:逐层取「依赖已全部成功」的节点,层内保持数组原顺序——与 execute() 的取法完全一致。 +// 保存时按它重排 nodes,数组顺序即执行顺序,前端列表/运行详情不必再猜。 +function execOrder(nodes) { + const done = new Set(); + const out = []; + let guard = 0; + while (out.length < nodes.length && guard++ <= nodes.length + 1) { + const layer = nodes.filter( + (n) => !done.has(n.id) && (n.deps || []).every((d) => done.has(d)) + ); + if (!layer.length) break; + for (const n of layer) { + done.add(n.id); + out.push(n); + } + } + // 理论到不了(保存前 topoLayers 已拦环/缺依赖),兜底不丢节点 + for (const n of nodes) if (!done.has(n.id)) out.push(n); + return out; +} + function normalizeNodes(raw) { if (!Array.isArray(raw) || !raw.length) throw new Error("流程至少需要 1 个节点"); if (raw.length > MAX_NODES) throw new Error(`单个流程最多 ${MAX_NODES} 个节点`); @@ -277,7 +298,7 @@ function normalizeNodes(raw) { } } topoLayers(nodes); // 有环直接抛 - return nodes; + return execOrder(nodes); } // 定时调度配置:与「定时任务」共用同一套 cron 解析与最小间隔(1 小时)约束 diff --git a/desktop/electron-shell/frontend/src/components/FlowPage.vue b/desktop/electron-shell/frontend/src/components/FlowPage.vue index 67bca9a..9a020bb 100644 --- a/desktop/electron-shell/frontend/src/components/FlowPage.vue +++ b/desktop/electron-shell/frontend/src/components/FlowPage.vue @@ -33,7 +33,7 @@
-