|
|
@@ -20,41 +20,36 @@ const Contracts: React.FC = () => {
|
|
|
const queryClient = useQueryClient();
|
|
|
|
|
|
// 获取客户列表
|
|
|
- const { data: clientsData } = useQuery(
|
|
|
- ['clients'],
|
|
|
- async () => {
|
|
|
+ const { data: clientsData } = useQuery({
|
|
|
+ queryKey: ['clients'],
|
|
|
+ queryFn: async () => {
|
|
|
const response = await clientClient.$get({ query: { page: 1, pageSize: 1000 } });
|
|
|
if (response.status !== 200) throw new Error('Failed to fetch clients');
|
|
|
return response.json() as Promise<InferResponseType<typeof clientClient.$get, 200>>;
|
|
|
},
|
|
|
- {
|
|
|
- onSuccess: (result) => {
|
|
|
- setClients(result.data);
|
|
|
- },
|
|
|
- }
|
|
|
- );
|
|
|
+ onSuccess: (result) => {
|
|
|
+ setClients(result.data);
|
|
|
+ },
|
|
|
+ });
|
|
|
|
|
|
// 获取合同列表数据
|
|
|
- const fetchContracts = ({ page, pageSize }: { page: number; pageSize: number }): Promise<HetongListResponse> =>
|
|
|
- async () => {
|
|
|
- const response = await hetongClient.$get({ query: { page, pageSize, keyword: searchText } });
|
|
|
- if (response.status !== 200) throw new Error('Failed to fetch contracts');
|
|
|
- return response.json() as Promise<HetongListResponse>;
|
|
|
- };
|
|
|
+ const fetchContracts = async ({ page, pageSize }: { page: number; pageSize: number }): Promise<HetongListResponse> => {
|
|
|
+ const response = await hetongClient.$get({ query: { page, pageSize, keyword: searchText } });
|
|
|
+ if (response.status !== 200) throw new Error('Failed to fetch contracts');
|
|
|
+ return response.json() as Promise<HetongListResponse>;
|
|
|
+ };
|
|
|
|
|
|
- const { data, isLoading: loading, refetch } = useQuery(
|
|
|
- ['contracts', pagination.current, pagination.pageSize, searchText],
|
|
|
- () => fetchContracts({ page: pagination.current, pageSize: pagination.pageSize }),
|
|
|
- {
|
|
|
- onSuccess: (result: HetongListResponse) => {
|
|
|
- setDataSource(result.data);
|
|
|
- setPagination({
|
|
|
- ...pagination,
|
|
|
- total: result.pagination.total,
|
|
|
- });
|
|
|
- },
|
|
|
- }
|
|
|
- );
|
|
|
+ const { data, isLoading: loading, refetch } = useQuery({
|
|
|
+ queryKey: ['contracts', pagination.current, pagination.pageSize, searchText],
|
|
|
+ queryFn: () => fetchContracts({ page: pagination.current, pageSize: pagination.pageSize }),
|
|
|
+ onSuccess: (result: HetongListResponse) => {
|
|
|
+ setDataSource(result.data);
|
|
|
+ setPagination(prev => ({
|
|
|
+ ...prev,
|
|
|
+ total: result.pagination.total,
|
|
|
+ }));
|
|
|
+ },
|
|
|
+ });
|
|
|
|
|
|
const [dataSource, setDataSource] = useState<HetongItem[]>([]);
|
|
|
const [pagination, setPagination] = useState({
|