Browse Source

feat: 防止多次点击导致多次跳转

蛋吧eggbar
徐飞洋 1 month ago
parent
commit
424a1a65e7
  1. 40
      custom-tab-bar/index.js
  2. 22
      pages/evaluate2/index.js
  3. 4
      pages/goods-detail/goods-detail.js

40
custom-tab-bar/index.js

@ -12,6 +12,7 @@ Component({
selected: 'index', selected: 'index',
show: true, show: true,
badges: {}, badges: {},
navigating: false,
tabBarItems: [ tabBarItems: [
{ key: 'index', route: 'pages/index/index' }, { key: 'index', route: 'pages/index/index' },
{ key: 'chat', route: 'pages/chat/index', badgeKey: 'chat' }, { key: 'chat', route: 'pages/chat/index', badgeKey: 'chat' },
@ -26,6 +27,19 @@ Component({
* 组件的方法列表 * 组件的方法列表
*/ */
methods: { methods: {
// 导航锁机制,防止多次点击导致多次跳转
navigateLock: function(cb) {
if (this.data.navigating) {
return false;
}
this.setData({ navigating: true });
cb();
// 延迟重置导航锁,确保导航操作有足够时间完成
setTimeout(() => {
this.setData({ navigating: false });
}, 5000);
return true;
},
// 切换tab页面的方法 - 增强版,改进状态管理 // 切换tab页面的方法 - 增强版,改进状态管理
switchTab(e) { switchTab(e) {
try { try {
@ -117,6 +131,7 @@ Component({
// 跳转到tab页面的通用方法 // 跳转到tab页面的通用方法
navigateToTabPage(url) { navigateToTabPage(url) {
this.navigateLock(() => {
// 定义tabBar页面列表 // 定义tabBar页面列表
const tabBarPages = [ const tabBarPages = [
'pages/index/index', 'pages/index/index',
@ -162,6 +177,7 @@ Component({
} }
}) })
} }
});
}, },
// 强制更新选中状态 // 强制更新选中状态
@ -198,36 +214,39 @@ Component({
// 跳转到收藏页面 // 跳转到收藏页面
goToFavoritesPage() { goToFavoritesPage() {
this.navigateLock(() => {
wx.navigateTo({ wx.navigateTo({
url: '/pages/favorites/index' url: '/pages/favorites/index'
}) })
});
}, },
// 跳转到估价页面 // 跳转到估价页面
goToEvaluatePage() { goToEvaluatePage() {
this.navigateLock(() => {
console.log('点击了估价按钮,跳转到evaluate2/one页面') console.log('点击了估价按钮,跳转到evaluate2/one页面')
// 判断partnerstatus是否为approved // 判断idcardstatus是否为1
const app = getApp() const app = getApp()
const userInfo = app.globalData.userInfo || wx.getStorageSync('userInfo') || {} const userInfo = app.globalData.userInfo || wx.getStorageSync('userInfo') || {}
const partnerstatus = userInfo.partnerstatus const idcardstatus = userInfo.idcardstatus
console.log('用户partnerstatus:', partnerstatus) console.log('用户idcardstatus:', idcardstatus)
// 如果partnerstatus不是approved,提示用户并跳转到入驻页面 // 如果idcardstatus不是1,提示用户并跳转到入驻页面
if (partnerstatus !== 'approved') { if (idcardstatus !== 1) {
wx.showToast({ wx.showToast({
title: '该功能需要入驻之后才能使用', title: '请先完成身份认证',
icon: 'none', icon: 'none',
duration: 5000 duration: 3000
}) })
// 5秒后自动跳转到入驻页面 // 3秒后自动跳转到认证页面
setTimeout(() => { setTimeout(() => {
wx.navigateTo({ wx.navigateTo({
url: '/pages/settlement/index' url: '/pages/profile/authentication/index'
}) })
}, 5000) }, 3000)
return return
} }
@ -266,6 +285,7 @@ Component({
}) })
} }
}) })
});
}, },
// 从全局数据同步状态的方法 - 增强版 // 从全局数据同步状态的方法 - 增强版

22
pages/evaluate2/index.js

@ -3,7 +3,21 @@ Page({
productName: '', productName: '',
specifications: [], specifications: [],
loading: false, 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) { onLoad(options) {
let productName = ''; let productName = '';
@ -454,21 +468,26 @@ Page({
// 跳转到规格详情页面 // 跳转到规格详情页面
goToSpecDetail(e) { goToSpecDetail(e) {
this.navigateLock(() => {
const specItem = e.currentTarget.dataset.spec; const specItem = e.currentTarget.dataset.spec;
console.log('点击的规格项:', specItem); console.log('点击的规格项:', specItem);
console.log('传递的价格:', specItem.finalPriceText); console.log('传递的价格:', specItem.finalPriceText);
wx.navigateTo({ wx.navigateTo({
url: `/pages/evaluate2/spec-detail?productName=${encodeURIComponent(this.data.productName)}&specification=${encodeURIComponent(specItem.name)}&price=${encodeURIComponent(specItem.finalPriceText)}` url: `/pages/evaluate2/spec-detail?productName=${encodeURIComponent(this.data.productName)}&specification=${encodeURIComponent(specItem.name)}&price=${encodeURIComponent(specItem.finalPriceText)}`
}); });
});
}, },
// 返回上一页 // 返回上一页
goBack() { goBack() {
this.navigateLock(() => {
wx.navigateBack(); wx.navigateBack();
});
}, },
// 返回商品列表页面 // 返回商品列表页面
goBackToProductList() { goBackToProductList() {
this.navigateLock(() => {
// 从本地存储中获取之前选择的分类 // 从本地存储中获取之前选择的分类
const selectedCategory = wx.getStorageSync('selectedCategory') || ''; const selectedCategory = wx.getStorageSync('selectedCategory') || '';
console.log('返回商品列表页面,之前选择的分类:', selectedCategory); console.log('返回商品列表页面,之前选择的分类:', selectedCategory);
@ -482,6 +501,7 @@ Page({
wx.redirectTo({ wx.redirectTo({
url: url url: url
}); });
});
}, },
// 下拉刷新 // 下拉刷新

4
pages/goods-detail/goods-detail.js

@ -3046,7 +3046,7 @@ Page({
duration: 2000 duration: 2000
}); });
// 延迟5秒跳转到认证页面 // 延迟3秒跳转到认证页面
setTimeout(() => { setTimeout(() => {
wx.navigateTo({ wx.navigateTo({
url: '/pages/profile/authentication/index', url: '/pages/profile/authentication/index',
@ -3057,7 +3057,7 @@ Page({
console.error('跳转到认证页面失败:', error); console.error('跳转到认证页面失败:', error);
} }
}); });
}, 5000); }, 3000);
return; return;
} }

Loading…
Cancel
Save