feat: update

This commit is contained in:
landaiqing
2024-05-29 21:33:58 +08:00
parent cb9c827220
commit 4ce065214a
11 changed files with 173 additions and 144 deletions

View File

@@ -2,6 +2,7 @@
import axios, { AxiosInstance, AxiosRequestConfig } from "axios";
import { message } from "antd";
import { getStorageFromKey } from "@/utils/localStorage/config.ts";
class Request {
private instance: AxiosInstance | undefined;
@@ -11,6 +12,11 @@ class Request {
// 全局请求拦截
this.instance.interceptors.request.use(
(config) => {
const token: string | null = getStorageFromKey("token");
if (token) {
config.headers.Authorization = `schisandra ${token}`;
}
// if (config.method == "post") {
// config.data = EncryptData(JSON.stringify(config.data));
// }

View File

@@ -1,17 +1,10 @@
/** @format */
import Request from "./request";
import localforage from "localforage";
async function getToken() {
return await localforage.getItem("token");
}
const token = await getToken();
const web: Request = new Request({
baseURL: import.meta.env.VITE_APP_BASE_API,
headers: {
token: import.meta.env.VITE_APP_TOKEN_KEY + " " + token,
},
timeout: 5000,
});
export default web;