Compare commits
No commits in common. '177a4dfe324841d4b89e53263ac3fd047af5dc97' and '336125dd89eba18f95b66570070806f7f4c50be3' have entirely different histories.
177a4dfe32
...
336125dd89
Before Width: | Height: | Size: 87 KiB After Width: | Height: | Size: 87 KiB |
Before Width: | Height: | Size: 611 B After Width: | Height: | Size: 611 B |
Before Width: | Height: | Size: 586 B After Width: | Height: | Size: 586 B |
Before Width: | Height: | Size: 576 B After Width: | Height: | Size: 576 B |
After Width: | Height: | Size: 87 KiB |
After Width: | Height: | Size: 22 KiB |
After Width: | Height: | Size: 14 KiB |
@ -1,47 +0,0 @@ |
|||||||
// 长按弹出上拉操作面板
|
|
||||||
class Mobile { |
|
||||||
toucheX: number = 0; |
|
||||||
toucheY: number = 0; |
|
||||||
timeOutEvent: number = 0; |
|
||||||
data?: any; |
|
||||||
onLongTouch?: Function; |
|
||||||
onClick?: Function; |
|
||||||
e: any; |
|
||||||
|
|
||||||
onTouchStart(e, data) { |
|
||||||
this.toucheX = e.targetTouches[0].screenX; |
|
||||||
this.toucheY = e.targetTouches[0].screenY; |
|
||||||
this.data = data; |
|
||||||
this.e = e; |
|
||||||
|
|
||||||
// 开启定时器前先清除定时器,防止重复触发
|
|
||||||
this.timeOutEvent && clearTimeout(this.timeOutEvent); |
|
||||||
// 显示上拉面板
|
|
||||||
this.timeOutEvent = setTimeout(() => { |
|
||||||
this.onLongTouch && this.onLongTouch(e, data); |
|
||||||
this.timeOutEvent = 0; |
|
||||||
}, 1000); |
|
||||||
e.preventDefault(); // 阻止系统默认事件
|
|
||||||
} |
|
||||||
onTouchMove(e) { |
|
||||||
const moveX = e.targetTouches[0].screenX; |
|
||||||
const moveY = e.targetTouches[0].screenY; |
|
||||||
// 解决vivo机型,手指没有move,touchmove事件仍然会调用而导致setTimeout被clear
|
|
||||||
if (this.toucheX !== moveX || this.toucheY !== moveY) { |
|
||||||
// 手指滑动,清除定时器,中断长按逻辑
|
|
||||||
this.timeOutEvent && clearTimeout(this.timeOutEvent); |
|
||||||
} |
|
||||||
} |
|
||||||
onTouchEnd() { |
|
||||||
// 清除定时器,结束长按逻辑
|
|
||||||
this.timeOutEvent && clearTimeout(this.timeOutEvent); |
|
||||||
// 若手指离开屏幕,时间小于我们设置的长按时间,则为点击事件
|
|
||||||
if (this.timeOutEvent !== 0) { |
|
||||||
this.onClick && this.onClick(this.e, this.data); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
export const userMobile = () => { |
|
||||||
return new Mobile(); |
|
||||||
}; |
|