ArticleListPublic.tsx 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. import { Link } from "react-router-dom";
  2. import { useRef } from "react";
  3. import { Space } from "antd";
  4. import { ActionType, ProList } from "@ant-design/pro-components";
  5. import { get } from "../../request";
  6. import { IArticleListResponse } from "../api/Article";
  7. import { IStudio } from "../auth/StudioName";
  8. import { IUser } from "../auth/User";
  9. import TimeShow from "../general/TimeShow";
  10. interface DataItem {
  11. sn: number;
  12. id: string;
  13. title: string;
  14. subtitle: string;
  15. summary: string;
  16. anthologyCount?: number;
  17. anthologyTitle?: string;
  18. publicity: number;
  19. createdAt?: string;
  20. updatedAt: string;
  21. studio?: IStudio;
  22. editor?: IUser;
  23. }
  24. interface IWidget {
  25. search?: string;
  26. studioName?: string;
  27. }
  28. const ArticleListWidget = ({ search, studioName }: IWidget) => {
  29. const ref = useRef<ActionType>();
  30. return (
  31. <>
  32. <ProList<DataItem>
  33. rowKey="id"
  34. actionRef={ref}
  35. metas={{
  36. title: {
  37. render: (text, row, index, action) => {
  38. return <Link to={`/article/article/${row.id}`}>{row.title}</Link>;
  39. },
  40. },
  41. description: {
  42. dataIndex: "summary",
  43. },
  44. subTitle: {
  45. render: (text, row, index, action) => {
  46. return (
  47. <Space>
  48. {row.editor?.nickName}
  49. <TimeShow time={row.updatedAt} />
  50. </Space>
  51. );
  52. },
  53. },
  54. }}
  55. request={async (params = {}, sorter, filter) => {
  56. let url = `/v2/article?view=public`;
  57. const offset =
  58. ((params.current ? params.current : 1) - 1) *
  59. (params.pageSize ? params.pageSize : 20);
  60. url += `&limit=${params.pageSize}&offset=${offset}`;
  61. url += params.keyword ? "&search=" + params.keyword : "";
  62. url += studioName ? "&studio=" + studioName : "";
  63. const res = await get<IArticleListResponse>(url);
  64. const items: DataItem[] = res.data.rows.map((item, id) => {
  65. return {
  66. sn: id + 1,
  67. id: item.uid,
  68. title: item.title,
  69. subtitle: item.subtitle,
  70. summary: item.summary,
  71. anthologyCount: item.anthology_count,
  72. anthologyTitle: item.anthology_first?.title,
  73. publicity: item.status,
  74. updatedAt: item.updated_at,
  75. studio: item.studio,
  76. editor: item.editor,
  77. };
  78. });
  79. return {
  80. total: res.data.count,
  81. succcess: true,
  82. data: items,
  83. };
  84. }}
  85. bordered
  86. pagination={{
  87. showQuickJumper: true,
  88. showSizeChanger: true,
  89. pageSize: 20,
  90. }}
  91. search={false}
  92. options={{
  93. search: true,
  94. }}
  95. />
  96. </>
  97. );
  98. };
  99. export default ArticleListWidget;