import * as axios from 'axios'; import { AxiosError, AxiosRequestConfig, CancelToken } from 'axios'; export { AxiosError, AxiosPromise, AxiosRequestConfig, AxiosResponse } from 'axios'; interface ResType { code: number; data: T; msg: string; err?: string | null | AxiosError; url?: string; total?: number; } interface RetryAdapterOption { times?: number; delay?: number; } type ICacheLike = { get(key: string): T | undefined; set(key: string, value: T): void; } & ({ del(key: string): void; } | { delete(key: string): void; }); interface Http { get: (url: string, config?: AxiosRequestConfig) => Promise>; post: (url: string, config?: AxiosRequestConfig) => Promise>; put(url: string, config?: AxiosRequestConfig): Promise>; patch(url: string, config?: AxiosRequestConfig): Promise>; delete(url: string, config?: AxiosRequestConfig): Promise>; upload(url: string, config: AxiosRequestConfig): Promise>; } /** * 扩展 axios config 类型声明 */ declare module 'axios' { interface AxiosRequestConfig { retry?: boolean | { times?: number; delay?: number; }; useCache?: boolean | { expire?: number; max?: number; } | ICacheLike; payload?: any; id?: string | number; isCancel?: boolean | 'recover'; } } type CancelFn = (message?: string) => void; declare const useCancelTokenStore: () => { cancelApiMap: Map; key: string; getRequestKey: (config?: AxiosRequestConfig) => any; isOwner: (config?: AxiosRequestConfig) => boolean; useCancelToken: (config?: AxiosRequestConfig) => { cancelToken: CancelToken; }; cancel: (cancelOption?: { key?: string; msg?: string; }) => void; cancelAll: () => void; deleteResponseApi: (targetKey?: string) => void; }; declare function buildSortedURL(url: string, params?: any, options?: any): any; declare const isNetworkError: (error: any) => any; declare const instance: axios.AxiosInstance; declare const http: Http; export { Http, ICacheLike, ResType, RetryAdapterOption, buildSortedURL, http as default, instance, isNetworkError, useCancelTokenStore };