This commit is contained in:
parent
c1e4e7be24
commit
788f4e6b5e
|
|
@ -123,9 +123,16 @@ const emit = defineEmits(['longpress']);
|
||||||
|
|
||||||
let longPressTimer = null;
|
let longPressTimer = null;
|
||||||
let isLongPressTriggered = false;
|
let isLongPressTriggered = false;
|
||||||
|
let startX = 0;
|
||||||
|
let startY = 0;
|
||||||
|
|
||||||
const handleTouchStart = (e) => {
|
const handleTouchStart = (e) => {
|
||||||
isLongPressTriggered = false;
|
isLongPressTriggered = false;
|
||||||
|
const touch = e.touches[0] || e.changedTouches[0];
|
||||||
|
if (touch) {
|
||||||
|
startX = touch.clientX;
|
||||||
|
startY = touch.clientY;
|
||||||
|
}
|
||||||
longPressTimer = setTimeout(() => {
|
longPressTimer = setTimeout(() => {
|
||||||
isLongPressTriggered = true;
|
isLongPressTriggered = true;
|
||||||
uni.vibrateShort();
|
uni.vibrateShort();
|
||||||
|
|
@ -133,10 +140,18 @@ const handleTouchStart = (e) => {
|
||||||
}, 1200); // 长按时间 1200ms
|
}, 1200); // 长按时间 1200ms
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleTouchMove = () => {
|
const handleTouchMove = (e) => {
|
||||||
if (longPressTimer) {
|
if (longPressTimer) {
|
||||||
clearTimeout(longPressTimer);
|
const touch = e.touches[0] || e.changedTouches[0];
|
||||||
longPressTimer = null;
|
if (touch) {
|
||||||
|
const moveX = touch.clientX;
|
||||||
|
const moveY = touch.clientY;
|
||||||
|
// 增加 15px 容错,防止微小抖动取消长按
|
||||||
|
if (Math.abs(moveX - startX) > 15 || Math.abs(moveY - startY) > 15) {
|
||||||
|
clearTimeout(longPressTimer);
|
||||||
|
longPressTimer = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue