TopChapter.tsx 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. import { Typography } from "antd";
  2. import { ProList } from "@ant-design/pro-components";
  3. import { get } from "../../request";
  4. import type { IChapterListResponse } from "../../api/Corpus";
  5. import { Link } from "react-router";
  6. const { Paragraph } = Typography;
  7. interface IItem {
  8. sn: number;
  9. title: string;
  10. subTitle: string;
  11. summary: string;
  12. book: number;
  13. paragraph: number;
  14. path: string;
  15. channelId: string;
  16. progress: number;
  17. view: number;
  18. created_at: string;
  19. updated_at: string;
  20. }
  21. interface IWidget {
  22. studioName?: string;
  23. }
  24. const TopChapterWidget = ({ studioName }: IWidget) => {
  25. return (
  26. <ProList<IItem>
  27. metas={{
  28. title: {
  29. render: (_dom, entity, _index, _action, _schema) => {
  30. return (
  31. <Link
  32. to={`/article/chapter/${entity.book}-${entity.paragraph}?mode=read&channel=${entity.channelId}`}
  33. >
  34. {entity.title ? entity.title : entity.subTitle}
  35. </Link>
  36. );
  37. },
  38. },
  39. subTitle: {},
  40. description: { dataIndex: "path" },
  41. type: {},
  42. avatar: {},
  43. content: {
  44. render: (_dom, entity, _index, _action, _schema) => {
  45. return (
  46. <Paragraph
  47. ellipsis={{ rows: 2, expandable: false, symbol: "more" }}
  48. >
  49. {entity.summary}
  50. </Paragraph>
  51. );
  52. },
  53. },
  54. actions: {
  55. cardActionProps: "extra",
  56. },
  57. }}
  58. showActions="hover"
  59. grid={{ gutter: 16, column: 2, md: 1 }}
  60. request={async (params = {}, sorter, filter) => {
  61. console.info(params, sorter, filter);
  62. const res = await get<IChapterListResponse>(
  63. `/v2/progress?view=chapter&studio=${studioName}&progress=0.9&limit=4`
  64. );
  65. console.debug("result", res.data.rows);
  66. const items: IItem[] = res.data.rows.map((item, id) => {
  67. return {
  68. sn: id + 1,
  69. book: item.book,
  70. paragraph: item.para,
  71. view: item.view,
  72. title: item.title,
  73. subTitle: item.toc,
  74. summary: item.summary,
  75. channelId: item.channel_id,
  76. path: item.path,
  77. progress: item.progress,
  78. created_at: item.created_at,
  79. updated_at: item.updated_at,
  80. };
  81. });
  82. return {
  83. total: res.data.count,
  84. succcess: true,
  85. data: items,
  86. };
  87. }}
  88. rowKey="id"
  89. bordered
  90. search={false}
  91. />
  92. );
  93. };
  94. export default TopChapterWidget;