types.ts
1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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>>;