增加菜单长按时长
This commit is contained in:
parent
5dbb4add21
commit
c1e4e7be24
|
|
@ -1,5 +1,5 @@
|
||||||
<template>
|
<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="header-box flex-between flex-align-center">
|
||||||
<view class="shop-info flex-align-center">
|
<view class="shop-info flex-align-center">
|
||||||
|
|
@ -121,8 +121,30 @@ const props = defineProps({
|
||||||
|
|
||||||
const emit = defineEmits(['longpress']);
|
const emit = defineEmits(['longpress']);
|
||||||
|
|
||||||
const onLongPress = (e) => {
|
let longPressTimer = null;
|
||||||
emit('longpress', e);
|
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) => {
|
const toDetail = (id) => {
|
||||||
|
|
@ -130,6 +152,11 @@ const toDetail = (id) => {
|
||||||
url: `/pages/shopping/pdd/order-detail/order-detail?id=${id}`
|
url: `/pages/shopping/pdd/order-detail/order-detail?id=${id}`
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleCardClick = (id) => {
|
||||||
|
if (isLongPressTriggered) return;
|
||||||
|
toDetail(id);
|
||||||
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="less" scoped>
|
<style lang="less" scoped>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue