types: 优src/utils/http文件中postget工具函数的类型

This commit is contained in:
xiaoxian521 2024-04-16 14:01:36 +08:00
parent cd42dbf188
commit abd042afe8

View File

@ -35,16 +35,16 @@ class PureHttp {
this.httpInterceptorsResponse();
}
/** token过期后暂存待执行的请求 */
/** `token`过期后,暂存待执行的请求 */
private static requests = [];
/** 防止重复刷新token */
/** 防止重复刷新`token` */
private static isRefreshing = false;
/** 初始化配置对象 */
private static initConfig: PureHttpRequestConfig = {};
/** 保存当前Axios实例对象 */
/** 保存当前`Axios`实例对象 */
private static axiosInstance: AxiosInstance = Axios.create(defaultConfig);
/** 重连原始请求 */
@ -72,7 +72,7 @@ class PureHttp {
PureHttp.initConfig.beforeRequestCallback(config);
return config;
}
/** 请求白名单,放置一些不需要token的接口通过设置请求白名单防止token过期后再请求造成的死循环问题 */
/** 请求白名单,放置一些不需要`token`的接口(通过设置请求白名单,防止`token`过期后再请求造成的死循环问题) */
const whiteList = ["/refresh-token", "/login"];
return whiteList.some(url => config.url.endsWith(url))
? config
@ -172,22 +172,22 @@ class PureHttp {
});
}
/** 单独抽离的post工具函数 */
/** 单独抽离的`post`工具函数 */
public post<T, P>(
url: string,
params?: AxiosRequestConfig<T>,
params?: AxiosRequestConfig<P>,
config?: PureHttpRequestConfig
): Promise<P> {
return this.request<P>("post", url, params, config);
): Promise<T> {
return this.request<T>("post", url, params, config);
}
/** 单独抽离的get工具函数 */
/** 单独抽离的`get`工具函数 */
public get<T, P>(
url: string,
params?: AxiosRequestConfig<T>,
params?: AxiosRequestConfig<P>,
config?: PureHttpRequestConfig
): Promise<P> {
return this.request<P>("get", url, params, config);
): Promise<T> {
return this.request<T>("get", url, params, config);
}
}