import type { AxiosInstance, AxiosRequestConfig } from 'axios'; import type { CustomAjaxMethods } from './compatibleMethods'; import type { RequestCreator } from './methods'; export type AnyObj = Record; export interface AjaxOption extends AxiosRequestConfig { /** 是否发送FormData数据,仅用于post类请求,为true则使用qs.stringify序列化数据 */ sendFormData?: boolean; /** 当前请求的取消函数名称,使用ajax.canceller[cancelKey]()的方式调用 */ cancelKey?: string; /** 如果有值,则请求直接resolve这个值,阻断请求发送。用于开发mock数据 */ mock?: any; /** 如果请求的URL和method与一个pending状态的请求相同,是否要终止前面的请求 */ cancelLastSameUrl?: boolean; /** 防重设置,在此时间内触发的相同请求会复用上一个处于pending状态的请求,单位为ms。请求返回后,该参数自动失效。 */ reUseDuration?: number; } export type RequestMethods = 'get' | 'post' | 'patch' | 'put' | 'delete' | 'head'; export type ProxyedAttrs = keyof Omit; export type CancellerType = { [K: string]: () => void | undefined; }; export interface AjaxInstance = any, DataShape extends object = any> extends Pick { /** @deprecated 即将废弃,请使用ajax.get方法替换 */ query: CustomAjaxMethods; /** @deprecated 即将废弃,请使用ajax.post方法替换 */ create: CustomAjaxMethods; /** @deprecated 即将废弃,请使用ajax.delete方法替换 */ deletes: CustomAjaxMethods; /** @deprecated 即将废弃,请使用ajax.put方法替换 */ putWay: CustomAjaxMethods; /** @deprecated 即将废弃,请使用ajax.patch方法替换 */ patchWay: CustomAjaxMethods; head: RequestCreator; get: RequestCreator; post: RequestCreator; put: RequestCreator; delete: RequestCreator; patch: RequestCreator; extend: (obj: object) => void; canceller: CancellerType; $baseUrl: string; $options: AjaxOption; $engine: AxiosInstance; } export type AxiosMethods = 'GET' | 'POST' | 'DELETE' | 'PUT' | 'PATCH' | 'HEAD';