index.tsx 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import {Card, Space, Button, Table} from 'antd';
  2. import {FC} from 'react';
  3. import {useHandle, useList} from './hooks';
  4. import {usePage} from '@hooks';
  5. import {pageContext} from '../context';
  6. import {PAGE_SIZE_LIST} from '@utils';
  7. import RoleModal from './modal';
  8. import TreeModal from './tree-modal';
  9. const TableList: FC = function() {
  10. const [{data, isFetching, count}, refetch] = useList();
  11. const [{page, pageSize}, {onPageChange}] = usePage(pageContext);
  12. const [
  13. {columns, visible, editId, roleVisible, roleId},
  14. {onAdd, onClose, onRoleClose},
  15. ] = useHandle(data, refetch);
  16. return (
  17. <>
  18. <Card className='table-wrapper'>
  19. <section className='table-tool'>
  20. <Space>
  21. <Button type='primary' onClick={onAdd}>新增</Button>
  22. </Space>
  23. </section>
  24. <Table
  25. columns={columns}
  26. dataSource={data}
  27. rowKey='id'
  28. pagination={{
  29. current: page,
  30. pageSize,
  31. onChange: onPageChange,
  32. pageSizeOptions: PAGE_SIZE_LIST,
  33. total: count,
  34. showSizeChanger: true,
  35. }}
  36. loading={isFetching}
  37. />
  38. </Card>
  39. <RoleModal visible={visible} onClose={onClose} onFetch={refetch} id={editId} />
  40. <TreeModal visible={roleVisible} onClose={onRoleClose} onFetch={refetch} id={roleId} />
  41. </>
  42. );
  43. };
  44. export default TableList;