fix:登录判断优化

This commit is contained in:
Gsh
2025-06-30 16:02:39 +08:00
parent 3d22a2ef65
commit 6aefcdbed8
6 changed files with 31 additions and 11 deletions

View File

@@ -77,7 +77,7 @@ function jwtPlugin(): HookFetchPlugin<BaseResponse> {
beforeRequest: async (config) => {
config.headers = new Headers(config.headers);
if (userStore.refreshToken) {
config.headers.set('refresh_token', `Bearer ${userStore.refreshToken}`);
config.headers.set('refresh_token', `${userStore.refreshToken}`);
}
if (userStore.token) {
config.headers.set('authorization', `Bearer ${userStore.token}`);
@@ -85,9 +85,13 @@ function jwtPlugin(): HookFetchPlugin<BaseResponse> {
return config;
},
afterResponse: async (response: any) => {
console.log('response---', response);
console.log('response.headers---', response.headers);
console.log('response.response.headers---', response.response.headers);
if (response.response.headers?.refresh_token) {
console.log('返回有token---response.response.headers-:', response.response.headers);
userStore.setToken(response.response.headers?.access_token, response.response.headers?.refresh_token);
}
@@ -108,6 +112,14 @@ function jwtPlugin(): HookFetchPlugin<BaseResponse> {
ElMessage.error(response.result?.msg);
return Promise.reject(response);
},
onError: async (error) => {
console.log('error---', error);
console.log('response---', error.response);
if (error.status === 403) {
// 弹窗提示
ElMessage.error('业务错误,请稍后再试');
}
},
};
}