代码提交

This commit is contained in:
fengxiangdebaozi committed 2026-06-18 21:09:37 +08:00
1 parent 179a3f2b2f
commit ce78cbf936
4 files changed
+188 -26

No files matched your search

+11 -2
View File
@@ -166,14 +166,18 @@ export function derivePurposeLevels(tree: PurposeTreeNode[]): PurposeLevel[] {
* 把归一化后的目的树转换成 Step 3 流程图组件(FlowGraphPanel)认识的 FlowGraphData。
*
* - 逐层深度优先遍历,给每个节点分配稳定 id(`p1/p2/…`,按遍历顺序);
* - 父→子建一条边(from=父 id);多个根目的各自成一棵子树(画布支持多根);
* - 父→子建一条边(from=父 id);
* - 节点主文本(`text`)作 label,层级名(`label`)作 group(画布顶部小标签),
* 推荐理由并进 detail(点节点弹窗里看)。
* - 传入 ``rootLabel`` 时,在最顶层加一个「任务」根节点,所有「目的」挂到它下面
* (与 B 系统给的「任务 → 目的 → 行为体 → …」流程一致,单一根节点);不传则保持
* 旧的「多个目的各自成根」森林(向后兼容)。
* 容错沿用 PurposeTreeNode(normalizeNode 已兜底字段/层级变动),这里不再二次判断。
*/
export function purposeTreeToFlowGraph(
tree: PurposeTreeNode[],
taskId?: string,
rootLabel?: string,
): FlowGraphData {
const nodes: FlowGraphNode[] = [];
const edges: FlowGraphEdge[] = [];
@@ -189,7 +193,12 @@ export function purposeTreeToFlowGraph(
if (parentId) edges.push({ from: parentId, to: id });
node.children?.forEach((child) => walk(child, id));
};
tree.forEach((root) => walk(root, null));
// 任务为单一根节点(仅在有目的数据且传入 rootLabel 时):每个「目的」根挂到它下面。
const rootId = rootLabel && rootLabel.trim() && tree.length > 0 ? "task-root" : null;
if (rootId) {
nodes.push({ id: rootId, label: rootLabel!.trim(), type: "start", group: "任务" });
}
tree.forEach((root) => walk(root, rootId));
return {
title: taskId ? `任务目的(任务 ${taskId})` : "任务目的",
nodes,