index.tsx 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. import * as React from 'react';
  2. import { observer } from 'mobx-react';
  3. import { Table, TableColumnsType, TablePaginationConfig, Modal } from 'antd';
  4. import { DownloadOutlined } from '@ant-design/icons';
  5. import Search from './components/Search';
  6. import dayjs from 'dayjs';
  7. import store from './store';
  8. import { Record } from './types';
  9. import './style.less';
  10. const DataExport: React.FC = () => {
  11. const {
  12. state,
  13. onClickSearch,
  14. onClickReset,
  15. onChangePagination,
  16. onClickDownload,
  17. init,
  18. reset
  19. } = store;
  20. const {
  21. listLoading,
  22. list,
  23. page
  24. } = state;
  25. React.useEffect(() => {
  26. init();
  27. return () => reset();
  28. }, []);
  29. const columns: TableColumnsType<Record> = [
  30. {
  31. title: '序号',
  32. dataIndex: 'index',
  33. width: 80,
  34. render: (text, record, index) => {
  35. return index + 1;
  36. }
  37. },
  38. {
  39. title: '聊天标题',
  40. dataIndex: 'dialog_name',
  41. },
  42. {
  43. title: '消息长度',
  44. dataIndex: 'length',
  45. render: (text) => {
  46. return text + '条';
  47. }
  48. },
  49. {
  50. title: '聊天时间',
  51. dataIndex: 'create_time',
  52. width: 200,
  53. render: (text) => {
  54. if (text) {
  55. return dayjs(text).format('YYYY-MM-DD HH:mm:ss');
  56. } else {
  57. return '--';
  58. }
  59. }
  60. },
  61. {
  62. title: '操作',
  63. dataIndex: 'operation',
  64. width: 80,
  65. fixed: 'right',
  66. render: (text, record) => {
  67. return (
  68. <a
  69. onClick={() => {
  70. Modal.confirm({
  71. title: '导出',
  72. content: '确定导出Excel吗?',
  73. onOk: async () => {
  74. await onClickDownload(record.id, record.dialog_name);
  75. }
  76. });
  77. }}
  78. >
  79. <DownloadOutlined />
  80. </a >
  81. )
  82. }
  83. }
  84. ];
  85. const paginationConfig: TablePaginationConfig = {
  86. // 显示数据总量
  87. showTotal: (total: number) => {
  88. return `共 ${total} 条`;
  89. },
  90. // 展示分页条数切换
  91. showSizeChanger: true,
  92. // 指定每页显示条数
  93. pageSizeOptions: ['10', '20', '50', '100'],
  94. // 快速跳转至某页
  95. showQuickJumper: true,
  96. current: page.pageNumber,
  97. pageSize: page.pageSize,
  98. total: page.total,
  99. onChange: async (page, pageSize) => {
  100. await onChangePagination(page, pageSize);
  101. },
  102. };
  103. return (
  104. <div className='dataExport'>
  105. <div className='dataExport-search'>
  106. <Search
  107. onClickSearch={onClickSearch}
  108. onClickReset={onClickReset}
  109. />
  110. </div>
  111. <div className='dataExport-table'>
  112. <Table
  113. scroll={{ x: 'max-content' }}
  114. rowKey={(record) => record.id}
  115. loading={listLoading}
  116. columns={columns}
  117. dataSource={list}
  118. pagination={paginationConfig}
  119. />
  120. </div>
  121. </div>
  122. );
  123. };
  124. export default observer(DataExport);