fix(electron-shell): 流程节点按实际执行顺序展示,不再按添加顺序

- 后端 normalizeNodes 保存时按执行序重排(拓扑层 + 层内原序,与 execute 取法一致)

- 前端流程列表节点链改按执行序渲染,画布节点加执行序号徽标
This commit is contained in:
2026-10-27 13:53:05 +08:00
parent a8b25f2942
commit a3ed22b8df
2 changed files with 63 additions and 2 deletions
+22 -1
View File
@@ -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 小时)约束