perf: 分页组件

This commit is contained in:
archer
2023-04-07 21:34:51 +08:00
parent 9b18a46456
commit 29c5554f9e
4 changed files with 71 additions and 51 deletions

View File

@@ -1,20 +1,20 @@
import React from 'react';
import { Card, Box, Table, Thead, Tbody, Tr, Th, Td, TableContainer } from '@chakra-ui/react';
import ScrollData from '@/components/ScrollData';
import { BillTypeMap } from '@/constants/user';
import { getUserBills } from '@/api/user';
import { usePaging } from '@/hooks/usePaging';
import type { UserBillType } from '@/types/user';
import { usePagination } from '@/hooks/usePagination';
import { useLoading } from '@/hooks/useLoading';
const BillTable = () => {
const { Loading } = useLoading();
const {
nextPage,
isLoadAll,
requesting,
data: bills
} = usePaging<UserBillType>({
api: getUserBills,
pageSize: 30
data: bills,
isLoading,
Pagination
} = usePagination<UserBillType>({
api: getUserBills
});
return (
@@ -22,38 +22,34 @@ const BillTable = () => {
<Box fontSize={'xl'} fontWeight={'bold'} px={6} mb={1}>
使
</Box>
<ScrollData
maxH={'400px'}
px={6}
isLoadAll={isLoadAll}
requesting={requesting}
nextPage={nextPage}
>
<TableContainer>
<Table>
<Thead>
<Tr>
<Th></Th>
<Th></Th>
<Th></Th>
<Th>Tokens </Th>
<Th></Th>
<TableContainer position={'relative'}>
<Table>
<Thead>
<Tr>
<Th></Th>
<Th></Th>
<Th></Th>
<Th>Tokens </Th>
<Th></Th>
</Tr>
</Thead>
<Tbody fontSize={'sm'}>
{bills.map((item) => (
<Tr key={item.id}>
<Td>{item.time}</Td>
<Td>{BillTypeMap[item.type]}</Td>
<Td>{item.textLen}</Td>
<Td>{item.tokenLen}</Td>
<Td>{item.price}</Td>
</Tr>
</Thead>
<Tbody fontSize={'sm'}>
{bills.map((item) => (
<Tr key={item.id}>
<Td>{item.time}</Td>
<Td>{BillTypeMap[item.type]}</Td>
<Td>{item.textLen}</Td>
<Td>{item.tokenLen}</Td>
<Td>{item.price}</Td>
</Tr>
))}
</Tbody>
</Table>
</TableContainer>
</ScrollData>
))}
</Tbody>
</Table>
<Box mt={4} mr={4} textAlign={'end'}>
<Pagination />
</Box>
<Loading loading={isLoading} fixed={false} />
</TableContainer>
</Card>
);
};

View File

@@ -70,7 +70,7 @@ const PayRecordTable = () => {
wx联系
</Button>
</Flex>
<TableContainer maxH={'400px'} overflowY={'auto'} px={6}>
<TableContainer px={6}>
<Table>
<Thead>
<Tr>