From 20157fcc8d78235118df710f4c4315317409025a Mon Sep 17 00:00:00 2001 From: wanglin2 <1013335014@qq.com> Date: Mon, 16 Oct 2023 10:29:45 +0800 Subject: [PATCH] =?UTF-8?q?Feat=EF=BC=9A=E8=A2=AB=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E7=9A=84=E8=8A=82=E7=82=B9=E5=90=8C=E6=AD=A5=E4=BB=8E=E6=BF=80?= =?UTF-8?q?=E6=B4=BB=E8=8A=82=E7=82=B9=E5=88=97=E8=A1=A8=E9=87=8C=E5=88=A0?= =?UTF-8?q?=E9=99=A4=EF=BC=9B=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81=EF=BC=9A?= =?UTF-8?q?1.=E7=A7=BB=E9=99=A4=E7=88=B6=E8=8A=82=E7=82=B9=E7=9A=84?= =?UTF-8?q?=E8=BF=9E=E7=BA=BF=E9=80=BB=E8=BE=91=E5=90=88=E5=B9=B6=E5=88=B0?= =?UTF-8?q?node.destroy=E6=96=B9=E6=B3=95=E5=86=85=EF=BC=9B2.=E6=8F=90?= =?UTF-8?q?=E5=8F=96render=E7=B1=BB=E4=B8=AD=E6=B4=BE=E5=8F=91=E8=8A=82?= =?UTF-8?q?=E7=82=B9=E6=BF=80=E6=B4=BB=E4=BA=8B=E4=BB=B6=E7=9A=84=E9=87=8D?= =?UTF-8?q?=E5=A4=8D=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- simple-mind-map/src/core/render/Render.js | 22 +++++++++++++------- simple-mind-map/src/core/render/node/Node.js | 8 +++---- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/simple-mind-map/src/core/render/Render.js b/simple-mind-map/src/core/render/Render.js index 35d80299..64a24d7e 100644 --- a/simple-mind-map/src/core/render/Render.js +++ b/simple-mind-map/src/core/render/Render.js @@ -387,10 +387,11 @@ class Render { // 删除本次渲染时不再需要的节点 Object.keys(this.lastNodeCache).forEach(uid => { if (!this.nodeCache[uid]) { + // 从激活节点列表里删除 + this.removeNodeFromActiveList(this.lastNodeCache[uid]) + this.emitNodeActiveEvent() + // 调用节点的销毁方法 this.lastNodeCache[uid].destroy() - if (this.lastNodeCache[uid].parent) { - this.lastNodeCache[uid].parent.removeLine() - } } }) // 更新根节点 @@ -416,7 +417,7 @@ class Render { } }) }) - this.mindMap.emit('node_active', null, [...this.activeNodeList]) + this.emitNodeActiveEvent() } // 清除当前所有激活节点,并会触发事件 @@ -475,7 +476,7 @@ class Render { 0, 0 ) - this.mindMap.emit('node_active', null, [...this.activeNodeList]) + this.emitNodeActiveEvent() } // 回退 @@ -1019,7 +1020,7 @@ class Render { if (needActiveNode) { this.addNodeToActiveList(needActiveNode) } - this.mindMap.emit('node_active', null, [...this.activeNodeList]) + this.emitNodeActiveEvent() this.mindMap.render() } @@ -1062,7 +1063,7 @@ class Render { if (needActiveNode) { this.addNodeToActiveList(needActiveNode) } - this.mindMap.emit('node_active', null, [...this.activeNodeList]) + this.emitNodeActiveEvent() this.mindMap.render() } @@ -1143,7 +1144,7 @@ class Render { removeFromParentNodeData(item) toNode.nodeData.children.push(item.nodeData) }) - this.mindMap.emit('node_active', null, [...this.activeNodeList]) + this.emitNodeActiveEvent() this.mindMap.render() } @@ -1535,6 +1536,11 @@ class Render { }) return res } + + // 派发节点激活改变事件 + emitNodeActiveEvent() { + this.mindMap.emit('node_active', null, [...this.activeNodeList]) + } } export default Render diff --git a/simple-mind-map/src/core/render/node/Node.js b/simple-mind-map/src/core/render/node/Node.js index 09bed01d..f4eb0868 100644 --- a/simple-mind-map/src/core/render/node/Node.js +++ b/simple-mind-map/src/core/render/node/Node.js @@ -492,10 +492,7 @@ class Node { } // 如果有且只有当前节点激活了,那么不需要重新激活 if ( - !( - this.getData('isActive') && - this.renderer.activeNodeList.length === 1 - ) + !(this.getData('isActive') && this.renderer.activeNodeList.length === 1) ) { this.renderer.clearActiveNodeList() this.active(e) @@ -693,6 +690,9 @@ class Node { this.removeGeneralization() this.removeLine() this.group = null + if (this.parent) { + this.parent.removeLine() + } } // 隐藏节点