From 6b4c118a2b89b8c28dda982cf368c7e968744dcc Mon Sep 17 00:00:00 2001 From: wanglin2 <1013335014@qq.com> Date: Fri, 1 Sep 2023 09:34:22 +0800 Subject: [PATCH] =?UTF-8?q?Fix=EF=BC=9A=E4=BC=98=E5=8C=96Select=E6=8F=92?= =?UTF-8?q?=E4=BB=B6=EF=BC=8C=E5=A6=82=E6=9E=9C=E5=A4=9A=E9=80=89=E8=8A=82?= =?UTF-8?q?=E7=82=B9=E6=B2=A1=E6=9C=89=E5=8F=98=E5=8C=96=EF=BC=8C=E9=82=A3?= =?UTF-8?q?=E4=B9=88=E4=B8=8D=E8=A7=A6=E5=8F=91=E6=BF=80=E6=B4=BB=E6=BF=80?= =?UTF-8?q?=E6=B4=BB=E4=BA=8B=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- simple-mind-map/src/plugins/Select.js | 33 +++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/simple-mind-map/src/plugins/Select.js b/simple-mind-map/src/plugins/Select.js index e3fba7bc..329b4dc1 100644 --- a/simple-mind-map/src/plugins/Select.js +++ b/simple-mind-map/src/plugins/Select.js @@ -12,6 +12,7 @@ class Select { this.mouseMoveX = 0 this.mouseMoveY = 0 this.isSelecting = false + this.cacheActiveList = [] this.bindEvent() } @@ -31,6 +32,7 @@ class Select { } e.preventDefault() this.isMousedown = true + this.cacheActiveList = [...this.mindMap.renderer.activeNodeList] let { x, y } = this.mindMap.toPos(e.clientX, e.clientY) this.mouseDownX = x this.mouseDownY = y @@ -62,13 +64,10 @@ class Select { if (!this.isMousedown) { return } - this.mindMap.emit( - 'node_active', - null, - this.mindMap.renderer.activeNodeList - ) + this.checkTriggerNodeActiveEvent() clearTimeout(this.autoMoveTimer) this.isMousedown = false + this.cacheActiveList = [] if (this.rect) this.rect.remove() this.rect = null setTimeout(() => { @@ -77,6 +76,30 @@ class Select { }) } + // 如果激活节点改变了,那么触发事件 + checkTriggerNodeActiveEvent() { + let isNumChange = this.cacheActiveList.length !== this.mindMap.renderer.activeNodeList.length + let isNodeChange = false + if (!isNumChange) { + for(let i = 0; i < this.cacheActiveList.length; i++) { + let cur = this.cacheActiveList[i] + if (!this.mindMap.renderer.activeNodeList.find((item) => { + return item.nodeData.data.uid === cur.nodeData.data.uid + })){ + isNodeChange = true + break + } + } + } + if (isNumChange || isNodeChange) { + this.mindMap.emit( + 'node_active', + null, + this.mindMap.renderer.activeNodeList + ) + } + } + // 鼠标移动事件 onMove(x, y) { this.isSelecting = true