mirror of
https://gitee.com/durcframework/SOP.git
synced 2025-08-12 07:02:14 +08:00
5.0
This commit is contained in:
@@ -13,19 +13,23 @@ import { stringify } from "qs";
|
||||
import NProgress from "../progress";
|
||||
import { getToken, formatToken } from "@/utils/auth";
|
||||
import { useUserStoreHook } from "@/store/modules/user";
|
||||
|
||||
const PREFIX_MOCK: string = "mock";
|
||||
import { ElMessage } from "element-plus";
|
||||
|
||||
export const baseUrl = (url: string) => {
|
||||
if (url.startsWith("/")) {
|
||||
url = url.substring(1);
|
||||
}
|
||||
if (url.startsWith(PREFIX_MOCK)) {
|
||||
return url.substring(PREFIX_MOCK.length);
|
||||
}
|
||||
return `/api/${url}`;
|
||||
};
|
||||
|
||||
export const createUrl = (data: object) => {
|
||||
const ret = {};
|
||||
for (const dataKey in data) {
|
||||
ret[dataKey] = baseUrl(data[dataKey]);
|
||||
}
|
||||
return ret;
|
||||
};
|
||||
|
||||
// 相关配置请参考:www.axios-js.com/zh-cn/docs/#axios-request-config-1
|
||||
const defaultConfig: AxiosRequestConfig = {
|
||||
// 请求超时时间
|
||||
@@ -45,6 +49,13 @@ class PureHttp {
|
||||
constructor() {
|
||||
this.httpInterceptorsRequest();
|
||||
this.httpInterceptorsResponse();
|
||||
PureHttp.initConfig.beforeResponseCallback = response => {
|
||||
const resp = response.data || {};
|
||||
if (resp.code && resp.code !== "0") {
|
||||
console.log(resp);
|
||||
ElMessage.error(resp.msg || "后台出错,请查看日志");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/** `token`过期后,暂存待执行的请求 */
|
||||
@@ -166,7 +177,7 @@ class PureHttp {
|
||||
): Promise<T> {
|
||||
const config = {
|
||||
method,
|
||||
url: baseUrl(url),
|
||||
url: url,
|
||||
...param,
|
||||
...axiosConfig
|
||||
} as PureHttpRequestConfig;
|
||||
|
Reference in New Issue
Block a user