base.ts 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import { http } from "@/utils/http";
  2. export interface Result<T> {
  3. code: number;
  4. message: string;
  5. result: T;
  6. success: boolean;
  7. timestamp: number;
  8. }
  9. export interface BaseQuery {
  10. size?: number;
  11. current?: number;
  12. }
  13. /**
  14. * post
  15. */
  16. export function post<T, P>(url: string, data: T): Promise<Result<P>> {
  17. return http.post<T, Result<P>>(url, { data: data });
  18. }
  19. /**
  20. * get
  21. */
  22. export function get<T, P>(url: string, params?: T): Promise<Result<P>> {
  23. return http.get<T, Result<P>>(url, { params: params });
  24. }
  25. /**
  26. * put
  27. * @param url path
  28. * @param params query
  29. * @param data body
  30. * @returns .
  31. */
  32. export function put<T>(
  33. url: string,
  34. params?: any,
  35. data?: T
  36. ): Promise<Result<T>> {
  37. return http.request("put", url, { params: params, data: data });
  38. }
  39. /**
  40. * 删除
  41. * @param url .
  42. * @param params .
  43. * @param data .
  44. * @returns .
  45. */
  46. export function deleteRequest<T>(
  47. url: string,
  48. params?: any,
  49. data?: any
  50. ): Promise<Result<T>> {
  51. return http.request("delete", url, { params: params, data: data });
  52. }