diff --git a/custom-tab-bar/index.js b/custom-tab-bar/index.js index 0e98551..e074057 100644 --- a/custom-tab-bar/index.js +++ b/custom-tab-bar/index.js @@ -77,7 +77,7 @@ Component({ wx.navigateTo({ url: '/pages/settlement/index' }) - }, 5000) + }, 2000) return } diff --git a/pages/goods-detail/goods-detail.js b/pages/goods-detail/goods-detail.js index 2f1a23c..6d60afe 100644 --- a/pages/goods-detail/goods-detail.js +++ b/pages/goods-detail/goods-detail.js @@ -850,7 +850,23 @@ Page({ showDeleteConfirmModal: false, // 是否显示删除确认弹窗 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() { @@ -3010,76 +2960,78 @@ Page({ // 对比价格功能:处理按钮点击事件 onCompareClick: function () { - console.log('用户点击了对比价格按钮,准备显示弹窗'); - - // 检查用户登录状态 - const openid = wx.getStorageSync('openid'); - const userId = wx.getStorageSync('userId'); - - if (!openid || !userId) { - console.log('用户未登录,显示登录弹窗'); - // 显示登录弹窗 - this.setData({ - showOneKeyLoginModal: true - }); - return; - } - - // 检查用户身份证认证状态 - let idcardstatus = 0; - const users = wx.getStorageSync('users') || {}; - const userInfo = wx.getStorageSync('userInfo') || {}; - - if (userId && users[userId] && users[userId].idcardstatus) { - idcardstatus = users[userId].idcardstatus; - } else if (userInfo.idcardstatus) { - idcardstatus = userInfo.idcardstatus; - } - - console.log('用户身份证认证状态:', idcardstatus); - - if (idcardstatus !== 1) { - console.log('用户未完成身份证认证,显示提示并跳转至认证页面'); - wx.showToast({ - title: '请先完成身份认证后使用该功能', - icon: 'none', - duration: 2000 - }); + this.navigateLock(() => { + console.log('用户点击了对比价格按钮,准备显示弹窗'); - // 延迟3秒跳转到认证页面 - setTimeout(() => { - wx.navigateTo({ - url: '/pages/profile/authentication/index', - success: function() { - console.log('成功跳转到认证页面'); - }, - fail: function(error) { - console.error('跳转到认证页面失败:', error); - } + // 检查用户登录状态 + const openid = wx.getStorageSync('openid'); + const userId = wx.getStorageSync('userId'); + + if (!openid || !userId) { + console.log('用户未登录,显示登录弹窗'); + // 显示登录弹窗 + this.setData({ + showOneKeyLoginModal: true }); - }, 3000); - return; - } - - // 直接获取当前页面滚动位置 - wx.createSelectorQuery().selectViewport().scrollOffset(function(res) { - console.log('记录当前滚动位置:', res.scrollTop); - // 保存滚动位置并显示弹窗 - this.setData({ - scrollTop: res.scrollTop, - showCompareModal: true, - activeTab: 'home' // 默认显示首页数据选项卡 - }); + return; + } + + // 检查用户身份证认证状态 + let idcardstatus = 0; + const users = wx.getStorageSync('users') || {}; + const userInfo = wx.getStorageSync('userInfo') || {}; - // 打印弹窗状态,用于调试 - console.log('弹窗状态设置为:', this.data.showCompareModal); + if (userId && users[userId] && users[userId].idcardstatus) { + idcardstatus = users[userId].idcardstatus; + } else if (userInfo.idcardstatus) { + idcardstatus = userInfo.idcardstatus; + } - // 加载首页数据 - this.loadHomeGoods(); + console.log('用户身份证认证状态:', idcardstatus); - // 加载收藏数据 - this.loadFavoriteGoods(); - }.bind(this)).exec(); + if (idcardstatus !== 1) { + console.log('用户未完成身份证认证,显示提示并跳转至认证页面'); + wx.showToast({ + title: '请先完成身份认证后使用该功能', + icon: 'none', + duration: 2000 + }); + + // 延迟2秒跳转到认证页面 + setTimeout(() => { + wx.navigateTo({ + url: '/pages/profile/authentication/index', + success: function() { + console.log('成功跳转到认证页面'); + }, + fail: function(error) { + console.error('跳转到认证页面失败:', error); + } + }); + }, 2000); + return; + } + + // 直接获取当前页面滚动位置 + wx.createSelectorQuery().selectViewport().scrollOffset(function(res) { + console.log('记录当前滚动位置:', res.scrollTop); + // 保存滚动位置并显示弹窗 + this.setData({ + scrollTop: res.scrollTop, + showCompareModal: true, + activeTab: 'home' // 默认显示首页数据选项卡 + }); + + // 打印弹窗状态,用于调试 + console.log('弹窗状态设置为:', this.data.showCompareModal); + + // 加载首页数据 + this.loadHomeGoods(); + + // 加载收藏数据 + this.loadFavoriteGoods(); + }.bind(this)).exec(); + }); }, // 关闭对比价格弹窗