|
@@ -41,12 +41,6 @@ class EnclosureHttp {
|
|
// 记录当前这一次cancelToken的key
|
|
// 记录当前这一次cancelToken的key
|
|
private currentCancelTokenKey = "";
|
|
private currentCancelTokenKey = "";
|
|
|
|
|
|
- private beforeRequestCallback: EnclosureHttpRequestConfig["beforeRequestCallback"] =
|
|
|
|
- undefined;
|
|
|
|
-
|
|
|
|
- private beforeResponseCallback: EnclosureHttpRequestConfig["beforeResponseCallback"] =
|
|
|
|
- undefined;
|
|
|
|
-
|
|
|
|
public get cancelTokenList(): Array<cancelTokenType> {
|
|
public get cancelTokenList(): Array<cancelTokenType> {
|
|
return this.sourceTokenList;
|
|
return this.sourceTokenList;
|
|
}
|
|
}
|
|
@@ -126,9 +120,8 @@ class EnclosureHttp {
|
|
this.cancelRepeatRequest();
|
|
this.cancelRepeatRequest();
|
|
this.currentCancelTokenKey = cancelKey;
|
|
this.currentCancelTokenKey = cancelKey;
|
|
// 优先判断post/get等方法是否传入回掉,否则执行初始化设置等回掉
|
|
// 优先判断post/get等方法是否传入回掉,否则执行初始化设置等回掉
|
|
- if (typeof this.beforeRequestCallback === "function") {
|
|
|
|
- this.beforeRequestCallback($config);
|
|
|
|
- this.beforeRequestCallback = undefined;
|
|
|
|
|
|
+ if (typeof config.beforeRequestCallback === "function") {
|
|
|
|
+ config.beforeRequestCallback($config);
|
|
return $config;
|
|
return $config;
|
|
}
|
|
}
|
|
if (EnclosureHttp.initConfig.beforeRequestCallback) {
|
|
if (EnclosureHttp.initConfig.beforeRequestCallback) {
|
|
@@ -159,20 +152,21 @@ class EnclosureHttp {
|
|
const instance = EnclosureHttp.axiosInstance;
|
|
const instance = EnclosureHttp.axiosInstance;
|
|
instance.interceptors.response.use(
|
|
instance.interceptors.response.use(
|
|
(response: EnclosureHttpResoponse) => {
|
|
(response: EnclosureHttpResoponse) => {
|
|
|
|
+ const $config = response.config;
|
|
// 请求每次成功一次就删除当前canceltoken标记
|
|
// 请求每次成功一次就删除当前canceltoken标记
|
|
- const cancelKey = EnclosureHttp.genUniqueKey(response.config);
|
|
|
|
|
|
+ const cancelKey = EnclosureHttp.genUniqueKey($config);
|
|
this.deleteCancelTokenByCancelKey(cancelKey);
|
|
this.deleteCancelTokenByCancelKey(cancelKey);
|
|
|
|
+
|
|
|
|
+ NProgress.done();
|
|
// 优先判断post/get等方法是否传入回掉,否则执行初始化设置等回掉
|
|
// 优先判断post/get等方法是否传入回掉,否则执行初始化设置等回掉
|
|
- if (typeof this.beforeResponseCallback === "function") {
|
|
|
|
- this.beforeResponseCallback(response);
|
|
|
|
- this.beforeResponseCallback = undefined;
|
|
|
|
|
|
+ if (typeof $config.beforeResponseCallback === "function") {
|
|
|
|
+ $config.beforeResponseCallback(response);
|
|
return response.data;
|
|
return response.data;
|
|
}
|
|
}
|
|
if (EnclosureHttp.initConfig.beforeResponseCallback) {
|
|
if (EnclosureHttp.initConfig.beforeResponseCallback) {
|
|
EnclosureHttp.initConfig.beforeResponseCallback(response);
|
|
EnclosureHttp.initConfig.beforeResponseCallback(response);
|
|
return response.data;
|
|
return response.data;
|
|
}
|
|
}
|
|
- NProgress.done();
|
|
|
|
return response.data;
|
|
return response.data;
|
|
},
|
|
},
|
|
(error: EnclosureHttpError) => {
|
|
(error: EnclosureHttpError) => {
|
|
@@ -210,12 +204,6 @@ class EnclosureHttp {
|
|
...axiosConfig
|
|
...axiosConfig
|
|
} as EnclosureHttpRequestConfig);
|
|
} as EnclosureHttpRequestConfig);
|
|
// 单独处理自定义请求/响应回掉
|
|
// 单独处理自定义请求/响应回掉
|
|
- if (axiosConfig?.beforeRequestCallback) {
|
|
|
|
- this.beforeRequestCallback = axiosConfig.beforeRequestCallback;
|
|
|
|
- }
|
|
|
|
- if (axiosConfig?.beforeResponseCallback) {
|
|
|
|
- this.beforeResponseCallback = axiosConfig.beforeResponseCallback;
|
|
|
|
- }
|
|
|
|
return new Promise((resolve, reject) => {
|
|
return new Promise((resolve, reject) => {
|
|
EnclosureHttp.axiosInstance
|
|
EnclosureHttp.axiosInstance
|
|
.request(config)
|
|
.request(config)
|