mirror of
https://github.com/yangjian102621/geekai.git
synced 2025-11-09 02:33:42 +08:00
feat(ui): 新增请求方法及表格
This commit is contained in:
28
gpt-vue/packages/request/index.ts
Normal file
28
gpt-vue/packages/request/index.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import axios from "axios";
|
||||
import tokenHandler from "./token";
|
||||
|
||||
const { _tokenData, refreshToken, setCurRequest } = tokenHandler();
|
||||
|
||||
const createInstance = (baseURL: string = (import.meta as any).env.VITE_PROXY_BASE_URL) => {
|
||||
|
||||
const instance = axios.create({
|
||||
baseURL,
|
||||
timeout: 10000,
|
||||
withCredentials: true,
|
||||
});
|
||||
|
||||
instance.interceptors.request.use((config) => {
|
||||
if (config.url !== _tokenData.get("lastRequest")) {
|
||||
refreshToken();
|
||||
}
|
||||
if (config.method === "post") {
|
||||
setCurRequest(config.url);
|
||||
config.headers["request-id"] = _tokenData.get("__token");
|
||||
}
|
||||
return config;
|
||||
});
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
export default createInstance;
|
||||
Reference in New Issue
Block a user