import type { AxiosRequestConfig, AxiosResponse } from "axios"; import { AxiosInstance } from "axios"; /** * 通用 JSON 对象类型 */ export type JSONObject = Record; /** * 查询参数类型 */ export type QueryParams = JSONObject; /** * 请求数据类型 */ export type RequestData = JSONObject; /** * 响应数据类型 */ export interface ResponseData> extends AxiosResponse { data: ResData; } /** * 接口返回数据格式 */ export interface ResData> { code: number; data: T; msg: string; } /** * Axios 配置类型 */ export type AxiosConfig = AxiosRequestConfig; /** * 数据映射函数类型 * @template T - 输入类型 * @template R - 输出类型(默认为 T) */ export type MapFunction = (data: T) => R; /** * 带原始参数的映射函数类型(用于请求前处理) * @template T - 处理后的参数类型 * @template P - 原始参数类型 */ export type RequestMapFunction = (params: T, originalParams?: P) => T; /** * 列表请求返回结果接口 * @template T - 列表项数据类型 */ export interface GetListResult { /** 列表数据 */ list: T[]; /** 分页信息 */ pagination: { current?: number; total: number; pageSize?: number }; /** 其他扩展字段 */ [key: string]: any; } /** * 自定义列表请求函数类型 * @template T - 列表项数据类型 */ export type GetListFunc = (query: QueryParams) => Promise>; /** * 响应处理函数类型 */ export type HandleResponseFunc = (response: AxiosResponse) => ResponseData; /** * API 错误接口 */ export interface ApiError extends Error { /** 错误码 */ code?: number | string; /** 响应对象 */ response?: AxiosResponse; /** 错误消息(带下划线前缀) */ _msg?: string; /** 错误消息(带下划线前缀) */ _message?: string; /** 原始错误数据 */ data?: any; } /** * 网络链接信息接口(非标准 API) */ export interface NetworkConnection { type?: string; downlink?: number; effectiveType?: string; } /** * 扩展 Navigator 接口(包含非标准连接属性) */ export interface ExtendedNavigator extends Navigator { connection?: NetworkConnection; mozConnection?: NetworkConnection; webkitConnection?: NetworkConnection; }