interface.ts 1001 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. export type Method = 'OPTIONS' | 'GET' | 'HEAD' | 'POST' | 'PUT' | 'DELETE' | 'TRACE' | 'CONNECT'
  2. /**
  3. * Http请求配置
  4. */
  5. export interface HttpConfig<T> {
  6. url: string;
  7. method: Method;
  8. enableAuthorization?: boolean; // 是否启用用户凭证
  9. data?: T; // 请求参数
  10. isAccess?: boolean
  11. }
  12. /**
  13. * Http响应结果
  14. */
  15. export interface HttpResponse<T> {
  16. code: ResultCode;
  17. msg: string;
  18. data: T;
  19. }
  20. /**
  21. * Http请求参数
  22. * @param Req 请求参数
  23. * @param Res 响应结果
  24. */
  25. export interface HttpRequest<T extends { req?: unknown, rsp?: unknown } = object> {
  26. data?: T['req'];
  27. enableAuthorization?: boolean;
  28. success?: (res: HttpResponse<T['rsp']>) => void;
  29. fail?: (err: string) => void;
  30. complete?: () => void;
  31. }
  32. /**
  33. * Http响应结果状态码
  34. */
  35. export enum ResultCode {
  36. Success = 200, // 成功
  37. Code = 0, // 请求成功
  38. Error = 7, // 失败
  39. InvalidToken = 8, // 令牌无效
  40. }