完善状态验证

This commit is contained in:
2026-03-13 09:01:59 +08:00
parent a5304bdc9e
commit 3617a6a086
5 changed files with 233 additions and 292 deletions

View File

@@ -1,4 +1,4 @@
import { AkReqUploadOptions, AkReqOptions, AkReqResponse, AkReqError } from './interface.uts';
import { AkReqUploadOptions, AkReqOptions, AkReqResponse, AkReqError } from './interface.uts';
import { SUPA_URL } from '@/ak/config.uts';
// token 持久化 key
@@ -117,10 +117,7 @@ export class AkReq {
if (accessToken !== null && refreshTokenNew !== null && expiresAt !== null) {
this.setToken(accessToken, refreshTokenNew, expiresAt);
return true;
} else {
this.clearToken();
return false;
}
} else { this.clearToken(); uni.$emit('AUTH_SESSION_EXPIRED', { reason: 'refresh_failed' }); return false; }
} catch (e) {
this.clearToken();
return false;
@@ -249,6 +246,8 @@ export class AkReq {
// 全局处理 401 未授权:在非 refresh 场景下,清理 token。
// 测试模式下不强制跳登录页,避免影响任意跳转调试。
if ((finalRes.status === 401) && (skipRefresh !== true)) {
uni.$emit('AUTH_SESSION_EXPIRED', { reason: '401' });
try {
this.clearToken();
uni.showToast({ title: '未授权或登录已过期,请重新登录', icon: 'none' });