import type { AxiosRequestConfig, AxiosResponse, CreateAxiosDefaults, InternalAxiosRequestConfig, } from 'axios'; type ExtendOptions = { /** 响应数据的返回方式。 * raw: 原始的AxiosResponse,包括headers、status等,不做是否成功请求的检查。 * body: 返回响应数据的BODY部分(只会根据status检查请求是否成功,忽略对code的判断,这种情况下应由调用方检查请求是否成功)。 * data: 解构响应的BODY数据,只返回其中的data节点数据(会检查status和code是否为成功状态)。 */ responseReturn?: 'body' | 'data' | 'raw'; }; type RequestClientConfig = AxiosRequestConfig & ExtendOptions; type RequestResponse = AxiosResponse & { config: RequestClientConfig; }; type RequestContentType = | 'application/json;charset=utf-8' | 'application/octet-stream;charset=utf-8' | 'application/x-www-form-urlencoded;charset=utf-8' | 'multipart/form-data;charset=utf-8'; type RequestClientOptions = CreateAxiosDefaults & ExtendOptions; interface RequestInterceptorConfig { fulfilled?: ( config: ExtendOptions & InternalAxiosRequestConfig, ) => | (ExtendOptions & InternalAxiosRequestConfig) | Promise>; rejected?: (error: any) => any; } interface ResponseInterceptorConfig { fulfilled?: ( response: RequestResponse, ) => Promise | RequestResponse; rejected?: (error: any) => any; } type MakeErrorMessageFn = (message: string, error: any) => void; interface HttpResponse { /** * 0 表示成功 其他表示失败 * 0 means success, others means fail */ code: number; data: T; message: string; } export type { HttpResponse, MakeErrorMessageFn, RequestClientConfig, RequestClientOptions, RequestContentType, RequestInterceptorConfig, RequestResponse, ResponseInterceptorConfig, };