|
@@ -57,53 +57,7 @@ export default {
|
|
}
|
|
}
|
|
},
|
|
},
|
|
methods: {
|
|
methods: {
|
|
- renderIcon: function (h, icon) {
|
|
|
|
- if (icon === 'none' || icon === undefined) {
|
|
|
|
- return null
|
|
|
|
- }
|
|
|
|
- const props = {}
|
|
|
|
- typeof (icon) === 'object' ? props.component = icon : props.type = icon
|
|
|
|
- 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 }, target: target } }, [
|
|
|
|
- this.renderIcon(h, menu.meta.icon),
|
|
|
|
- h('span', [menu.meta.title])
|
|
|
|
- ])
|
|
|
|
- ])
|
|
|
|
- },
|
|
|
|
- renderSubMenu: function (h, menu, pIndex, index) {
|
|
|
|
- const this2_ = this
|
|
|
|
- const subItem = [h('span', { slot: 'title' }, [this.renderIcon(h, menu.meta.icon), h('span', [menu.meta.title])])]
|
|
|
|
- const itemArr = []
|
|
|
|
- const pIndex_ = pIndex + '_' + index
|
|
|
|
- console.log('menu', menu)
|
|
|
|
- if (!menu.hideChildrenInMenu) {
|
|
|
|
- menu.children.forEach(function (item, i) {
|
|
|
|
- itemArr.push(this2_.renderItem(h, item, pIndex_, i))
|
|
|
|
- })
|
|
|
|
- }
|
|
|
|
- return h(SubMenu, { key: menu.path ? menu.path : 'submenu_' + pIndex + '_' + index }, subItem.concat(itemArr))
|
|
|
|
- },
|
|
|
|
- renderItem: function (h, menu, pIndex, index) {
|
|
|
|
- if (!menu.hidden) {
|
|
|
|
- return menu.children && !menu.hideChildrenInMenu
|
|
|
|
- ? this.renderSubMenu(h, menu, pIndex, index)
|
|
|
|
- : this.renderMenuItem(h, menu, pIndex, index)
|
|
|
|
- }
|
|
|
|
- },
|
|
|
|
- renderMenu: function (h, menuTree) {
|
|
|
|
- const this2_ = this
|
|
|
|
- const menuArr = []
|
|
|
|
- menuTree.forEach(function (menu, i) {
|
|
|
|
- if (!menu.hidden) {
|
|
|
|
- menuArr.push(this2_.renderItem(h, menu, '0', i))
|
|
|
|
- }
|
|
|
|
- })
|
|
|
|
- return menuArr
|
|
|
|
- },
|
|
|
|
|
|
+ // select menu item
|
|
onOpenChange (openKeys) {
|
|
onOpenChange (openKeys) {
|
|
const latestOpenKey = openKeys.find(key => !this.openKeys.includes(key))
|
|
const latestOpenKey = openKeys.find(key => !this.openKeys.includes(key))
|
|
if (!this.rootSubmenuKeys.includes(latestOpenKey)) {
|
|
if (!this.rootSubmenuKeys.includes(latestOpenKey)) {
|
|
@@ -130,27 +84,82 @@ export default {
|
|
}
|
|
}
|
|
|
|
|
|
this.collapsed ? (this.cachedOpenKeys = openKeys) : (this.openKeys = openKeys)
|
|
this.collapsed ? (this.cachedOpenKeys = openKeys) : (this.openKeys = openKeys)
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ // render
|
|
|
|
+ renderItem (menu) {
|
|
|
|
+ if (!menu.hidden) {
|
|
|
|
+ return menu.children && !menu.hideChildrenInMenu ? this.renderSubMenu(menu) : this.renderMenuItem(menu)
|
|
|
|
+ }
|
|
|
|
+ return null
|
|
|
|
+ },
|
|
|
|
+ renderMenuItem (menu) {
|
|
|
|
+ const target = menu.meta.target || null
|
|
|
|
+ const props = {
|
|
|
|
+ to: { name: menu.name },
|
|
|
|
+ target: target
|
|
|
|
+ }
|
|
|
|
+ return (
|
|
|
|
+ <Item {...{ key: menu.path }}>
|
|
|
|
+ <router-link {...{ props }}>
|
|
|
|
+ {this.renderIcon(menu.meta.icon)}
|
|
|
|
+ <span>{menu.meta.title}</span>
|
|
|
|
+ </router-link>
|
|
|
|
+ </Item>
|
|
|
|
+ )
|
|
|
|
+ },
|
|
|
|
+ renderSubMenu (menu) {
|
|
|
|
+ const itemArr = []
|
|
|
|
+ if (!menu.hideChildrenInMenu) {
|
|
|
|
+ menu.children.forEach(item => itemArr.push(this.renderItem(item)))
|
|
|
|
+ }
|
|
|
|
+ return (
|
|
|
|
+ <SubMenu {...{ key: menu.path }}>
|
|
|
|
+ <span slot="title">
|
|
|
|
+ {this.renderIcon(menu.meta.icon)}
|
|
|
|
+ <span>{menu.meta.title}</span>
|
|
|
|
+ </span>
|
|
|
|
+ {itemArr}
|
|
|
|
+ </SubMenu>
|
|
|
|
+ )
|
|
|
|
+ },
|
|
|
|
+ renderIcon (icon) {
|
|
|
|
+ if (icon === 'none' || icon === undefined) {
|
|
|
|
+ return null
|
|
|
|
+ }
|
|
|
|
+ const props = {}
|
|
|
|
+ typeof (icon) === 'object' ? props.component = icon : props.type = icon
|
|
|
|
+ return (
|
|
|
|
+ <Icon {... { props } }/>
|
|
|
|
+ )
|
|
}
|
|
}
|
|
},
|
|
},
|
|
- render (h) {
|
|
|
|
- return h(
|
|
|
|
- Menu,
|
|
|
|
- {
|
|
|
|
- props: {
|
|
|
|
- theme: this.$props.theme,
|
|
|
|
- mode: this.$props.mode,
|
|
|
|
- openKeys: this.openKeys,
|
|
|
|
- selectedKeys: this.selectedKeys
|
|
|
|
- },
|
|
|
|
- on: {
|
|
|
|
- openChange: this.onOpenChange,
|
|
|
|
- select: obj => {
|
|
|
|
- this.selectedKeys = obj.selectedKeys
|
|
|
|
- this.$emit('select', obj)
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ render () {
|
|
|
|
+ const { mode, theme, menu } = this
|
|
|
|
+ const props = {
|
|
|
|
+ mode: mode,
|
|
|
|
+ theme: theme,
|
|
|
|
+ openKeys: this.openKeys
|
|
|
|
+ }
|
|
|
|
+ const on = {
|
|
|
|
+ select: obj => {
|
|
|
|
+ this.selectedKeys = obj.selectedKeys
|
|
|
|
+ this.$emit('select', obj)
|
|
},
|
|
},
|
|
- this.renderMenu(h, this.menu)
|
|
|
|
|
|
+ openChange: this.onOpenChange
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ const menuTree = menu.map(item => {
|
|
|
|
+ if (item.hidden) {
|
|
|
|
+ return null
|
|
|
|
+ }
|
|
|
|
+ return this.renderItem(item)
|
|
|
|
+ })
|
|
|
|
+ // {...{ props, on: on }}
|
|
|
|
+ return (
|
|
|
|
+ <Menu vModel={this.selectedKeys} {...{ props, on: on }}>
|
|
|
|
+ {menuTree}
|
|
|
|
+ </Menu>
|
|
)
|
|
)
|
|
}
|
|
}
|
|
}
|
|
}
|