index.tsx 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import {Card, 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 ChildMenuModal from '../child-menu';
  7. import {TableTools} from '@components';
  8. const TableList: FC = function() {
  9. const [{isFetching, data, page, pageSize, count}, {refetch, onPageChange}] = useList();
  10. const [
  11. {columns, visible, editId, pid, childVisible},
  12. {onModalClose, onAdd, closeChildModal},
  13. ] = useHandle(refetch);
  14. return (
  15. <>
  16. <Card className='table-wrapper'>
  17. <TableTools onClick={onAdd} />
  18. <Table
  19. data-testid='menu_table'
  20. bordered
  21. columns={columns}
  22. dataSource={data}
  23. loading={isFetching}
  24. rowKey='id'
  25. pagination={{
  26. pageSize,
  27. pageSizeOptions: PAGE_SIZE_LIST,
  28. total: count,
  29. showSizeChanger: true,
  30. onChange: onPageChange,
  31. current: page,
  32. }}
  33. />
  34. </Card>
  35. <MenuModal visible={visible} onClose={onModalClose} id={editId} onFetch={refetch} />
  36. <ChildMenuModal visible={childVisible} id={pid} onClose={closeChildModal} />
  37. </>
  38. );
  39. };
  40. export default TableList;