Browse Source

fix: router alwaysShow rename hideChildrenInMenu

Sendya 6 years ago
parent
commit
de6136356f

+ 5 - 3
src/components/menu/index.js

@@ -66,8 +66,9 @@ export default {
       return h(Icon, { props: { ...props } })
     },
     renderMenuItem: function (h, menu, pIndex, index) {
+      const target = menu.meta.target || null
       return h(Item, { key: menu.path ? menu.path : 'item_' + pIndex + '_' + index }, [
-        h('router-link', { attrs: { to: { name: menu.name } } }, [
+        h('router-link', { attrs: { to: { name: menu.name }, target: target } }, [
           this.renderIcon(h, menu.meta.icon),
           h('span', [menu.meta.title])
         ])
@@ -78,7 +79,8 @@ export default {
       const subItem = [h('span', { slot: 'title' }, [this.renderIcon(h, menu.meta.icon), h('span', [menu.meta.title])])]
       const itemArr = []
       const pIndex_ = pIndex + '_' + index
-      if (!menu.alwaysShow) {
+      console.log('menu', menu)
+      if (!menu.hideChildrenInMenu) {
         menu.children.forEach(function (item, i) {
           itemArr.push(this2_.renderItem(h, item, pIndex_, i))
         })
@@ -87,7 +89,7 @@ export default {
     },
     renderItem: function (h, menu, pIndex, index) {
       if (!menu.hidden) {
-        return menu.children && !menu.alwaysShow
+        return menu.children && !menu.hideChildrenInMenu
           ? this.renderSubMenu(h, menu, pIndex, index)
           : this.renderMenuItem(h, menu, pIndex, index)
       }

+ 0 - 1
src/components/page/GlobalLayout.vue

@@ -131,7 +131,6 @@ export default {
         }, 16)
       })
     }
-
   },
   methods: {
     ...mapActions(['setSidebar']),

+ 2 - 2
src/config/router.config.js

@@ -80,7 +80,7 @@ export const asyncRouterMap = [
           {
             path: '/list/query-list',
             name: 'QueryListWrapper',
-            alwaysShow: true, // 强制显示 MenuItem 而不是 SubMenu
+            hideChildrenInMenu: true, // 强制显示 MenuItem 而不是 SubMenu
             component: () => import('@/views/list/TableList'),
             meta: { title: '查询表格', keepAlive: true, permission: [ 'table' ] }
           },
@@ -257,7 +257,7 @@ export const asyncRouterMap = [
             component: () => import('@/views/account/settings/Index'),
             meta: { title: '个人设置', hideHeader: true, keepAlive: true, permission: [ 'user' ] },
             redirect: '/account/settings/base',
-            alwaysShow: true,
+            hideChildrenInMenu: true,
             children: [
               {
                 path: '/account/settings/base',

+ 1 - 1
src/router/README.md

@@ -42,7 +42,7 @@
 | redirect | 重定向地址, 访问这个路由时,自定进行重定向 | string  | -      |
 | name     | 路由名称, 必须设置,且不能重名           | string  | -      |
 | meta     | 路由元信息(路由附带扩展信息)            | object  | {}     |
-| alwaysShow | 强制菜单显示为Item而不是SubItem(配合 meta.hidden) | boolean  | -   |
+| hideChildrenInMenu | 强制菜单显示为Item而不是SubItem(配合 meta.hidden) | boolean  | -   |
 
 
 `{ Meta }` 路由元信息对象