import type { CnRequestConfig } from '@cainiaofe/cn-request'; interface IBaseRequestConfig { manual?: boolean; onBefore?: (params: any) => void; onSuccess?: (data: any, params: any) => void; onError?: (e: Error, params: any) => void; onFinally?: (params: any, data?: any, e?: Error) => void; defaultParams?: any; refreshDeps?: any; refreshDepsAction?: () => void; loadingDelay?: number; pollingInterval?: number; pollingWhenHidden?: boolean; pollingErrorRetryCount?: number; refreshOnWindowFocus?: boolean; focusTimespan?: number; debounceWait?: number; debounceLeading?: boolean; debounceTrailing?: boolean; debounceMaxWait?: number; throttleWait?: number; throttleLeading?: boolean; throttleTrailing?: boolean; cacheKey?: string; cacheTime?: number; staleTime?: number; setCache?: (data: any) => void; getCache?: (params: any) => any; retryCount?: number; retryInterval?: number; ready?: boolean; } export interface IRequestConfig< /** * 接口层返回的数据 * 数据格式必须遵守菜鸟数据规范 */ IResponseData = unknown, /** * 请求所需的参数,注意只支持对象传参 */ IRequestParam = unknown, /** * 格式化后返回的数据,且是组件能消费的数据格式 * 当用户没有传该类型时,默认认为接口返回的 IResponseData 已经符合标准的数据格式 */ IFormatResult = IResponseData, /** * 格式化参数后返回的参数,最终接口服务所需参数的数据格式 * 当用户没有传该类型时,默认认为接口服务所需参数格式为 IRequestParam,这种情况比较完美,说明服务跟组件完美适配 */ IFormatParam = IRequestParam, > extends CnRequestConfig, IBaseRequestConfig { /** * 格式化接口返回数据 * @deprecated 请使用 formatResult 替代 */ resultFormatter?: (data: IResponse) => IFormatResult; /** * 格式化接口返回的数据,使用该 api 需要注意以下几点 * 1. 组件会将符合菜鸟数据规范的数据透传下去 * 2. 数据处理逻辑交给用户处理,组件不再做干预 * 3. 必须返回组件能消费的数据结构 */ formatResult?: (data: IResponse) => IFormatResult; /** * 格式化请求参数 * @deprecated 请使用 formatParam 替代 */ paramsFormatter?: (params?: IRequestParam) => IFormatParam; /** * 格式化请求参数 */ formatParam?: (params?: IRequestParam) => IFormatParam; /** * 自定义数据请求 service,service api 优先级高于 url api * 自定义 service 后,有以下几点需要注意: * 1. 数据交给用户自由控制,组件不会干预 * 2. formatParam 和 formatResults api 不再生效 * 3. service api 必须返回组件可消费的数据格式 */ service?: (params: IFormatParam) => Promise | IFormatResult; } export interface IResponse { data: T; errorCode: string; errorMsg: string; msg: string | null; success: boolean; }