UNPKG

jz-tool-lib

Version:

项目常用公共方法集合

41 lines (40 loc) 2.09 kB
import { AxiosInstance, CreateAxiosDefaults, InternalAxiosRequestConfig, AxiosResponse, AxiosError } from 'axios'; type ObjectType = Record<string, unknown> | undefined; type RequestMethod = 'get' | 'delete' | 'post' | 'put'; type RequestParams = ObjectType; type RequestConfig = ObjectType; type Identifier = { url: string; params: ObjectType; }; interface ParamsConfig extends CreateAxiosDefaults { requestInterceptorsSuccess?: RequestInterceptors; requestInterceptorsCatch?: InterceptorsCatch; responseInterceptorsSuccess?: ResponseInterceptors; responseInterceptorsCatch?: InterceptorsCatch; } type RequestInterceptors = ((config: InternalAxiosRequestConfig) => Promise<InternalAxiosRequestConfig>) | undefined; type ResponseInterceptors = ((config: AxiosResponse) => Promise<AxiosResponse>) | undefined; type InterceptorsCatch = ((err: AxiosError) => Promise<AxiosError>) | undefined; export declare class Http { http: AxiosInstance; abortControllers: Map<string, AbortController>; requestInterceptors: number | null; responseInterceptors: number | null; requestInterceptorsSuccess: RequestInterceptors; requestInterceptorsCatch: InterceptorsCatch; responseInterceptorsSuccess: ResponseInterceptors; responseInterceptorsCatch: InterceptorsCatch; constructor(params: ParamsConfig); setupInterceptors(): void; get(url: string, params?: RequestParams, config?: RequestConfig): Promise<unknown>; delete(url: string, params?: RequestParams, config?: RequestConfig): Promise<unknown>; post(url: string, data?: RequestParams, config?: RequestConfig): Promise<unknown>; put(url: string, data?: RequestParams, config?: RequestConfig): Promise<unknown>; request(url: string, method: RequestMethod, data?: RequestParams, params?: RequestParams, config?: RequestConfig): Promise<unknown>; cancelRequest(identifier: Identifier[] | Identifier): void; getIdentifier(config: Identifier): string; requestInterceptorsEject(): Promise<unknown>; responseInterceptorsEject(): Promise<unknown>; } export {};