interface.ts 977 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. }
  11. /**
  12. * Http响应结果
  13. */
  14. export interface HttpResponse<T> {
  15. code: ResultCode;
  16. msg: string;
  17. data: T;
  18. }
  19. /**
  20. * Http请求参数
  21. * @param Req 请求参数
  22. * @param Res 响应结果
  23. */
  24. export interface HttpRequest<T extends { req?: unknown, rsp?: unknown } = object> {
  25. data?: T['req'];
  26. enableAuthorization?: boolean;
  27. success?: (res: HttpResponse<T['rsp']>) => void;
  28. fail?: (err: string) => void;
  29. complete?: () => void;
  30. }
  31. /**
  32. * Http响应结果状态码
  33. */
  34. export enum ResultCode {
  35. Success = 200, // 成功
  36. Code = 0, // 请求成功
  37. Error = 7, // 失败
  38. InvalidToken = 8, // 令牌无效
  39. }