fix #209
Former-commit-id: d7010f02783505101c190835398a7c37eb307b55 [formerly d7010f02783505101c190835398a7c37eb307b55 [formerly d7010f02783505101c190835398a7c37eb307b55 [formerly d7010f02783505101c190835398a7c37eb307b55 [formerly a3290a545292ceb2b1919cdbacda986cf377725a [formerly 68f1acb63acc7b4d865d6f8ef291f5e3a0dc343c]]]]] Former-commit-id: c27bdeb76049a09c66ed9c7099482178669d8916 Former-commit-id: c17ffd2492fa3bbe035e1aff55f3a1f7a30fa865 Former-commit-id: 22bee1feb72768a03b09a7a152b8aadf4fadebb5 [formerly b85ad6c9f13e74b0d4982696986a2d4766c54a30] Former-commit-id: 2436d4d6c011e4a7a4caf4225023ab527edafe3b Former-commit-id: dabbec6015fb3389dca549b0aacdaa1ac5ba3b96 Former-commit-id: 20757fed0eef07b85e236f73803b2ab6862ecf7f Former-commit-id: 5952b4fb216126a1781baf8b8629d7cdaa73bf65 Former-commit-id: d3607c0521f90d7b368a0bb3de661010653f5041
This commit is contained in:
@@ -1,8 +1,6 @@
|
|||||||
import { uniqueId } from 'lodash'
|
|
||||||
|
|
||||||
// 创建 el-menu-item
|
// 创建 el-menu-item
|
||||||
export function elMenuItem (createElement, menu) {
|
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 ? [
|
...menu.icon ? [
|
||||||
createElement('i', { attrs: { class: `fa fa-${menu.icon}` } })
|
createElement('i', { attrs: { class: `fa fa-${menu.icon}` } })
|
||||||
] : [],
|
] : [],
|
||||||
@@ -18,7 +16,7 @@ export function elMenuItem (createElement, menu) {
|
|||||||
|
|
||||||
// 创建 el-submenu
|
// 创建 el-submenu
|
||||||
export function elSubmenu (createElement, menu) {
|
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 ? [
|
...menu.icon ? [
|
||||||
createElement('i', { slot: 'title', attrs: { class: `fa fa-${menu.icon}` } })
|
createElement('i', { slot: 'title', attrs: { class: `fa fa-${menu.icon}` } })
|
||||||
] : [],
|
] : [],
|
||||||
|
|||||||
@@ -45,14 +45,9 @@ export default {
|
|||||||
}, 500)
|
}, 500)
|
||||||
},
|
},
|
||||||
// 监听路由 控制侧边栏激活状态
|
// 监听路由 控制侧边栏激活状态
|
||||||
'$route': {
|
'$route.fullPath': {
|
||||||
handler ({ fullPath }) {
|
handler (value) {
|
||||||
this.active = fullPath
|
this.active = value
|
||||||
this.$nextTick(() => {
|
|
||||||
if (this.aside.length > 0 && this.$refs.menu) {
|
|
||||||
this.$refs.menu.activeIndex = fullPath
|
|
||||||
}
|
|
||||||
})
|
|
||||||
},
|
},
|
||||||
immediate: true
|
immediate: true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,22 @@
|
|||||||
|
import { uniqueId } from 'lodash'
|
||||||
// 设置文件
|
// 设置文件
|
||||||
import setting from '@/setting.js'
|
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 {
|
export default {
|
||||||
namespaced: true,
|
namespaced: true,
|
||||||
state: {
|
state: {
|
||||||
@@ -77,7 +93,7 @@ export default {
|
|||||||
*/
|
*/
|
||||||
headerSet (state, menu) {
|
headerSet (state, menu) {
|
||||||
// store 赋值
|
// store 赋值
|
||||||
state.header = menu
|
state.header = supplementMenuPath(menu)
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* @description 设置侧边栏菜单
|
* @description 设置侧边栏菜单
|
||||||
@@ -86,7 +102,7 @@ export default {
|
|||||||
*/
|
*/
|
||||||
asideSet (state, menu) {
|
asideSet (state, menu) {
|
||||||
// store 赋值
|
// store 赋值
|
||||||
state.aside = menu
|
state.aside = supplementMenuPath(menu)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user