feat: 回忆导图根节点自动聚焦指定路径
- loadData 中根据 focusPath 自动查找标准导图节点设为根 - 新增 findNodeByPath 辅助函数支持路径定位 - 有 focusPath 时节点始终可点选
This commit is contained in:
@@ -121,9 +121,30 @@ const loadData = async () => {
|
|||||||
if (!recallTree.value) {
|
if (!recallTree.value) {
|
||||||
recallTree.value = buildEmptyRecallTree();
|
recallTree.value = buildEmptyRecallTree();
|
||||||
}
|
}
|
||||||
|
// 若从 URL 带了 focusPath,自动设置回忆导图根节点
|
||||||
|
if (focusPath.value && standard.value?.content) {
|
||||||
|
try {
|
||||||
|
const tree = JSON.parse(standard.value.content) as MindMapTreeNode;
|
||||||
|
const match = findNodeByPath(tree, focusPath.value);
|
||||||
|
if (match) {
|
||||||
|
recallTree.value = { title: match.title, children: [] };
|
||||||
|
}
|
||||||
|
} catch { /* ignore */ }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const findNodeByPath = (node: MindMapTreeNode, path: string): MindMapTreeNode | null => {
|
||||||
|
const parts = path.split(" / ");
|
||||||
|
let current: MindMapTreeNode | null = node;
|
||||||
|
for (let i = 0; i < parts.length && current; i++) {
|
||||||
|
if (current.title === parts[i] && i === parts.length - 1) return current;
|
||||||
|
const child = (current.children || []).find((c) => c.title === parts[i]);
|
||||||
|
current = child || null;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
|
||||||
// 重新生成(防抖 + 用户编辑时弹窗选模式)
|
// 重新生成(防抖 + 用户编辑时弹窗选模式)
|
||||||
const handleRegenerate = async () => {
|
const handleRegenerate = async () => {
|
||||||
// 防抖:正在生成中跳过
|
// 防抖:正在生成中跳过
|
||||||
@@ -521,7 +542,7 @@ onMounted(() => {
|
|||||||
v-if="standardTree"
|
v-if="standardTree"
|
||||||
:tree="compareTree || standardTree"
|
:tree="compareTree || standardTree"
|
||||||
:color-by-compare="!!compareTree"
|
:color-by-compare="!!compareTree"
|
||||||
:selectable="!editingStandard && !focusPath && !hasCompared"
|
:selectable="!editingStandard && !hasCompared"
|
||||||
height="60vh"
|
height="60vh"
|
||||||
@node-select="handleNodeSelect"
|
@node-select="handleNodeSelect"
|
||||||
@node-click="goToNodeSource"
|
@node-click="goToNodeSource"
|
||||||
|
|||||||
Reference in New Issue
Block a user