recent.ts 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. // src/api/recent.ts
  2. import { get, post } from "../request";
  3. import type { ArticleType } from "./article";
  4. export interface IRecent {
  5. id: string;
  6. title: string;
  7. type: ArticleType;
  8. articleId: string;
  9. updatedAt: string;
  10. param?: IRecentParam;
  11. }
  12. export interface IRecentRequest {
  13. type: ArticleType;
  14. article_id: string;
  15. param?: string;
  16. }
  17. export interface IRecentParam {
  18. book?: string;
  19. para?: string;
  20. channel?: string;
  21. mode?: string;
  22. }
  23. export interface IRecentData {
  24. id: string;
  25. title: string;
  26. type: ArticleType;
  27. article_id: string;
  28. param: string | null;
  29. updated_at: string;
  30. }
  31. export interface IRecentResponse {
  32. ok: boolean;
  33. message: string;
  34. data: IRecentData;
  35. }
  36. export interface IRecentListResponse {
  37. ok: boolean;
  38. message: string;
  39. data: {
  40. rows: IRecentData[];
  41. count: number;
  42. };
  43. }
  44. // 新增
  45. export interface IGetRecentByUserParams {
  46. userId: string;
  47. pageSize: number;
  48. page?: number;
  49. type?: ArticleType;
  50. }
  51. // 修改
  52. export const getRecentByUser = async (
  53. params: IGetRecentByUserParams
  54. ): Promise<IRecentListResponse> => {
  55. const { userId, pageSize, page = 0, type } = params;
  56. let url = `/api/v2/recent?view=user&id=${userId}`;
  57. url += `&limit=${pageSize}&offset=${page}`;
  58. if (type !== undefined) url += `&type=${type}`;
  59. console.log("url", url);
  60. return await get<IRecentListResponse>(url);
  61. };
  62. export interface ISaveRecentRequest {
  63. type: ArticleType;
  64. article_id: string;
  65. param?: string;
  66. }
  67. export const saveRecent = async (
  68. payload: ISaveRecentRequest
  69. ): Promise<IRecentResponse> => {
  70. return await post<ISaveRecentRequest, IRecentResponse>(
  71. "/api/v2/recent",
  72. payload
  73. );
  74. };