index on main: f96885b
perf: 同步代码
This commit is contained in:
@@ -41,12 +41,6 @@ class EnclosureHttp {
|
||||
// 记录当前这一次cancelToken的key
|
||||
private currentCancelTokenKey = "";
|
||||
|
||||
private beforeRequestCallback: EnclosureHttpRequestConfig["beforeRequestCallback"] =
|
||||
undefined;
|
||||
|
||||
private beforeResponseCallback: EnclosureHttpRequestConfig["beforeResponseCallback"] =
|
||||
undefined;
|
||||
|
||||
public get cancelTokenList(): Array<cancelTokenType> {
|
||||
return this.sourceTokenList;
|
||||
}
|
||||
@@ -126,9 +120,8 @@ class EnclosureHttp {
|
||||
this.cancelRepeatRequest();
|
||||
this.currentCancelTokenKey = cancelKey;
|
||||
// 优先判断post/get等方法是否传入回掉,否则执行初始化设置等回掉
|
||||
if (typeof this.beforeRequestCallback === "function") {
|
||||
this.beforeRequestCallback($config);
|
||||
this.beforeRequestCallback = undefined;
|
||||
if (typeof config.beforeRequestCallback === "function") {
|
||||
config.beforeRequestCallback($config);
|
||||
return $config;
|
||||
}
|
||||
if (EnclosureHttp.initConfig.beforeRequestCallback) {
|
||||
@@ -159,20 +152,21 @@ class EnclosureHttp {
|
||||
const instance = EnclosureHttp.axiosInstance;
|
||||
instance.interceptors.response.use(
|
||||
(response: EnclosureHttpResoponse) => {
|
||||
const $config = response.config;
|
||||
// 请求每次成功一次就删除当前canceltoken标记
|
||||
const cancelKey = EnclosureHttp.genUniqueKey(response.config);
|
||||
const cancelKey = EnclosureHttp.genUniqueKey($config);
|
||||
this.deleteCancelTokenByCancelKey(cancelKey);
|
||||
|
||||
NProgress.done();
|
||||
// 优先判断post/get等方法是否传入回掉,否则执行初始化设置等回掉
|
||||
if (typeof this.beforeResponseCallback === "function") {
|
||||
this.beforeResponseCallback(response);
|
||||
this.beforeResponseCallback = undefined;
|
||||
if (typeof $config.beforeResponseCallback === "function") {
|
||||
$config.beforeResponseCallback(response);
|
||||
return response.data;
|
||||
}
|
||||
if (EnclosureHttp.initConfig.beforeResponseCallback) {
|
||||
EnclosureHttp.initConfig.beforeResponseCallback(response);
|
||||
return response.data;
|
||||
}
|
||||
NProgress.done();
|
||||
return response.data;
|
||||
},
|
||||
(error: EnclosureHttpError) => {
|
||||
@@ -210,12 +204,6 @@ class EnclosureHttp {
|
||||
...axiosConfig
|
||||
} as EnclosureHttpRequestConfig);
|
||||
// 单独处理自定义请求/响应回掉
|
||||
if (axiosConfig?.beforeRequestCallback) {
|
||||
this.beforeRequestCallback = axiosConfig.beforeRequestCallback;
|
||||
}
|
||||
if (axiosConfig?.beforeResponseCallback) {
|
||||
this.beforeResponseCallback = axiosConfig.beforeResponseCallback;
|
||||
}
|
||||
return new Promise((resolve, reject) => {
|
||||
EnclosureHttp.axiosInstance
|
||||
.request(config)
|
||||
|
@@ -23,14 +23,23 @@ export const injectResponsiveStorage = (app: App, config: ServerConfigs) => {
|
||||
locale: {
|
||||
type: Object,
|
||||
default: Storage.getData(undefined, "locale") ?? {
|
||||
locale: config.Locale
|
||||
locale: config.Locale ?? "zh"
|
||||
}
|
||||
},
|
||||
// layout模式以及主题
|
||||
layout: {
|
||||
type: Object,
|
||||
default: Storage.getData(undefined, "layout") ?? {
|
||||
layout: config.Layout
|
||||
layout: config.Layout ?? "vertical",
|
||||
theme: config.Theme ?? "default"
|
||||
}
|
||||
},
|
||||
sets: {
|
||||
type: Object,
|
||||
default: Storage.getData(undefined, "sets") ?? {
|
||||
grey: config.Grey ?? false,
|
||||
weak: config.Weak ?? false,
|
||||
hideTabs: config.HideTabs ?? false
|
||||
}
|
||||
}
|
||||
});
|
||||
|
Reference in New Issue
Block a user