This commit is contained in:
parent
c1e4e7be24
commit
788f4e6b5e
|
|
@ -123,9 +123,16 @@ const emit = defineEmits(['longpress']);
|
|||
|
||||
let longPressTimer = null;
|
||||
let isLongPressTriggered = false;
|
||||
let startX = 0;
|
||||
let startY = 0;
|
||||
|
||||
const handleTouchStart = (e) => {
|
||||
isLongPressTriggered = false;
|
||||
const touch = e.touches[0] || e.changedTouches[0];
|
||||
if (touch) {
|
||||
startX = touch.clientX;
|
||||
startY = touch.clientY;
|
||||
}
|
||||
longPressTimer = setTimeout(() => {
|
||||
isLongPressTriggered = true;
|
||||
uni.vibrateShort();
|
||||
|
|
@ -133,10 +140,18 @@ const handleTouchStart = (e) => {
|
|||
}, 1200); // 长按时间 1200ms
|
||||
};
|
||||
|
||||
const handleTouchMove = () => {
|
||||
const handleTouchMove = (e) => {
|
||||
if (longPressTimer) {
|
||||
clearTimeout(longPressTimer);
|
||||
longPressTimer = null;
|
||||
const touch = e.touches[0] || e.changedTouches[0];
|
||||
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