增加菜单长按时长

This commit is contained in:
tangxinyue 2026-05-30 15:30:15 +08:00
parent 5dbb4add21
commit c1e4e7be24
1 changed files with 30 additions and 3 deletions

View File

@ -1,5 +1,5 @@
<template>
<view class="list-card-container" v-if="item" @click="toDetail(item.id)" @longpress="onLongPress">
<view class="list-card-container" v-if="item" @click="handleCardClick(item.id)" @touchstart="handleTouchStart" @touchmove="handleTouchMove" @touchend="handleTouchEnd" @touchcancel="handleTouchEnd">
<!-- 头部店铺信息和状态 -->
<view class="header-box flex-between flex-align-center">
<view class="shop-info flex-align-center">
@ -121,8 +121,30 @@ const props = defineProps({
const emit = defineEmits(['longpress']);
const onLongPress = (e) => {
emit('longpress', e);
let longPressTimer = null;
let isLongPressTriggered = false;
const handleTouchStart = (e) => {
isLongPressTriggered = false;
longPressTimer = setTimeout(() => {
isLongPressTriggered = true;
uni.vibrateShort();
emit('longpress', e);
}, 1200); // 1200ms
};
const handleTouchMove = () => {
if (longPressTimer) {
clearTimeout(longPressTimer);
longPressTimer = null;
}
};
const handleTouchEnd = () => {
if (longPressTimer) {
clearTimeout(longPressTimer);
longPressTimer = null;
}
};
const toDetail = (id) => {
@ -130,6 +152,11 @@ const toDetail = (id) => {
url: `/pages/shopping/pdd/order-detail/order-detail?id=${id}`
});
};
const handleCardClick = (id) => {
if (isLongPressTriggered) return;
toDetail(id);
};
</script>
<style lang="less" scoped>