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 小时)约束
@@ -33,7 +33,7 @@
</span>
</div>
<div class="fr-chain">
<template v-for="(n, i) in f.nodes" :key="n.id">
<template v-for="(n, i) in execOrder(f.nodes)" :key="n.id">
<span class="fr-node" :class="nodeState(f, n).cls">
<i class="nd"></i>{{ n.name }}<em v-if="nodeState(f, n).text">{{ nodeState(f, n).text }}</em>
</span>
@@ -102,6 +102,7 @@
:class="[nodeVisual(n), { active: selectedKey === n.key }, 'type-' + n.type]"
:style="{ left: n.x + 'px', top: n.y + 'px' }"
@pointerdown="startDrag($event, n)" @click.stop="selectNode(n)">
<span class="fn-step" :title="`第 ${nodeStep(n)} 个执行`">{{ nodeStep(n) }}</span>
<div class="fn-name">
<span class="fn-type" :class="n.type">{{ typeLabel(n.type) }}</span>
<span class="fn-text">{{ nodeTitle(n) }}</span>
@@ -756,6 +757,40 @@ function removeEdge(e) {
ElMessage.info('已删除这条连线')
}
// 执行顺序:逐层取「依赖均已排入」的节点,层内保持数组原顺序——与后端 flows.js 的 execute() 取法一致。
// 列表节点链与画布序号都按它展示,否则看起来会像「按添加顺序执行」。
function execOrder(nodes) {
const list = nodes || []
if (list.length < 2) return [...list]
const keyOf = (n) => n.id || n.key
const ids = new Set(list.map(keyOf))
const done = new Set()
const out = []
let guard = 0
while (out.length < list.length && guard++ <= list.length + 1) {
const layer = list.filter(
(n) => !done.has(keyOf(n)) && (n.deps || []).every((d) => done.has(d) || !ids.has(d))
)
if (!layer.length) break
for (const n of layer) {
done.add(keyOf(n))
out.push(n)
}
}
// 兜底:环或脏依赖时不丢节点,保持原序追加
for (const n of list) if (!done.has(keyOf(n))) out.push(n)
return out
}
const stepMap = computed(() => {
const m = new Map()
execOrder(form.nodes).forEach((n, i) => m.set(n.key, i + 1))
return m
})
function nodeStep(n) {
return stepMap.value.get(n.key) || 0
}
function autoLayout() {
const nodes = form.nodes
const byId = new Map(nodes.map((n) => [n.id || n.key, n]))
@@ -1093,6 +1128,11 @@ function nodeVisual(n) {
.fnode.ok { border-color: var(--good-line); }
.fnode.bad { border-color: var(--danger-line); background: var(--danger-soft); }
.fnode.skip { opacity: .6; }
.fn-step {
position: absolute; left: -8px; top: -8px; width: 18px; height: 18px; border-radius: 50%;
background: var(--brand); color: #fff; font: 600 10px/18px var(--f-cn); text-align: center;
box-shadow: var(--sh-card); pointer-events: none;
}
.fn-name { display: flex; align-items: center; gap: var(--space-1-5); min-width: 0; }
.fn-text { font: 600 12.5px/18px var(--f-cn); color: var(--t1); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fn-type {