ArticleListPublic.tsx 2.9 KB

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