|
|
@@ -1,5 +1,4 @@
|
|
|
import {useBoolean} from 'ahooks';
|
|
|
-import {useContext, useContextSelector} from 'use-context-selector';
|
|
|
import {context, pageContext} from '../context';
|
|
|
import {useState} from 'react';
|
|
|
import {useMutation, useQuery} from '@tanstack/react-query';
|
|
|
@@ -9,11 +8,12 @@ import {MenuListData} from '@models';
|
|
|
import {Button, Modal} from 'antd';
|
|
|
import {ColumnsType} from 'antd/es/table';
|
|
|
import {MENU_CHILD_PATH, MENU_PATH} from '@routes';
|
|
|
+import {useContext, useContextSection} from '@hooks';
|
|
|
|
|
|
export function useList() {
|
|
|
const [{page, pageSize}, dispatch] = useContext(pageContext);
|
|
|
const [count, setCount] = useState(0);
|
|
|
- const name = useContextSelector(context, state => state[0].name);
|
|
|
+ const name = useContextSection(context, state => state[0].name);
|
|
|
const {id} = useParams<{id: string}>();
|
|
|
const pid = id ?? '0';
|
|
|
|
|
|
@@ -91,16 +91,19 @@ export function useHandle(data: MenuListData[], refetch: () => void) {
|
|
|
}
|
|
|
|
|
|
const navigate = useNavigate();
|
|
|
- const name = useContextSelector(context, state => state[0].name);
|
|
|
- const {page, pageSize} = useContextSelector(pageContext, state => state[0]);
|
|
|
+ const name = useContextSection(context, state => state[0].name);
|
|
|
+ const {page, pageSize} = useContextSection(pageContext, state => state[0]);
|
|
|
|
|
|
- function onChild(id: string) {
|
|
|
+ function onToChild(id: string) {
|
|
|
return function() {
|
|
|
+ // 去往二级菜单后 返回时候携带查询信息 确保数据与离开时相同
|
|
|
const url = generatePath(MENU_CHILD_PATH, {id});
|
|
|
- navigate(url, {state: {name, page, pageSize}});
|
|
|
+ navigate(url, {state: {name, page, pageSize, pathValue: MENU_PATH}});
|
|
|
};
|
|
|
}
|
|
|
|
|
|
+ const {id} = useParams<{id: string}>();
|
|
|
+ const isChild = Boolean(id);
|
|
|
const columns: ColumnsType<MenuListData> = [
|
|
|
{title: '菜单名称', dataIndex: 'name', key: 'name'},
|
|
|
{title: '菜单路径', dataIndex: 'url', key: 'url'},
|
|
|
@@ -127,13 +130,13 @@ export function useHandle(data: MenuListData[], refetch: () => void) {
|
|
|
>
|
|
|
删除
|
|
|
</Button>
|
|
|
- <Button
|
|
|
+ {!isChild && <Button
|
|
|
type='text'
|
|
|
loading={pendingId === id}
|
|
|
- onClick={onChild(id)}
|
|
|
+ onClick={onToChild(id)}
|
|
|
>
|
|
|
子菜单
|
|
|
- </Button>
|
|
|
+ </Button>}
|
|
|
</>
|
|
|
);
|
|
|
},
|
|
|
@@ -145,7 +148,6 @@ export function useHandle(data: MenuListData[], refetch: () => void) {
|
|
|
|
|
|
export function useBack() {
|
|
|
const {id} = useParams<{id: string}>();
|
|
|
-
|
|
|
const isChild = Boolean(id);
|
|
|
|
|
|
const {state} = useLocation();
|