Skip to content

Commit

Permalink
fix: 修复菜单自动折叠的 bug
Browse files Browse the repository at this point in the history
fix #229
  • Loading branch information
FairyEver committed Apr 19, 2020
1 parent 2de8a8b commit 06f1acf
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 27 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"countup.js": "^2.0.4",
"dayjs": "^1.8.17",
"echarts": "^4.5.0",
"element-ui": "^2.13.0",
"element-ui": "^2.13.1",
"flex.css": "^1.1.7",
"fuse.js": "^3.4.6",
"github-markdown-css": "^3.0.1",
Expand Down
25 changes: 21 additions & 4 deletions src/menu/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { uniqueId } from 'lodash'

// 插件
import demoPlugins from './modules/demo-plugins'
// 组件
Expand All @@ -15,8 +17,23 @@ import demoD2Crud from './modules/demo-d2-crud'
// 第三方网页
import demoFrame from './modules/demo-frame'

/**
* @description 给菜单数据补充上 path 字段
* @description https://github.com/d2-projects/d2-admin/issues/209
* @param {Array} menu 原始的菜单数据
*/
function supplementPath (menu) {
return menu.map(e => ({
...e,
path: e.path || uniqueId('d2-menu-empty-'),
...e.children ? {
children: supplementPath(e.children)
} : {}
}))
}

// 菜单 侧边栏
export const menuAside = [
export const menuAside = supplementPath([
demoComponents,
demoPlugins,
demoCharts,
Expand All @@ -25,10 +42,10 @@ export const menuAside = [
demoBusiness,
demoD2Crud,
demoFrame
]
])

// 菜单 顶栏
export const menuHeader = [
export const menuHeader = supplementPath([
{
path: '/index',
title: '首页',
Expand Down Expand Up @@ -60,4 +77,4 @@ export const menuHeader = [
},
demoPlayground,
demoBusiness
]
])
20 changes: 2 additions & 18 deletions src/store/modules/d2admin/modules/menu.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,6 @@
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: {
Expand Down Expand Up @@ -93,7 +77,7 @@ export default {
*/
headerSet (state, menu) {
// store 赋值
state.header = supplementMenuPath(menu)
state.header = menu
},
/**
* @description 设置侧边栏菜单
Expand All @@ -102,7 +86,7 @@ export default {
*/
asideSet (state, menu) {
// store 赋值
state.aside = supplementMenuPath(menu)
state.aside = menu
}
}
}
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3980,10 +3980,10 @@ element-resize-detector@^1.1.15:
dependencies:
batch-processor "^1.0.0"

element-ui@^2.13.0:
version "2.13.0"
resolved "https://registry.yarnpkg.com/element-ui/-/element-ui-2.13.0.tgz#f6bb04e5b0a76ea5f62466044b774407ba4ebd2d"
integrity sha512-KYsHWsBXYbLELS8cdfvgJTOMSUby3UEjvsPV1V1VmgJ/DdkOAS4z3MiOrPxrT9w2Cc5lZ4eVSQiGhYFR5NVChw==
element-ui@^2.13.1:
version "2.13.1"
resolved "https://registry.yarnpkg.com/element-ui/-/element-ui-2.13.1.tgz#0cb1a45cf27aa61c601defbe192740ac5cb9df7c"
integrity sha512-jyvJmXa2c6ElRc4NOw4V1vnjHsvfzTRhbwElZ68CyF9by2F64B+AJRzujg/HJgXCimHwd2g1Av9D04EP3mWymg==
dependencies:
async-validator "~1.8.1"
babel-helper-vue-jsx-merge-props "^2.0.0"
Expand Down

0 comments on commit 06f1acf

Please sign in to comment.