/** * Axios HTTP 请求封装模块 * * 提供统一的 HTTP 请求方法,支持直接传入请求模型对象 * 配合 decorator 模块可实现 API 路由自动映射 * * @example * ```typescript * import { requestApi } from '@fefeding/common'; * * // 使用请求模型(自动获取装饰器中定义的 URL) * const res = await requestApi(new LoginReq({ account, password })); * * // 或直接传入 URL * const data = await requestApi('/api/user/info', { method: 'GET' }); * ``` */ import type { AxiosRequestConfig, AxiosResponse, AxiosInstance, AxiosStatic } from 'axios'; import axios from 'axios'; import request from '../models/base/request'; import response from '../models/base/response'; export default axios; /** 可注入的 HTTP 客户端类型 */ export type HttpClient = AxiosInstance | AxiosStatic; /** * 注入托管 HTTP 客户端(框架层用,例如 @midwayjs/axios 的 default client)。 * 注入后 common 的所有请求都会带上框架配置的超时、拦截器与链路信息。 * 传 null/undefined 可回退到全局 axios。 */ export declare function setHttpClient(client: HttpClient | null | undefined): void; /** 获取当前生效的 HTTP 客户端 */ export declare function getHttpClient(): HttpClient; /** 恢复为全局 axios 实例(单测 / 热更新用) */ export declare function resetHttpClient(): void; /** * 发送 HTTP 请求,返回完整响应对象 * @param url 请求 URL 或请求模型对象(带 @api 装饰器) * @param option Axios 请求配置 * @returns Axios 响应对象 */ export declare const requestServer: (url: string | request, option?: AxiosRequestConfig) => Promise; /** * 发送 HTTP 请求,返回响应数据体 * @param url 请求 URL 或请求模型对象(带 @api 装饰器) * @param option Axios 请求配置 * @returns 响应数据(response.data),无数据时返回 null */ export declare const requestApi: (url: string | request, option?: AxiosRequestConfig) => Promise;