SentHistory.tsx 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. import { ProList } from "@ant-design/pro-components";
  2. import { Space, Typography } from "antd";
  3. import { get } from "../../request";
  4. import User from "../auth/User";
  5. import { IUser } from "../auth/UserName";
  6. import TimeShow from "../general/TimeShow";
  7. const { Paragraph } = Typography;
  8. export interface ISentHistoryData {
  9. id: string;
  10. sent_uid: string;
  11. content: string;
  12. editor: IUser;
  13. landmark: string;
  14. created_at: string;
  15. }
  16. export interface ISentHistoryListResponse {
  17. ok: boolean;
  18. message: string;
  19. data: { rows: ISentHistoryData[]; count: number };
  20. }
  21. interface ISentHistory {
  22. content: string;
  23. editor: IUser;
  24. createdAt: string;
  25. }
  26. interface IWidget {
  27. sentId?: string;
  28. }
  29. const SentHistoryWidget = ({ sentId }: IWidget) => {
  30. return (
  31. <ProList<ISentHistory>
  32. rowKey="id"
  33. request={async (params = {}, sorter, filter) => {
  34. if (typeof sentId === "undefined") {
  35. return {
  36. total: 0,
  37. succcess: false,
  38. data: [],
  39. };
  40. }
  41. console.log(params, sorter, filter);
  42. let url = `/v2/sent_history?view=sentence&id=${sentId}`;
  43. const offset =
  44. ((params.current ? params.current : 1) - 1) *
  45. (params.pageSize ? params.pageSize : 20);
  46. url += `&limit=${params.pageSize}&offset=${offset}`;
  47. if (typeof params.keyword !== "undefined") {
  48. url += "&search=" + (params.keyword ? params.keyword : "");
  49. }
  50. console.info("url", url);
  51. const res = await get<ISentHistoryListResponse>(url);
  52. if (res.ok) {
  53. console.debug(res.data);
  54. const items: ISentHistory[] = res.data.rows.map((item, id) => {
  55. return {
  56. content: item.content,
  57. editor: item.editor,
  58. createdAt: item.created_at,
  59. };
  60. });
  61. console.debug(items);
  62. return {
  63. total: res.data.count,
  64. succcess: true,
  65. data: items,
  66. };
  67. } else {
  68. console.error(res.message);
  69. return {
  70. total: 0,
  71. succcess: false,
  72. data: [],
  73. };
  74. }
  75. }}
  76. pagination={{
  77. showQuickJumper: true,
  78. showSizeChanger: true,
  79. }}
  80. metas={{
  81. title: {
  82. render: (text, row, index, action) => {
  83. return (
  84. <Paragraph copyable={{ text: row.content }}>
  85. {row.content}
  86. </Paragraph>
  87. );
  88. },
  89. },
  90. avatar: {
  91. dataIndex: "image",
  92. editable: false,
  93. },
  94. description: {
  95. render: (text, row, index, action) => {
  96. return (
  97. <Space style={{ fontSize: "80%" }}>
  98. <User {...row.editor} />
  99. <TimeShow type="secondary" createdAt={row.createdAt} />
  100. </Space>
  101. );
  102. },
  103. },
  104. actions: {
  105. render: (text, row, index, action) => [<></>],
  106. },
  107. }}
  108. />
  109. );
  110. };
  111. export default SentHistoryWidget;