UNPKG

@zdb/utils

Version:

工具包

30 lines (27 loc) 1.43 kB
import { AxiosRequestConfig, type AxiosResponse } from 'axios' export type TResponse<T> = { code: number msg?: string data: T } export type TResponseTable<T> = { total: number list: T } export interface AxiosProps { ProxyStr: string; // 接口前缀 ACCESS_TOKEN: string; // token 名称key errorNotification?: (msg: string) => void, // 错误提示 handler401Response?: (response: AxiosResponse) => void; // 处理401状态的请求 handler403Response?: (response: AxiosResponse) => void; // 处理403状态的请求 handlerError?: (error: any) => void; // 处理异常状态的请求 } export type UseAxios = (HOST: string, axiosProps: AxiosProps) => { service: <T>(options: AxiosRequestConfig) => Promise<TResponse<T>>, get: <T>(url: string, params?: unknown, options?: AxiosRequestConfig) => Promise<TResponse<T>>, post: <T = any>(url: string, data?: unknown, options?: AxiosRequestConfig) => Promise<TResponse<T>>, put: <T = any>(url: string, data?: unknown, options?: AxiosRequestConfig) => Promise<TResponse<T>>, _delete: <T = any>(url: string, params?: unknown, options?: AxiosRequestConfig) => Promise<TResponse<T>>, downloadFile: <T>(url: string, data?: unknown, options?: AxiosRequestConfig) => Promise<TResponse<T>> } export declare function useAxios (HOST: string, axiosProps: AxiosProps): UseAxios// 声明导出方法