Former-commit-id: a028cd2bfb5d361eeb019eafc1203d26fd68a35e
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
import { uniqueId } from 'lodash'
|
||||
|
||||
// 创建 el-menu-item
|
||||
export function elMenuItem (createElement, menu) {
|
||||
return createElement('el-menu-item', { props: { index: menu.path || uniqueId('d2-menu-empty-') } }, [
|
||||
return createElement('el-menu-item', { props: { index: menu.path } }, [
|
||||
...menu.icon ? [
|
||||
createElement('i', { attrs: { class: `fa fa-${menu.icon}` } })
|
||||
] : [],
|
||||
@@ -12,13 +10,13 @@ export function elMenuItem (createElement, menu) {
|
||||
...menu.iconSvg ? [
|
||||
createElement('d2-icon-svg', { props: { name: menu.iconSvg } })
|
||||
] : [],
|
||||
createElement('span', { slot: 'title' }, menu.title || '未命名菜单')
|
||||
createElement('span', { slot: 'title' }, menu.title || this.$t('layout.header-aside.menu-item.label-default'))
|
||||
])
|
||||
}
|
||||
|
||||
// 创建 el-submenu
|
||||
export function elSubmenu (createElement, menu) {
|
||||
return createElement('el-submenu', { props: { index: menu.path || uniqueId('d2-menu-empty-') } }, [
|
||||
return createElement('el-submenu', { props: { index: menu.path } }, [
|
||||
...menu.icon ? [
|
||||
createElement('i', { slot: 'title', attrs: { class: `fa fa-${menu.icon}` } })
|
||||
] : [],
|
||||
@@ -28,7 +26,7 @@ export function elSubmenu (createElement, menu) {
|
||||
...menu.iconSvg ? [
|
||||
createElement('d2-icon-svg', { slot: 'title', props: { name: menu.iconSvg } })
|
||||
] : [],
|
||||
createElement('span', { slot: 'title' }, menu.title || '未命名菜单'),
|
||||
createElement('span', { slot: 'title' }, menu.title || this.$t('layout.header-aside.menu-item.label-default')),
|
||||
...menu.children.map((child, childIndex) => (child.children === undefined ? elMenuItem : elSubmenu).call(this, createElement, child))
|
||||
])
|
||||
}
|
||||
|
||||
@@ -45,14 +45,9 @@ export default {
|
||||
}, 500)
|
||||
},
|
||||
// 监听路由 控制侧边栏激活状态
|
||||
'$route': {
|
||||
handler ({ fullPath }) {
|
||||
this.active = fullPath
|
||||
this.$nextTick(() => {
|
||||
if (this.aside.length > 0 && this.$refs.menu) {
|
||||
this.$refs.menu.activeIndex = fullPath
|
||||
}
|
||||
})
|
||||
'$route.fullPath': {
|
||||
handler (value) {
|
||||
this.active = value
|
||||
},
|
||||
immediate: true
|
||||
}
|
||||
|
||||
@@ -1,6 +1,22 @@
|
||||
import { uniqueId } from 'lodash'
|
||||
// 设置文件
|
||||
import setting from '@/setting.js'
|
||||
|
||||
/**
|
||||
* 给菜单数据补充上 path 字段
|
||||
* https://github.com/d2-projects/d2-admin/issues/209
|
||||
* @param {Array} menu 原始的菜单数据
|
||||
*/
|
||||
function supplementMenuPath (menu) {
|
||||
return menu.map(e => ({
|
||||
...e,
|
||||
path: e.path || uniqueId('d2-menu-empty-'),
|
||||
...e.children ? {
|
||||
children: supplementMenuPath(e.children)
|
||||
} : {}
|
||||
}))
|
||||
}
|
||||
|
||||
export default {
|
||||
namespaced: true,
|
||||
state: {
|
||||
@@ -77,7 +93,7 @@ export default {
|
||||
*/
|
||||
headerSet (state, menu) {
|
||||
// store 赋值
|
||||
state.header = menu
|
||||
state.header = supplementMenuPath(menu)
|
||||
},
|
||||
/**
|
||||
* @description 设置侧边栏菜单
|
||||
@@ -86,7 +102,7 @@ export default {
|
||||
*/
|
||||
asideSet (state, menu) {
|
||||
// store 赋值
|
||||
state.aside = menu
|
||||
state.aside = supplementMenuPath(menu)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user