feat: update
This commit is contained in:
@@ -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));
|
||||
// }
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user