From 5014a2feb74e0d9ae6b0f81ac63e1b59ca528629 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=A1=97=E8=A7=92=E5=B0=8F=E6=9E=97?= <1013335014@qq.com> Date: Thu, 5 Sep 2024 19:14:18 +0800 Subject: [PATCH] =?UTF-8?q?Feat=EF=BC=9A=E5=B1=95=E5=BC=80=E6=89=80?= =?UTF-8?q?=E6=9C=89=E5=92=8C=E6=94=B6=E8=B5=B7=E6=89=80=E6=9C=89=E7=9A=84?= =?UTF-8?q?=E5=91=BD=E4=BB=A4=E6=94=AF=E6=8C=81=E6=8C=87=E5=AE=9A=E8=8A=82?= =?UTF-8?q?=E7=82=B9=E7=9A=84uid?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- simple-mind-map/src/core/render/Render.js | 69 ++++++++++++++--------- 1 file changed, 41 insertions(+), 28 deletions(-) diff --git a/simple-mind-map/src/core/render/Render.js b/simple-mind-map/src/core/render/Render.js index 605313a5..55e7f861 100644 --- a/simple-mind-map/src/core/render/Render.js +++ b/simple-mind-map/src/core/render/Render.js @@ -1606,40 +1606,53 @@ class Render { } // 展开所有 - expandAllNode() { + expandAllNode(uid = '') { if (!this.renderTree) return - walk( - this.renderTree, - null, - node => { - if (!node.data.expand) { - node.data.expand = true - } - }, - null, - true, - 0, - 0 - ) + + const _walk = (node, enableExpand) => { + // 如果该节点为目标节点,那么修改允许展开的标志 + if (!enableExpand && node.data.uid === uid) { + enableExpand = true + } + if (enableExpand && !node.data.expand) { + node.data.expand = true + } + if (node.children && node.children.length > 0) { + node.children.forEach(child => { + _walk(child, enableExpand) + }) + } + } + _walk(this.renderTree, !uid) + this.mindMap.render() } // 收起所有 - unexpandAllNode(isSetRootNodeCenter = true) { + unexpandAllNode(isSetRootNodeCenter = true, uid = '') { if (!this.renderTree) return - walk( - this.renderTree, - null, - (node, parent, isRoot) => { - if (!isRoot && node.children && node.children.length > 0) { - node.data.expand = false - } - }, - null, - true, - 0, - 0 - ) + + const _walk = (node, isRoot, enableUnExpand) => { + // 如果该节点为目标节点,那么修改允许展开的标志 + if (!enableUnExpand && node.data.uid === uid) { + enableUnExpand = true + } + if ( + enableUnExpand && + !isRoot && + node.children && + node.children.length > 0 + ) { + node.data.expand = false + } + if (node.children && node.children.length > 0) { + node.children.forEach(child => { + _walk(child, false, enableUnExpand) + }) + } + } + _walk(this.renderTree, true, !uid) + this.mindMap.render(() => { if (isSetRootNodeCenter) { this.setRootNodeCenter()