types.ts 1.11 KB
import type { RequestConfig, ResponseData } from '../types';

// 小程序请求选项接口
export interface MiniProgramRequestOptions {
  url: string;
  method: string;
  header?: RequestConfig['headers'];
  timeout?: number;
  data?: any;
  success?: (res: any) => void;
  fail?: (err: any) => void;
  complete?: () => void;
}

// uniapp请求选项接口
export interface UniAppRequestOptions {
  url: string;
  method: string;
  header?: RequestConfig['headers'];
  timeout?: number;
  data?: any;
  success?: (res: any) => void;
  fail?: (err: any) => void;
  complete?: () => void;
}

// 小程序接口
export interface MiniProgram {
  request: (options: MiniProgramRequestOptions) => { abort: () => void };
}

// uniapp接口
export interface UniApp {
  request: (options: UniAppRequestOptions) => { abort: () => void };
}

export interface IResponseConfig {
  responseData: ResponseData<any>,
  config: RequestConfig
}

// 声明全局变量
declare global {
  const wx: MiniProgram | undefined;
  const uni: UniApp | undefined;
}

// 适配器接口
export type Adapter = (config: RequestConfig) => Promise<ResponseData<any>>;