fix:双token更新
This commit is contained in:
@@ -6,6 +6,7 @@ import type { BubbleProps } from 'vue-element-plus-x/types/Bubble';
|
||||
import type { BubbleListInstance } from 'vue-element-plus-x/types/BubbleList';
|
||||
import type { FilesCardProps } from 'vue-element-plus-x/types/FilesCard';
|
||||
import type { ThinkingStatus } from 'vue-element-plus-x/types/Thinking';
|
||||
import { ElMessage } from 'element-plus';
|
||||
import { useHookFetch } from 'hook-fetch/vue';
|
||||
import { useRoute } from 'vue-router';
|
||||
import { send } from '@/api';
|
||||
@@ -148,7 +149,9 @@ function handleDataChunk(chunk: AnyObject) {
|
||||
|
||||
// 封装错误处理逻辑
|
||||
function handleError(err: any) {
|
||||
console.log('Fetch error:-------', err);
|
||||
if (err.status === 403) {
|
||||
ElMessage.error('业务错误,请稍后再试');
|
||||
}
|
||||
console.error('Fetch error:', err);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { HookFetchPlugin } from 'hook-fetch';
|
||||
import type { RequestConfig } from 'hook-fetch';
|
||||
import FingerprintJS from '@fingerprintjs/fingerprintjs'; // 新增指纹库
|
||||
import { ElMessage } from 'element-plus';
|
||||
import hookFetch from 'hook-fetch';
|
||||
@@ -70,7 +70,13 @@ export const request = hookFetch.create<BaseResponse>({
|
||||
});
|
||||
|
||||
// JWT插件(保持原有逻辑)
|
||||
function jwtPlugin(): HookFetchPlugin<BaseResponse> {
|
||||
function jwtPlugin(): {
|
||||
onError: (error: any) => Promise<void>;
|
||||
name: string;
|
||||
beforeRequest: (config: any) => Promise<RequestConfig<unknown, unknown, unknown>>;
|
||||
afterResponse: (response: any) => Promise<any>;
|
||||
beforeStream: (body: any, config: any) => Promise<void>;
|
||||
} {
|
||||
const userStore = useUserStore();
|
||||
return {
|
||||
name: 'jwt',
|
||||
@@ -86,13 +92,10 @@ 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);
|
||||
if (response.response.headers.get('access_token')) {
|
||||
userStore.setToken(response.response.headers.get('access_token'), response.response.headers.get('refresh_token'));
|
||||
}
|
||||
|
||||
if (response.result?.code === 200)
|
||||
@@ -112,9 +115,8 @@ 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('业务错误,请稍后再试');
|
||||
|
||||
Reference in New Issue
Block a user