This commit is contained in:
tangxinyue 2026-05-30 15:35:53 +08:00
parent c1e4e7be24
commit 788f4e6b5e
1 changed files with 18 additions and 3 deletions

View File

@ -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;
}
}
}
};