feat: 只保留前端部分

This commit is contained in:
osiris
2024-05-13 16:23:33 +08:00
parent 68951056b1
commit 9a55817794
13 changed files with 22 additions and 865 deletions
+2 -33
View File
@@ -1,44 +1,13 @@
import axios from "axios";
import { ElMessage } from "element-plus";
import { useUserStore } from '@/store/modules/user'
//store
import pinia from '../store' //这里需要引入pinia
const userStore = useUserStore(pinia)
//创建axios实例
let request = axios.create({
baseURL: import.meta.env.VITE_IS_MOCK == 'true' ? import.meta.env.VITE_APP_BASE_API : import.meta.env.VITE_SERVE + import.meta.env.VITE_APP_BASE_API,
timeout: 5000
})
//创建一个存储CancelToken源的映射,用于管理请求和取消操作
const cancelSources = new Map();
//mock环境下无法使用的接口
const mockBanUrl: string[] = [
'/login',
'/user/info',
'/get/tool/collects',
'/send/forget/password/code',
'/send/register/code',
'/forget/password',
'/register',
'/logout'
];
});
//请求拦截器
request.interceptors.request.use(config => {
if (import.meta.env.VITE_IS_MOCK == 'true' && config.url != undefined && mockBanUrl.includes(config.url)) {
//mock环境不能使用登录后相关功能
const source = axios.CancelToken.source()
//将source与请求的url或某种唯一标识符关联起来
cancelSources.set(config.url, source);
config.cancelToken = source.token;
//取消
source.cancel('Request canceled by the user.');
} else {
//获取token
if (userStore.token) {
// config.headers.token = userStore.token
config.headers.Authorization = 'Bearer ' + userStore.token
}
}
return config;
});
//响应拦截器