Browse Source

fix: 防止多次点击导致多次页面跳转

蛋吧eggbar
徐飞洋 1 month ago
parent
commit
7a795a726a
  1. 2
      custom-tab-bar/index.js
  2. 90
      pages/goods-detail/goods-detail.js

2
custom-tab-bar/index.js

@ -77,7 +77,7 @@ Component({
wx.navigateTo({ wx.navigateTo({
url: '/pages/settlement/index' url: '/pages/settlement/index'
}) })
}, 5000) }, 2000)
return return
} }

90
pages/goods-detail/goods-detail.js

@ -850,7 +850,23 @@ Page({
showDeleteConfirmModal: false, // 是否显示删除确认弹窗 showDeleteConfirmModal: false, // 是否显示删除确认弹窗
commentToDelete: null, // 要删除的评论对象 commentToDelete: null, // 要删除的评论对象
// 当前用户信息 // 当前用户信息
currentUserPhone: '' // 当前用户的手机号,用于判断评论是否属于当前用户 currentUserPhone: '', // 当前用户的手机号,用于判断评论是否属于当前用户
// 导航锁状态
navigating: false // 是否正在导航中,防止多次点击导致多次跳转
},
// 导航锁机制,防止多次点击导致多次跳转
navigateLock: function(cb) {
if (this.data.navigating) {
return false;
}
this.setData({ navigating: true });
cb();
// 延迟重置导航锁,确保导航操作有足够时间完成
setTimeout(() => {
this.setData({ navigating: false });
}, 4000);
return true;
}, },
// 点击对比价格列表中的商品,跳转到对应的商品详情页 // 点击对比价格列表中的商品,跳转到对应的商品详情页
@ -2563,72 +2579,6 @@ Page({
}); });
}, },
/*
onClickWantInDetail(e) {
console.log('我想要事件:', e);
const { id } = e.currentTarget.dataset;
if (!id) return;
// 从本地存储获取openid
const openid = wx.getStorageSync('openid');
console.log('openid:', openid);
// 检查是否已登录
if (!openid) {
// 如果未登录,显示授权登录弹窗
this.setData({ showAuthModal: true });
return;
}
// 获取已预约商品ID列表
let reservedGoodsIds = wx.getStorageSync('reservedGoodsIds') || [];
// 检查是否已经预约过
if (reservedGoodsIds.some(itemId => String(itemId) === String(id))) {
wx.showToast({
title: '您已经预约过该商品',
icon: 'none',
duration: 1500
});
return;
}
// 添加到已预约列表
reservedGoodsIds.push(id);
wx.setStorageSync('reservedGoodsIds', reservedGoodsIds);
// 更新页面状态
this.setData({
'goodsDetail.isReserved': true
});
// 调用API记录预约
API.reserveProduct({ id: id })
.then(res => {
console.log('预约成功:', res);
wx.showToast({
title: '预约成功',
icon: 'success',
duration: 1500
});
})
.catch(err => {
console.error('预约失败:', err);
// 如果API调用失败,从本地列表中移除
reservedGoodsIds = reservedGoodsIds.filter(itemId => String(itemId) !== String(id));
wx.setStorageSync('reservedGoodsIds', reservedGoodsIds);
// 更新页面状态
this.setData({
'goodsDetail.isReserved': false
});
wx.showToast({
title: '预约失败,请重试',
icon: 'none',
duration: 1500
});
});
},
*/
// 关闭登录弹窗 // 关闭登录弹窗
closeOneKeyLoginModal() { closeOneKeyLoginModal() {
@ -3010,6 +2960,7 @@ Page({
// 对比价格功能:处理按钮点击事件 // 对比价格功能:处理按钮点击事件
onCompareClick: function () { onCompareClick: function () {
this.navigateLock(() => {
console.log('用户点击了对比价格按钮,准备显示弹窗'); console.log('用户点击了对比价格按钮,准备显示弹窗');
// 检查用户登录状态 // 检查用户登录状态
@ -3046,7 +2997,7 @@ Page({
duration: 2000 duration: 2000
}); });
// 延迟3秒跳转到认证页面 // 延迟2秒跳转到认证页面
setTimeout(() => { setTimeout(() => {
wx.navigateTo({ wx.navigateTo({
url: '/pages/profile/authentication/index', url: '/pages/profile/authentication/index',
@ -3057,7 +3008,7 @@ Page({
console.error('跳转到认证页面失败:', error); console.error('跳转到认证页面失败:', error);
} }
}); });
}, 3000); }, 2000);
return; return;
} }
@ -3080,6 +3031,7 @@ Page({
// 加载收藏数据 // 加载收藏数据
this.loadFavoriteGoods(); this.loadFavoriteGoods();
}.bind(this)).exec(); }.bind(this)).exec();
});
}, },
// 关闭对比价格弹窗 // 关闭对比价格弹窗

Loading…
Cancel
Save