fix: 系统公告弹窗前端
This commit is contained in:
@@ -77,10 +77,11 @@ function jwtPlugin(): {
|
||||
afterResponse: (response: any) => Promise<any>;
|
||||
beforeStream: (body: any, config: any) => Promise<void>;
|
||||
} {
|
||||
const userStore = useUserStore();
|
||||
return {
|
||||
name: 'jwt',
|
||||
beforeRequest: async (config) => {
|
||||
// 延迟获取 store,确保 Pinia 已经初始化
|
||||
const userStore = useUserStore();
|
||||
config.headers = new Headers(config.headers);
|
||||
if (userStore.refreshToken) {
|
||||
config.headers.set('refresh_token', `${userStore.refreshToken}`);
|
||||
@@ -94,6 +95,8 @@ function jwtPlugin(): {
|
||||
|
||||
// 响应后处理
|
||||
afterResponse: async (response: any) => {
|
||||
// 延迟获取 store,确保 Pinia 已经初始化
|
||||
const userStore = useUserStore();
|
||||
if (response.response.headers.get('access_token')) {
|
||||
userStore.setToken(response.response.headers.get('access_token'), response.response.headers.get('refresh_token'));
|
||||
}
|
||||
@@ -118,6 +121,8 @@ function jwtPlugin(): {
|
||||
},
|
||||
|
||||
onError: async (error) => {
|
||||
// 延迟获取 store,确保 Pinia 已经初始化
|
||||
const userStore = useUserStore();
|
||||
if (error.status === 403) {
|
||||
const data = await (error.response.json());
|
||||
// 弹窗提示
|
||||
|
||||
Reference in New Issue
Block a user