axios.d.ts 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import type { ApiServiceEnum } from '@/utils/http/axios';
  2. import type { AxiosRequestConfig } from 'axios';
  3. export type ErrorMessageMode = 'none' | 'modal' | 'message' | undefined;
  4. export type SuccessMessageMode = ErrorMessageMode;
  5. export interface RequestOptions {
  6. // Splicing request parameters to url
  7. joinParamsToUrl?: boolean;
  8. // Format request parameter time
  9. formatDate?: boolean;
  10. // Whether to process the request result
  11. isTransformResponse?: boolean;
  12. // Whether to return native response headers
  13. // For example: use this attribute when you need to get the response headers
  14. isReturnNativeResponse?: boolean;
  15. // Whether to join url
  16. joinPrefix?: boolean;
  17. // Interface address, use the default apiUrl if you leave it blank
  18. apiUrl?: string;
  19. // 请求拼接路径
  20. urlPrefix?: string;
  21. // Error message prompt type
  22. errorMessageMode?: ErrorMessageMode;
  23. // Success message prompt type
  24. successMessageMode?: SuccessMessageMode;
  25. // Whether to add a timestamp
  26. joinTime?: boolean;
  27. ignoreCancelToken?: boolean;
  28. // Whether to send token in header
  29. withToken?: boolean;
  30. // 请求重试机制
  31. retryRequest?: RetryRequest;
  32. }
  33. export interface RetryRequest {
  34. isOpenRetry: boolean;
  35. count: number;
  36. waitTime: number;
  37. }
  38. export interface Result<T = any> {
  39. code: number;
  40. type: 'success' | 'error' | 'warning';
  41. message: string;
  42. data: T;
  43. exceptionNo?: number;
  44. }
  45. // multipart/form-data: upload file
  46. export interface UploadFileParams {
  47. // Other parameters
  48. data?: Recordable;
  49. // File parameter interface field name
  50. name?: string;
  51. // file name
  52. file: File | Blob;
  53. // file name
  54. filename?: string;
  55. [key: string]: any;
  56. }
  57. export type ApiService = ApiServiceEnum;
  58. export interface SmartAxiosRequestConfig<D = any> extends AxiosRequestConfig<D> {
  59. // 指定请求发送的服务
  60. service: ApiService;
  61. }