Skip to content

Commit

Permalink
修复:无效Token响应码不一致的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
feiyuchuixue committed Feb 7, 2025
1 parent 2422ff5 commit 1cbcc4f
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 11 deletions.
7 changes: 1 addition & 6 deletions src/api/helper/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,7 @@ export const CODE_SUCCESS: string = '0000';
* 无效Token
* @type {string}
*/
export const CODE_TOKEN_FAIL: string = 'C2001';
/**
* 无效用户
* @type {string}
*/
export const CODE_USER_FAIL: string = 'C2002';
export const CODE_TOKEN_FAIL: string = 'C105';

/**
* @description: 校验网络请求状态码
Expand Down
4 changes: 2 additions & 2 deletions src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { AxiosInstance, AxiosRequestConfig, InternalAxiosRequestConfig } fr

import router from '@/router';
import { LOGIN_URL } from '@/config';
import { checkStatus, CODE_SUCCESS, CODE_TOKEN_FAIL, CODE_USER_FAIL } from '@/api/helper';
import { checkStatus, CODE_SUCCESS, CODE_TOKEN_FAIL } from '@/api/helper';
import type { IResultData } from '@/api/interface';
import { useUserStore } from '@/stores/modules/user';
import { useAuthStore } from '@/stores/modules/auth';
Expand Down Expand Up @@ -68,7 +68,7 @@ class RequestHttp {

//tryHideFullScreenLoading()
// 登陆失效
if (data.code === CODE_TOKEN_FAIL || data.code === CODE_USER_FAIL) {
if (data.code === CODE_TOKEN_FAIL) {
userStore.clear();
authStore.clear();
// 关闭socket
Expand Down
6 changes: 3 additions & 3 deletions src/stores/modules/socket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ export const useSocketStore = defineStore('socket', () => {
type: 'warning',
callback: () => {
// 2.重定向到登陆页
router.replace(LOGIN_URL);
router.replace(LOGIN_URL).then(r => r);
}
});
break;
case UPGRADE_CHANNEL:
close();
/* close();
// 1.清除 Token
userStore.clear();
authStore.clear();
Expand All @@ -73,7 +73,7 @@ export const useSocketStore = defineStore('socket', () => {
// 2.重定向到登陆页
router.replace(LOGIN_URL);
}
});
});*/
break;

default:
Expand Down

0 comments on commit 1cbcc4f

Please sign in to comment.