/* * @Description: * @Author: Format-qi 283810417@qq.com * @Date: 2022-06-23 13:31:39 * @LastEditors: Format-qi jsq15517589670@163.com * @LastEditTime: 2022-12-14 18:11:07 */ /** * 数据处理类,可根据工程进行配置 */ import type { AxiosRequestConfig, AxiosResponse } from 'axios'; import type { RequestOptions, Result } from '/#/axios'; export interface CreateAxiosOptions extends AxiosRequestConfig { tenantId?: string; //header TENANT-ID 必传 authenticationScheme?: string; authToken?: string; transform?: AxiosTransform; // 会把 return 的 headers 加进请求头 setHeaders?: () => any; requestOptions?: RequestOptions; } export interface AxiosTransform { /** * @description: 请求前配置拦截器 */ beforeRequestHook?: (config: AxiosRequestConfig, options: RequestOptions) => AxiosRequestConfig; /** * @description: 处理响应数据 */ transformResponseHook?: (res: AxiosResponse, options: RequestOptions) => any; /** * @description: 请求失败处理 */ requestCatchHook?: (e: Error, options: RequestOptions) => Promise; /** * @description: 请求之前的拦截器 */ requestInterceptors?: ( config: AxiosRequestConfig, options: CreateAxiosOptions, ) => AxiosRequestConfig; /** * @description: 请求之后的拦截器 */ responseInterceptors?: (res: AxiosResponse) => AxiosResponse; /** * @description: 请求之前的拦截器错误处理 */ requestInterceptorsCatch?: (error: Error) => void; /** * @description: 请求之后的拦截器错误处理 */ responseInterceptorsCatch?: (axiosInstance: AxiosResponse, error: Error) => void; }