From 1f473b79e9a2c9ce77cec4899cee7640e197b2f2 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, 13 Jun 2024 16:26:51 +0800 Subject: [PATCH] =?UTF-8?q?Fix=EF=BC=9A=E4=BF=AE=E5=A4=8DTouchEvent?= =?UTF-8?q?=E6=8F=92=E4=BB=B6=E4=B8=A4=E6=AC=A1=E7=82=B9=E5=87=BB=E4=BD=8D?= =?UTF-8?q?=E7=BD=AE=E4=B8=8D=E5=90=8C=E6=97=B6=E4=B9=9F=E4=BC=9A=E8=A7=A6?= =?UTF-8?q?=E5=8F=91=E8=8A=82=E7=82=B9=E8=BE=93=E5=85=A5=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- simple-mind-map/src/plugins/TouchEvent.js | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/simple-mind-map/src/plugins/TouchEvent.js b/simple-mind-map/src/plugins/TouchEvent.js index c2e17783..61fae73d 100644 --- a/simple-mind-map/src/plugins/TouchEvent.js +++ b/simple-mind-map/src/plugins/TouchEvent.js @@ -1,3 +1,5 @@ +import { getTwoPointDistance } from '../utils' + // 手势事件支持插件 class TouchEvent { // 构造函数 @@ -7,6 +9,8 @@ class TouchEvent { this.singleTouchstartEvent = null this.clickNum = 0 this.touchStartScaleView = null + this.lastTouchStartPosition = null + this.lastTouchStartDistance = 0 this.bindEvent() } @@ -34,11 +38,22 @@ class TouchEvent { // 手指按下事件 onTouchstart(e) { - e.preventDefault() this.touchesNum = e.touches.length this.touchStartScaleView = null if (this.touchesNum === 1) { let touch = e.touches[0] + if (this.lastTouchStartPosition) { + this.lastTouchStartDistance = getTwoPointDistance( + this.lastTouchStartPosition.x, + this.lastTouchStartPosition.y, + touch.clientX, + touch.clientY + ) + } + this.lastTouchStartPosition = { + x: touch.clientX, + y: touch.clientY + } this.singleTouchstartEvent = touch this.dispatchMouseEvent('mousedown', touch.target, touch) } @@ -46,7 +61,6 @@ class TouchEvent { // 手指移动事件 onTouchmove(e) { - e.preventDefault() let len = e.touches.length if (len === 1) { let touch = e.touches[0] @@ -107,16 +121,17 @@ class TouchEvent { // 手指松开事件 onTouchend(e) { - e.preventDefault() this.dispatchMouseEvent('mouseup', e.target) if (this.touchesNum === 1) { // 模拟双击事件 this.clickNum++ setTimeout(() => { this.clickNum = 0 + this.lastTouchStartPosition = null + this.lastTouchStartDistance = 0 }, 300) let ev = this.singleTouchstartEvent - if (this.clickNum > 1) { + if (this.clickNum > 1 && this.lastTouchStartDistance <= 5) { this.clickNum = 0 this.dispatchMouseEvent('dblclick', ev.target, ev) } else {