|
|
@@ -1,48 +1,29 @@
|
|
|
import {useBoolean} from 'ahooks';
|
|
|
import {context, pIdContext, pageContext} from '../context';
|
|
|
import {useEffect, useState} from 'react';
|
|
|
-import {useMutation, useQuery} from '@tanstack/react-query';
|
|
|
+import {useMutation} from '@tanstack/react-query';
|
|
|
import {deleteMenu, getMenuList} from '@apis';
|
|
|
import {MenuListData} from '@models';
|
|
|
import {Button, message} from 'antd';
|
|
|
import {ColumnsType} from 'antd/es/table';
|
|
|
-import {useContext, useContextSection, usePage} from '@hooks';
|
|
|
+import {useContext, useContextSection, useQueryTableList} from '@hooks';
|
|
|
import {deleteConfirm} from '@utils';
|
|
|
|
|
|
export function useList() {
|
|
|
- const [{page, pageSize}, {onPageChange}] = usePage(pageContext);
|
|
|
const [{name}, dispatch] = useContext(context);
|
|
|
- const [count, setCount] = useState(0);
|
|
|
const pid = useContextSection(pIdContext, ([pid]) => pid);
|
|
|
|
|
|
- const {data, isFetching, refetch} = useQuery(
|
|
|
- [getMenuList.name, pid, page, pageSize, name],
|
|
|
- async function() {
|
|
|
- const data = await getMenuList({
|
|
|
- pId: pid,
|
|
|
- page: page.toString(),
|
|
|
- limit: pageSize.toString(),
|
|
|
- name,
|
|
|
- });
|
|
|
-
|
|
|
- if (data.msg === '200') {
|
|
|
- setCount(data.data.total);
|
|
|
- return data.data.list;
|
|
|
- }
|
|
|
-
|
|
|
- return [] as MenuListData[];
|
|
|
- },
|
|
|
- {
|
|
|
- initialData: [],
|
|
|
- enabled: pid !== '0',
|
|
|
- },
|
|
|
- );
|
|
|
+ const [{isFetching, data, count}, {refetch}] = useQueryTableList({
|
|
|
+ queryFn: getMenuList,
|
|
|
+ params: {pId: pid, name},
|
|
|
+ pageContext,
|
|
|
+ });
|
|
|
|
|
|
useEffect(function() {
|
|
|
dispatch({type: 'CHANGE_SEARCH_STATE', payload: isFetching});
|
|
|
}, [dispatch, isFetching]);
|
|
|
|
|
|
- return [{count, isFetching, data, page, pageSize}, {refetch, onPageChange}] as const;
|
|
|
+ return [{count, isFetching, data}, {refetch}] as const;
|
|
|
}
|
|
|
|
|
|
export function useHandle(data: MenuListData[], refetch: () => void) {
|