findme-miniprogram-frontend/utils/redirect.js
2025-12-27 17:16:03 +08:00

95 lines
2.3 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

var redirecting=false;
// 🔥 统一的页面跳转方法 - 避免跳转冲突和超时
function navigateToPage(url) {
// 防止重复跳转
if (redirecting) {
return;
}
redirecting = true;
// 延迟执行,确保页面状态稳定
setTimeout(() => {
wx.navigateTo({
url: url,
success: () => {
redirecting = false;
},
fail: (error) => {
console.error('❌ 跳转到'+url+'失败:', error);
redirecting = false;
// 备用方案
wx.redirectTo({
url: url,
fail: (error2) => {
console.error('❌ redirectTo '+url+'失败:', error2);
wx.showToast({
title: '跳转失败,请重试',
icon: 'none'
});
}
});
}
});
}, 200); // 200ms延迟确保页面状态稳定
} // 🔥 统一的页面跳转方法 - 避免跳转冲突和超时
function reLaunchToPage(url) {
// 防止重复跳转
if (redirecting) {
return;
}
redirecting = true;
// 延迟执行,确保页面状态稳定
setTimeout(() => {
wx.reLaunch({
url: url,
success: () => {
redirecting = false;
},
fail: (error) => {
console.error('❌ 跳转到'+url+'失败:', error);
redirecting = false;
// 备用方案
wx.redirectTo({
url: url,
fail: (error2) => {
console.error('❌ redirectTo '+url+'失败:', error2);
wx.showToast({
title: '跳转失败,请重试',
icon: 'none'
});
}
});
}
});
}, 200); // 200ms延迟确保页面状态稳定
}
// 🔥 统一的手机号登陆页面跳转方法 - 避免跳转冲突和超时
function goMobileLogin() {
navigateToPage('/pages/login/mobile-login-page')
}
// 🔥 统一的主页跳转方法 - 避免跳转冲突和超时
function goMain() {
reLaunchToPage('/pages/map/map')
}
function goProfile() {
navigateToPage('/pages/login/profile-page')
}
module.exports = {
navigateToPage: navigateToPage,
goMobileLogin: goMobileLogin,
reLaunchToPage:reLaunchToPage,
goMain: goMain,
goProfile: goProfile
}