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