feat: 修复登录逻辑
This commit is contained in:
+20
-2
@@ -59,6 +59,24 @@ class WxRequest {
|
||||
const processedResponse = this.interceptors.response(res);
|
||||
const { statusCode, data } = processedResponse;
|
||||
|
||||
// Auto-refresh token if 401 (One-time retry)
|
||||
if ((statusCode === 401 || data.code === 401) && !options.skipToken && !options._retry) {
|
||||
const app = getApp();
|
||||
if (app && app.forceRefreshLogin) {
|
||||
console.log('401 detected, refreshing token...');
|
||||
app.forceRefreshLogin().then(() => {
|
||||
// Retry Original Request
|
||||
this.request({ ...options, _retry: true })
|
||||
.then(resolve)
|
||||
.catch(reject);
|
||||
}).catch(err => {
|
||||
console.error('Token refresh failed', err);
|
||||
reject(data);
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// 1. Check HTTP Status Code
|
||||
if (statusCode >= 200 && statusCode < 300) {
|
||||
// 2. Check Business Logic Code (Assuming 200 is success based on common Go patterns,
|
||||
@@ -252,8 +270,8 @@ class WxRequest {
|
||||
|
||||
// Initialize with default instance
|
||||
const request = new WxRequest({
|
||||
//baseUrl: 'http://192.168.0.184:8889',
|
||||
baseUrl: 'https://go.sundynix.cn/api',
|
||||
baseUrl: 'http://192.168.0.184:8889',
|
||||
//baseUrl: 'https://go.sundynix.cn/api',
|
||||
header: {
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user