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. const res = await get<ISentHistoryListResponse>(url);
  51. if (res.ok) {
  52. console.log(res.data);
  53. const items: ISentHistory[] = res.data.rows.map((item, id) => {
  54. return {
  55. content: item.content,
  56. editor: item.editor,
  57. createdAt: item.created_at,
  58. };
  59. });
  60. console.log(items);
  61. return {
  62. total: res.data.count,
  63. succcess: true,
  64. data: items,
  65. };
  66. } else {
  67. console.error(res.message);
  68. return {
  69. total: 0,
  70. succcess: false,
  71. data: [],
  72. };
  73. }
  74. }}
  75. pagination={{
  76. showQuickJumper: true,
  77. showSizeChanger: true,
  78. }}
  79. metas={{
  80. title: {
  81. render: (text, row, index, action) => {
  82. return (
  83. <Paragraph copyable={{ text: row.content }}>
  84. {row.content}
  85. </Paragraph>
  86. );
  87. },
  88. },
  89. avatar: {
  90. dataIndex: "image",
  91. editable: false,
  92. },
  93. description: {
  94. render: (text, row, index, action) => {
  95. return (
  96. <Space style={{ fontSize: "80%" }}>
  97. <User {...row.editor} />
  98. <TimeShow type="secondary" createdAt={row.createdAt} />
  99. </Space>
  100. );
  101. },
  102. },
  103. actions: {
  104. render: (text, row, index, action) => [<></>],
  105. },
  106. }}
  107. />
  108. );
  109. };
  110. export default SentHistoryWidget;