From c68d629b7ae796e3dde6c46340a85cceb3e77fe1 Mon Sep 17 00:00:00 2001 From: wanglin2 <1013335014@qq.com> Date: Fri, 13 Oct 2023 10:55:02 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96=EF=BC=9A?= =?UTF-8?q?=E5=B0=86=E8=B0=83=E7=94=A8clearAllActive=E6=96=B9=E6=B3=95?= =?UTF-8?q?=E7=9A=84=E5=9C=B0=E6=96=B9=E6=94=B9=E4=B8=BA=E8=B0=83=E7=94=A8?= =?UTF-8?q?CLEAR=5FACTIVE=5FNODE=E5=91=BD=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- simple-mind-map/index.js | 4 ++-- simple-mind-map/src/core/render/Render.js | 26 +++++++++++------------ simple-mind-map/src/plugins/Drag.js | 2 +- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/simple-mind-map/index.js b/simple-mind-map/index.js index 657414e7..0a25d8da 100644 --- a/simple-mind-map/index.js +++ b/simple-mind-map/index.js @@ -234,7 +234,7 @@ class MindMap { // 设置主题 setTheme(theme, notRender = false) { - this.renderer.clearAllActive() + this.execCommand('CLEAR_ACTIVE_NODE') this.opt.theme = theme if (!notRender) { this.render(null, CONSTANTS.CHANGE_THEME) @@ -381,7 +381,7 @@ class MindMap { this.opt.readonly = mode === CONSTANTS.MODE.READONLY if (this.opt.readonly) { // 取消当前激活的元素 - this.renderer.clearAllActive() + this.execCommand('CLEAR_ACTIVE_NODE') } this.emit('mode_change', mode) } diff --git a/simple-mind-map/src/core/render/Render.js b/simple-mind-map/src/core/render/Render.js index 7d5507c8..4cea86e7 100644 --- a/simple-mind-map/src/core/render/Render.js +++ b/simple-mind-map/src/core/render/Render.js @@ -202,8 +202,8 @@ class Render { this.setNodeActive = this.setNodeActive.bind(this) this.mindMap.command.add('SET_NODE_ACTIVE', this.setNodeActive) // 清除所有激活节点 - this.clearAllActive = this.clearAllActive.bind(this) - this.mindMap.command.add('CLEAR_ACTIVE_NODE', this.clearAllActive) + this.clearActiveNode = this.clearActiveNode.bind(this) + this.mindMap.command.add('CLEAR_ACTIVE_NODE', this.clearActiveNode) // 切换节点是否展开 this.setNodeExpand = this.setNodeExpand.bind(this) this.mindMap.command.add('SET_NODE_EXPAND', this.setNodeExpand) @@ -400,6 +400,15 @@ class Render { this.mindMap.emit('node_active', null, [...this.activeNodeList]) } + // 清除当前所有激活节点,并会触发事件 + clearActiveNode() { + if (this.activeNodeList.length <= 0) { + return + } + this.clearActive() + this.mindMap.emit('node_active', null, []) + } + // 清除当前激活的节点 clearActive() { this.activeNodeList.forEach(item => { @@ -408,15 +417,6 @@ class Render { this.activeNodeList = [] } - // 清除当前所有激活节点,并会触发事件 - clearAllActive() { - if (this.activeNodeList.length <= 0) { - return - } - this.clearActive() - this.mindMap.emit('node_active', null, []) - } - // 添加节点到激活列表里 addActiveNode(node) { let index = this.findActiveNodeIndex(node) @@ -467,7 +467,7 @@ class Render { // 回退 back(step) { - this.clearAllActive() + this.mindMap.execCommand('CLEAR_ACTIVE_NODE') let data = this.mindMap.command.back(step) if (data) { this.renderTree = data @@ -477,7 +477,7 @@ class Render { // 前进 forward(step) { - this.clearAllActive() + this.mindMap.execCommand('CLEAR_ACTIVE_NODE') let data = this.mindMap.command.forward(step) if (data) { this.renderTree = data diff --git a/simple-mind-map/src/plugins/Drag.js b/simple-mind-map/src/plugins/Drag.js index a8162ab4..2b9ce554 100644 --- a/simple-mind-map/src/plugins/Drag.js +++ b/simple-mind-map/src/plugins/Drag.js @@ -222,7 +222,7 @@ class Drag extends Base { // 创建克隆节点 this.createCloneNode() // 清除当前所有激活的节点 - this.mindMap.renderer.clearAllActive() + this.mindMap.execCommand('CLEAR_ACTIVE_NODE') } }