Compare commits

..

1 Commits

Author SHA1 Message Date
kk b2b92ec6b4 防止重复跳转
Uni-app H5 Deploy (Prod + Staging) / deploy (release) Successful in 45s
2026-07-17 15:13:13 +08:00
+31
View File
@@ -16,6 +16,7 @@ export default {
statusText: '正在登录...',
deviceId: '',
action: '',
navigating: false, // 防止重复跳转
};
},
onLoad(options) {
@@ -91,6 +92,13 @@ export default {
* 发起 OAuth 授权(静默授权,只获取 openid)
*/
async startAuth() {
// 防止重复调用
if (this.navigating) {
console.log('[Auth] 已在跳转中,忽略重复 startAuth');
return;
}
this.navigating = true;
// 清除上次使用的 code 标记
uni.removeStorageSync('__used_auth_code');
@@ -151,6 +159,13 @@ export default {
* 处理授权回调(用 code 换 openid,再用 openid 登录)
*/
async handleCallback(code) {
// 防止重复调用(redirectTo 是异步的,页面可能被重新触发)
if (this.navigating) {
console.log('[Auth] 已在跳转中,忽略重复 handleCallback');
return;
}
this.navigating = true;
const appNo = uni.getStorageSync('app_no') || getAppNo(detectPlatform());
if (!appNo) {
@@ -163,6 +178,7 @@ export default {
const usedCode = uni.getStorageSync('__used_auth_code');
if (usedCode === code) {
console.warn('[loading] code 已使用过,跳过');
this.navigating = false;
return;
}
uni.setStorageSync('__used_auth_code', code);
@@ -247,6 +263,13 @@ export default {
* 发起非静默授权获取用户信息(snsapi_userinfo,弹窗确认)
*/
async startUserInfoAuth() {
// 防止重复调用
if (this.navigating) {
console.log('[Auth] 已在跳转中,忽略重复 startUserInfoAuth');
return;
}
this.navigating = true;
// 清除上次使用的 code 标记
uni.removeStorageSync('__used_auth_code');
@@ -308,6 +331,13 @@ export default {
* 处理用户信息授权回调(用 code 调 /api/v1/user/info 获取头像昵称)
*/
async handleUserInfoCallback(code) {
// 防止重复调用
if (this.navigating) {
console.log('[Auth] 已在跳转中,忽略重复 handleUserInfoCallback');
return;
}
this.navigating = true;
const appNo = uni.getStorageSync('app_no') || getAppNo(detectPlatform());
if (!appNo) {
@@ -319,6 +349,7 @@ export default {
const usedCode = uni.getStorageSync('__used_auth_code');
if (usedCode === code) {
console.warn('[loading] code 已使用过,跳过');
this.navigating = false;
return;
}
uni.setStorageSync('__used_auth_code', code);