|
@@ -1,6 +1,6 @@
|
|
|
import {Menu} from 'antd';
|
|
|
import { useDispatch,useSelector } from 'react-redux'
|
|
|
-import { add } from '../../store/reducers/tabPanes'
|
|
|
+import { add,active } from '../../store/reducers/tabPanes'
|
|
|
import OrgManager from "../OrgManager";
|
|
|
import RoleManager from "../RoleManager";
|
|
|
import UserManager from "../UserManager"
|
|
@@ -17,11 +17,22 @@ const pageMap = {
|
|
|
|
|
|
function AMenu (){
|
|
|
const dispatch = useDispatch();
|
|
|
+ //当前选中的菜单
|
|
|
const activeTab = useSelector(state => {
|
|
|
return state.tabPanes.activeTab
|
|
|
});
|
|
|
+ //已打开的tabs
|
|
|
+ const panes = useSelector(state => {
|
|
|
+ return state.tabPanes.panes
|
|
|
+ });
|
|
|
+ //切换菜单、增加tab
|
|
|
function changeMenu(val){
|
|
|
- console.log(val)
|
|
|
+ const item = panes.find((it)=>it.key===val.key);
|
|
|
+ console.log(item);
|
|
|
+ if(item){ //已存在当前tab,则定位即可不增加
|
|
|
+ dispatch(active(val.key));
|
|
|
+ return;
|
|
|
+ }
|
|
|
dispatch(
|
|
|
add({ title: val.key, content: pageMap[val.key]||<OrgManager />, key:val.key },)
|
|
|
)
|
|
@@ -30,6 +41,7 @@ function AMenu (){
|
|
|
<Menu
|
|
|
defaultSelectedKeys={['组织管理']}
|
|
|
defaultOpenKeys={['权限管理']}
|
|
|
+ selectedKeys={activeTab}
|
|
|
mode="inline"
|
|
|
onClick={changeMenu}
|
|
|
>
|