FEAT => 本次更新项目为:更新 index.html 和 manifest.json 中的資源引用,新增 token2 支持於請求模組,並調整 ChatWindow 組件的樣式以改善顯示效果。
This commit is contained in:
@@ -6,7 +6,7 @@ import axios, {
|
||||
} from "axios";
|
||||
import { Toast } from "antd-mobile";
|
||||
import { useUserStore } from "@/store/module/user";
|
||||
const { token } = useUserStore.getState();
|
||||
const { token, token2 } = useUserStore.getState();
|
||||
const DEFAULT_DEBOUNCE_GAP = 1000;
|
||||
const debounceMap = new Map<string, number>();
|
||||
|
||||
@@ -19,7 +19,13 @@ const instance: AxiosInstance = axios.create({
|
||||
});
|
||||
|
||||
instance.interceptors.request.use((config: any) => {
|
||||
if (token) {
|
||||
// 从配置中获取是否使用token2
|
||||
const useToken2 = config.useToken2;
|
||||
|
||||
if (useToken2 && token2) {
|
||||
config.headers = config.headers || {};
|
||||
config.headers["Authorization"] = `Bearer ${token2}`;
|
||||
} else if (token) {
|
||||
config.headers = config.headers || {};
|
||||
config.headers["Authorization"] = `Bearer ${token}`;
|
||||
}
|
||||
@@ -56,6 +62,7 @@ export function request(
|
||||
method: Method = "GET",
|
||||
config?: AxiosRequestConfig,
|
||||
debounceGap?: number,
|
||||
isToken2?: boolean,
|
||||
): Promise<any> {
|
||||
const gap =
|
||||
typeof debounceGap === "number" ? debounceGap : DEFAULT_DEBOUNCE_GAP;
|
||||
@@ -72,7 +79,10 @@ export function request(
|
||||
url,
|
||||
method,
|
||||
...config,
|
||||
};
|
||||
} as any;
|
||||
|
||||
// 添加自定义属性
|
||||
(axiosConfig as any).useToken2 = isToken2;
|
||||
|
||||
// 如果是FormData,不设置Content-Type,让浏览器自动设置
|
||||
if (data instanceof FormData) {
|
||||
|
||||
Reference in New Issue
Block a user