Skip to content

Commit 42b386e

Browse files
committed
test: menu selectedKeys | hideChildrenInMenu
1 parent 201f188 commit 42b386e

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

src/components/Menu/menu.js

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,19 @@ export default {
7474
},
7575
updateMenu () {
7676
const routes = this.$route.matched.concat()
77-
78-
if (routes.length >= 4 && this.$route.meta.hidden) {
77+
console.log('updateMenu: routes -> ', routes)
78+
console.log('this.$route', this.$route)
79+
console.log('routes.length >= 3', routes.length >= 3, this.$route.meta)
80+
const { hidden } = this.$route.meta
81+
console.log('hidden', hidden)
82+
if (routes.length >= 3 && hidden) {
7983
routes.pop()
80-
this.selectedKeys = [routes[2].path]
84+
console.log('updateMenu: routes -> ', routes)
85+
this.selectedKeys = [routes[routes.length - 1].path]
8186
} else {
8287
this.selectedKeys = [routes.pop().path]
8388
}
84-
89+
console.log('this.selectedKeys', this.selectedKeys)
8590
const openKeys = []
8691
if (this.mode === 'inline') {
8792
routes.forEach(item => {
@@ -104,6 +109,16 @@ export default {
104109
const tag = target && 'a' || 'router-link'
105110
const props = { to: { name: menu.name } }
106111
const attrs = { href: menu.path, target: menu.meta.target }
112+
113+
if (menu.children && menu.hideChildrenInMenu) {
114+
// 把有子菜单的 并且 父菜单是要隐藏子菜单的
115+
// 都给子菜单增加一个 hidden 属性
116+
// 用来给刷新页面时, selectedKeys 做控制用
117+
menu.children.forEach(item => {
118+
item.meta = Object.assign(item.meta, { hidden: true })
119+
})
120+
}
121+
107122
return (
108123
<Item {...{ key: menu.path }}>
109124
<tag {...{ props, attrs }}>

src/config/router.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export const asyncRouterMap = [
1717
name: 'dashboard',
1818
redirect: '/dashboard/workplace',
1919
component: RouteView,
20+
hideChildrenInMenu: true,
2021
meta: { title: '仪表盘', keepAlive: true, icon: bxAnaalyse, permission: [ 'dashboard' ] },
2122
children: [
2223
{

0 commit comments

Comments
 (0)