index.tsx 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import {Card, Button, Table} from 'antd';
  2. import {FC} from 'react';
  3. import MenuModal from './modal';
  4. import {useHandle, useList} from './hooks';
  5. import {PAGE_SIZE_LIST} from '@utils';
  6. import {useContextSection} from '@hooks';
  7. import {context} from '../context';
  8. import {TableTools} from '@components';
  9. const TableList: FC = function() {
  10. const [{isFetching, data, page, pageSize, count}, {refetch, onPageChange}] = useList();
  11. const [{columns, visible, editId}, {onModalClose, onAdd}] = useHandle(data, refetch);
  12. const onClose = useContextSection(context, ([{onClose}]) => onClose);
  13. return (
  14. <>
  15. <Card className='table-wrapper'>
  16. <TableTools onClick={onAdd} testId='child_menu_add_btn'>
  17. <Button type='default' onClick={onClose!} data-testid='child_menu_back'>返回</Button>
  18. </TableTools>
  19. <Table
  20. data-testid='child_menu_table'
  21. bordered
  22. columns={columns}
  23. dataSource={data}
  24. loading={isFetching}
  25. rowKey='id'
  26. pagination={{
  27. pageSize,
  28. pageSizeOptions: PAGE_SIZE_LIST,
  29. total: count,
  30. showSizeChanger: true,
  31. onChange: onPageChange,
  32. current: page,
  33. }}
  34. />
  35. </Card>
  36. <MenuModal visible={visible} onClose={onModalClose} id={editId} onFetch={refetch} />
  37. </>
  38. );
  39. };
  40. export default TableList;