From 424a1a65e7ac5f0d76355cafab298d54dcec1680 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E9=A3=9E=E6=B4=8B?= <15778543+xufeiyang6017@user.noreply.gitee.com> Date: Fri, 30 Jan 2026 11:07:54 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E9=98=B2=E6=AD=A2=E5=A4=9A=E6=AC=A1?= =?UTF-8?q?=E7=82=B9=E5=87=BB=E5=AF=BC=E8=87=B4=E5=A4=9A=E6=AC=A1=E8=B7=B3?= =?UTF-8?q?=E8=BD=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- custom-tab-bar/index.js | 232 ++++++++++++++++------------- pages/evaluate2/index.js | 58 +++++--- pages/goods-detail/goods-detail.js | 4 +- 3 files changed, 167 insertions(+), 127 deletions(-) diff --git a/custom-tab-bar/index.js b/custom-tab-bar/index.js index 5d85d1a..0e98551 100644 --- a/custom-tab-bar/index.js +++ b/custom-tab-bar/index.js @@ -12,6 +12,7 @@ Component({ selected: 'index', show: true, badges: {}, + navigating: false, tabBarItems: [ { key: 'index', route: 'pages/index/index' }, { key: 'chat', route: 'pages/chat/index', badgeKey: 'chat' }, @@ -21,11 +22,24 @@ Component({ { key: 'profile', route: 'pages/profile/index' } ] }, - + /** * 组件的方法列表 */ methods: { + // 导航锁机制,防止多次点击导致多次跳转 + navigateLock: function(cb) { + if (this.data.navigating) { + return false; + } + this.setData({ navigating: true }); + cb(); + // 延迟重置导航锁,确保导航操作有足够时间完成 + setTimeout(() => { + this.setData({ navigating: false }); + }, 5000); + return true; + }, // 切换tab页面的方法 - 增强版,改进状态管理 switchTab(e) { try { @@ -117,51 +131,53 @@ Component({ // 跳转到tab页面的通用方法 navigateToTabPage(url) { - // 定义tabBar页面列表 - const tabBarPages = [ - 'pages/index/index', - 'pages/chat/index', - 'pages/evaluate2/one', - 'pages/eggbar/eggbar', - 'pages/favorites/index', - 'pages/profile/index' - ]; - - // 检查是否为tabBar页面 - if (tabBarPages.includes(url)) { - console.log('使用switchTab跳转到tabbar页面:', url) - wx.switchTab({ - url: '/' + url, - success: (res) => { - console.log('switchTab成功:', url, res) - }, - fail: (err) => { - console.error('switchTab失败:', url, err) - console.log('尝试使用reLaunch跳转...') - wx.reLaunch({ - url: '/' + url, - success: (res) => { - console.log('reLaunch成功:', url, res) - }, - fail: (err) => { - console.error('reLaunch也失败:', url, err) - } - }) - } - }) - } else { - // 非tabBar页面,使用navigateTo跳转 - console.log('使用navigateTo跳转到非tabbar页面:', url) - wx.navigateTo({ - url: '/' + url, - success: (res) => { - console.log('navigateTo成功:', url, res) - }, - fail: (err) => { - console.error('navigateTo失败:', url, err) - } - }) - } + this.navigateLock(() => { + // 定义tabBar页面列表 + const tabBarPages = [ + 'pages/index/index', + 'pages/chat/index', + 'pages/evaluate2/one', + 'pages/eggbar/eggbar', + 'pages/favorites/index', + 'pages/profile/index' + ]; + + // 检查是否为tabBar页面 + if (tabBarPages.includes(url)) { + console.log('使用switchTab跳转到tabbar页面:', url) + wx.switchTab({ + url: '/' + url, + success: (res) => { + console.log('switchTab成功:', url, res) + }, + fail: (err) => { + console.error('switchTab失败:', url, err) + console.log('尝试使用reLaunch跳转...') + wx.reLaunch({ + url: '/' + url, + success: (res) => { + console.log('reLaunch成功:', url, res) + }, + fail: (err) => { + console.error('reLaunch也失败:', url, err) + } + }) + } + }) + } else { + // 非tabBar页面,使用navigateTo跳转 + console.log('使用navigateTo跳转到非tabbar页面:', url) + wx.navigateTo({ + url: '/' + url, + success: (res) => { + console.log('navigateTo成功:', url, res) + }, + fail: (err) => { + console.error('navigateTo失败:', url, err) + } + }) + } + }); }, // 强制更新选中状态 @@ -198,74 +214,78 @@ Component({ // 跳转到收藏页面 goToFavoritesPage() { - wx.navigateTo({ - url: '/pages/favorites/index' - }) + this.navigateLock(() => { + wx.navigateTo({ + url: '/pages/favorites/index' + }) + }); }, // 跳转到估价页面 goToEvaluatePage() { - console.log('点击了估价按钮,跳转到evaluate2/one页面') - - // 判断partnerstatus是否为approved - const app = getApp() - const userInfo = app.globalData.userInfo || wx.getStorageSync('userInfo') || {} - const partnerstatus = userInfo.partnerstatus - - console.log('用户partnerstatus:', partnerstatus) - - // 如果partnerstatus不是approved,提示用户并跳转到入驻页面 - if (partnerstatus !== 'approved') { - wx.showToast({ - title: '该功能需要入驻之后才能使用', - icon: 'none', - duration: 5000 - }) + this.navigateLock(() => { + console.log('点击了估价按钮,跳转到evaluate2/one页面') - // 5秒后自动跳转到入驻页面 - setTimeout(() => { - wx.navigateTo({ - url: '/pages/settlement/index' - }) - }, 5000) + // 判断idcardstatus是否为1 + const app = getApp() + const userInfo = app.globalData.userInfo || wx.getStorageSync('userInfo') || {} + const idcardstatus = userInfo.idcardstatus - return - } - - wx.switchTab({ - url: '/pages/evaluate2/one', - success: (res) => { - console.log('switchTab到evaluate2/one成功:', res) - // 更新选中状态 - this.setData({ selected: 'evaluate' }) - // 更新全局数据 - const app = getApp() - if (app && app.globalData) { - app.globalData.currentTab = 'evaluate' - } - }, - fail: (err) => { - console.error('switchTab到evaluate2/one失败:', err) - // 失败时尝试使用reLaunch - console.log('尝试使用reLaunch跳转到evaluate2/one...') - wx.reLaunch({ - url: '/pages/evaluate2/one', - success: (res) => { - console.log('reLaunch到evaluate2/one成功:', res) - // 更新选中状态 - this.setData({ selected: 'evaluate' }) - // 更新全局数据 - const app = getApp() - if (app && app.globalData) { - app.globalData.currentTab = 'evaluate' - } - }, - fail: (err) => { - console.error('reLaunch到evaluate2/one也失败:', err) - } + console.log('用户idcardstatus:', idcardstatus) + + // 如果idcardstatus不是1,提示用户并跳转到入驻页面 + if (idcardstatus !== 1) { + wx.showToast({ + title: '请先完成身份认证', + icon: 'none', + duration: 3000 }) + + // 3秒后自动跳转到认证页面 + setTimeout(() => { + wx.navigateTo({ + url: '/pages/profile/authentication/index' + }) + }, 3000) + + return } - }) + + wx.switchTab({ + url: '/pages/evaluate2/one', + success: (res) => { + console.log('switchTab到evaluate2/one成功:', res) + // 更新选中状态 + this.setData({ selected: 'evaluate' }) + // 更新全局数据 + const app = getApp() + if (app && app.globalData) { + app.globalData.currentTab = 'evaluate' + } + }, + fail: (err) => { + console.error('switchTab到evaluate2/one失败:', err) + // 失败时尝试使用reLaunch + console.log('尝试使用reLaunch跳转到evaluate2/one...') + wx.reLaunch({ + url: '/pages/evaluate2/one', + success: (res) => { + console.log('reLaunch到evaluate2/one成功:', res) + // 更新选中状态 + this.setData({ selected: 'evaluate' }) + // 更新全局数据 + const app = getApp() + if (app && app.globalData) { + app.globalData.currentTab = 'evaluate' + } + }, + fail: (err) => { + console.error('reLaunch到evaluate2/one也失败:', err) + } + }) + } + }) + }); }, // 从全局数据同步状态的方法 - 增强版 diff --git a/pages/evaluate2/index.js b/pages/evaluate2/index.js index 8543ab6..fa9f44d 100644 --- a/pages/evaluate2/index.js +++ b/pages/evaluate2/index.js @@ -3,7 +3,21 @@ Page({ productName: '', specifications: [], loading: false, - error: '' + error: '', + navigating: false + }, + // 导航锁机制,防止多次点击导致多次跳转 + navigateLock: function(cb) { + if (this.data.navigating) { + return false; + } + this.setData({ navigating: true }); + cb(); + // 延迟重置导航锁,确保导航操作有足够时间完成 + setTimeout(() => { + this.setData({ navigating: false }); + }, 1000); + return true; }, onLoad(options) { let productName = ''; @@ -454,33 +468,39 @@ Page({ // 跳转到规格详情页面 goToSpecDetail(e) { - const specItem = e.currentTarget.dataset.spec; - console.log('点击的规格项:', specItem); - console.log('传递的价格:', specItem.finalPriceText); - wx.navigateTo({ - url: `/pages/evaluate2/spec-detail?productName=${encodeURIComponent(this.data.productName)}&specification=${encodeURIComponent(specItem.name)}&price=${encodeURIComponent(specItem.finalPriceText)}` + this.navigateLock(() => { + const specItem = e.currentTarget.dataset.spec; + console.log('点击的规格项:', specItem); + console.log('传递的价格:', specItem.finalPriceText); + wx.navigateTo({ + url: `/pages/evaluate2/spec-detail?productName=${encodeURIComponent(this.data.productName)}&specification=${encodeURIComponent(specItem.name)}&price=${encodeURIComponent(specItem.finalPriceText)}` + }); }); }, // 返回上一页 goBack() { - wx.navigateBack(); + this.navigateLock(() => { + wx.navigateBack(); + }); }, // 返回商品列表页面 goBackToProductList() { - // 从本地存储中获取之前选择的分类 - const selectedCategory = wx.getStorageSync('selectedCategory') || ''; - console.log('返回商品列表页面,之前选择的分类:', selectedCategory); - - // 构建跳转URL,如果有分类参数就传递 - let url = '/pages/evaluate2/product-list'; - if (selectedCategory) { - url += '?category=' + encodeURIComponent(selectedCategory); - } - - wx.redirectTo({ - url: url + this.navigateLock(() => { + // 从本地存储中获取之前选择的分类 + const selectedCategory = wx.getStorageSync('selectedCategory') || ''; + console.log('返回商品列表页面,之前选择的分类:', selectedCategory); + + // 构建跳转URL,如果有分类参数就传递 + let url = '/pages/evaluate2/product-list'; + if (selectedCategory) { + url += '?category=' + encodeURIComponent(selectedCategory); + } + + wx.redirectTo({ + url: url + }); }); }, diff --git a/pages/goods-detail/goods-detail.js b/pages/goods-detail/goods-detail.js index f7f6a13..2f1a23c 100644 --- a/pages/goods-detail/goods-detail.js +++ b/pages/goods-detail/goods-detail.js @@ -3046,7 +3046,7 @@ Page({ duration: 2000 }); - // 延迟5秒跳转到认证页面 + // 延迟3秒跳转到认证页面 setTimeout(() => { wx.navigateTo({ url: '/pages/profile/authentication/index', @@ -3057,7 +3057,7 @@ Page({ console.error('跳转到认证页面失败:', error); } }); - }, 5000); + }, 3000); return; }