refactor: reorganize files

This commit is contained in:
yangsy
2025-11-22 01:46:16 +08:00
parent 00a961c346
commit a486f76aaf
148 changed files with 1440 additions and 1170 deletions

View File

@@ -0,0 +1,36 @@
import router from '@/router';
import { useUserStore } from '@/stores';
import { getAppEnvConfig, RequestClient } from '@/utils';
import type { AxiosError } from 'axios';
export const userClient = new RequestClient({
requestInterceptor: (config) => {
const userStore = useUserStore();
const { lampAuthorization, lampClientId, lampClientSecret } = getAppEnvConfig();
const newAuthorization = window.btoa(`${lampClientId}:${lampClientSecret}`);
const authorization = lampAuthorization.trim() !== '' ? lampAuthorization : newAuthorization;
config.headers.set('accept-language', 'zh-CN,zh;q=0.9');
config.headers.set('accept', 'application/json, text/plain, */*');
config.headers.set('Applicationid', '');
config.headers.set('Tenantid', '1');
config.headers.set('Authorization', authorization);
config.headers.set('token', userStore.userLoginResult?.token ?? '');
return config;
},
responseInterceptor: (response) => {
return response;
},
responseErrorInterceptor: (error) => {
const err = error as AxiosError;
if (err.response?.status === 401) {
window.$message.error('登录超时,请重新登录');
const userStore = useUserStore();
userStore.resetStore();
router.push('/login');
}
if (err.response?.status === 404) {
router.push('/404');
}
return Promise.reject(error);
},
});