import { AxiosRequestConfig } from 'axios'; import { HookedHistory, LinkPath } from './link'; export declare type MaybePromise = T | Promise; export declare function resolveMaybePromiseMethod(fun: (context?: any) => MaybePromise, context?: any): Promise; /** 函数类型的 formatter */ export declare type CommonRequestFunctionFormatter = (params: any, context?: any) => any; /** 支持上下文类型的 formatter */ export declare type CommonRequestFormatter = string | object | CommonRequestFunctionFormatter; export interface CustomRequestConfig extends AxiosRequestConfig { [key: string]: any; } /** * 通用的数据请求配置 * 统一处理常见业务场景的数据请求 * 完整数据请求的生命周期如下: * 1. 请求参数格式化 * 2. 发送请求 * 3. 处理请求结果(成功|失败):格式化(返回内容|错误) -> 消息提示 -> 回调函数 */ export interface CommonRequestConfig { /** 请求地址 */ url?: string; /** 请求方法 */ method?: 'get' | 'GET' | 'delete' | 'DELETE' | 'head' | 'HEAD' | 'options' | 'OPTIONS' | 'post' | 'POST' | 'put' | 'PUT' | 'patch' | 'PATCH' | 'purge' | 'PURGE' | 'link' | 'LINK' | 'unlink' | 'UNLINK'; /** 自定义请求,与url二选一 */ customRequest?: (context?: any) => Promise; /** 请求参数 */ params?: any; /** 请求参数。同时支持两种类型的参数,会自动根据请求方法做转换 */ data?: any; /** 扩展参数,会经过上下文处理,扩展到数据请求的参数中。 * 相当于执行 Objec.assign({}, extendParams, params)。 * 支持数组模式 extendParams = ['{{location}}', '{{fields}}'] */ extendParams?: any; /** 请求前处理函数 * 如果返回 false 或者 Promise,则停止发送请求。 * 如果返回 true 或者 Promise,则正常发送请求。 * 如果返回其他对象,则正常发送请求,并把返回的对象放到接下来请求处理的上下文中。 */ beforeRequest?: (context?: any) => MaybePromise; /** 请求成功后的消息,如有配置,会弹出成功提示 */ successMsg?: string; /** 请求失败后的消息,如有配置,会弹出失败提示 */ errorMsg?: string; /** 请求参数格式化函数,支持上下文类型 */ formatParams?: CommonRequestFormatter; /** 请求返回内容格式化函数,支持上下文类型 */ formatResult?: CommonRequestFormatter; /** 请求成功后的回调函数,支持使用上下文 */ onSuccess?: string | ((res: any, context?: any) => any); /** 请求失败后的回调函数,支持使用上下文 */ onError?: string | ((error: any, context?: any) => any); /** 请求成功后的跳转链接 */ link?: LinkPath; /** 自定义的请求配置 */ requestConfig?: CustomRequestConfig; } /** 通用数据请求能力,用来统一不同组件之间发送请求的能力,支持一些统一的配置项和请求处理过程 */ export declare function doCommonRequest(config: CommonRequestConfig, context?: any, history?: HookedHistory, extraParams?: any): Promise;