ny
昨天 282fbc6488f4e8ceb5fda759f963ee88fbf7b999
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import type {
  AxiosRequestConfig,
  AxiosResponse,
  CreateAxiosDefaults,
  InternalAxiosRequestConfig,
} from 'axios';
 
type RequestResponse<T = any> = AxiosResponse<T>;
 
type RequestContentType =
  | 'application/json;charset=utf-8'
  | 'application/octet-stream;charset=utf-8'
  | 'application/x-www-form-urlencoded;charset=utf-8'
  | 'multipart/form-data;charset=utf-8';
 
type RequestClientOptions = CreateAxiosDefaults;
 
type ErrorMessageMode = 'message' | 'none' | undefined;
 
interface RequestOptions {
  // 接口地址
  apiUrl?: string;
  // 错误信息提示类型
  errorMessageMode?: ErrorMessageMode;
  // 需要对返回数据进行处理
  isTransformResponse?: boolean;
  // 是否返回原生响应头 比如:需要获取响应头时使用该属性
  isReturnNativeResponse?: boolean;
  // post请求的时候添加参数到url
  joinParamsToUrl?: boolean;
  //  是否加入时间戳
  joinTime?: boolean;
  // 是否加密
  useCipher?: boolean;
}
 
interface CreateAxiosOptions extends AxiosRequestConfig {
  requestOptions?: RequestOptions;
}
 
interface CreateInternalAxiosRequestConfig extends InternalAxiosRequestConfig {
  requestOptions?: RequestOptions;
}
 
interface RequestInterceptorConfig {
  fulfilled?: (
    config: CreateInternalAxiosRequestConfig,
  ) =>
    | CreateInternalAxiosRequestConfig
    | Promise<CreateInternalAxiosRequestConfig>;
  rejected?: (error: any) => any;
}
 
interface ResponseInterceptorConfig<T = any> {
  fulfilled?: (
    response: AxiosResponse<T>,
  ) => AxiosResponse | Promise<AxiosResponse>;
  rejected?: (error: any) => any;
}
 
type MakeErrorMessageFn = (message: string, error: any) => void;
 
interface HttpResponse<T = any> {
  /**
   * 200 表示成功 其他表示失败
   */
  code: number;
  data: T;
  msg: string;
}
 
export type {
  CreateAxiosOptions,
  CreateInternalAxiosRequestConfig,
  HttpResponse,
  MakeErrorMessageFn,
  RequestClientOptions,
  RequestContentType,
  RequestInterceptorConfig,
  RequestOptions,
  RequestResponse,
  ResponseInterceptorConfig,
};