/** * Data processing class, can be configured according to the project */ import type { RequestOptions, Result } from '../../types/axios'; import type { AxiosRequestConfig, AxiosResponse } from 'axios'; export abstract class AxiosTransform { /** * @description: 请求之前处理配置 */ beforeRequestHook?: (config: AxiosRequestConfig, options: RequestOptions) => AxiosRequestConfig; /** * @description: 处理请求数据。如果数据不是预期格式,可直接抛出错 */ transformRequestHook?: (res: AxiosResponse, options: RequestOptions) => any; /** * @description: 请求之前的拦截器 */ // eslint-disable-next-line no-use-before-define requestInterceptors?: (config: AxiosRequestConfig, options: CreateAxiosOptions) => AxiosRequestConfig; /** * @description: 请求之后的拦截器 */ responseInterceptors?: (res: AxiosResponse) => AxiosResponse; /** * @description: 请求之后的拦截器错误处理 */ responseInterceptorsCatch?: (error: Error) => void; } export interface CreateAxiosOptions extends AxiosRequestConfig { authenticationScheme?: string; transform?: AxiosTransform; requestOptions?: RequestOptions; useAppStore?: any; showErrorMsg?: (options: any) => void; checkStatus?: ( status: number, msg: string, msgDetail: string | Record, code?: number, noErrorTip?: boolean ) => void; }