Skip to content

Commit 3de82cd

Browse files
committed
菜单组件
1 parent c884eaf commit 3de82cd

File tree

14 files changed

+188
-62
lines changed

14 files changed

+188
-62
lines changed

src/assets/less/common.less

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ body{
141141
right: 0;
142142
z-index: 99;
143143
.el-tabs{
144-
.el-tabs__item{
144+
.el-tabs__header .el-tabs__nav .el-tabs__item{
145145
height: 30px;
146146
line-height: 30px;
147147
font-size: 12px;
@@ -163,6 +163,9 @@ body{
163163
font-size: 12px;
164164
color: #606266;
165165
}
166+
.el-breadcrumb__separator{
167+
margin: 0 2px;
168+
}
166169
}
167170
}
168171
.el-tabs__nav-next, .el-tabs__nav-prev{

src/assets/less/theme.less

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
background-color: @color;
3636
}
3737
.menu-theme{
38+
width: @menu-width;
3839
.menu-list:not(.el-menu--collapse) {
3940
width: @menu-width;
4041
}

src/components/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import routerTab from "./router-tab.vue";
1+
import MenuTree from "./menu-tree.vue";
22

33
// 导出组件
44
export {
5-
routerTab
5+
MenuTree
66
}

src/components/menu-tree.vue

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<template>
2+
<div>
3+
<template v-for="item in menuLIst">
4+
<el-submenu v-if="item.children && item.children.length" :key="item.index" :index="item.index">
5+
<template slot="title">
6+
<span>{{item.label}}</span>
7+
</template>
8+
<MenuTree :menuLIst="item.children" @clickMenuItem="clickMenu"></MenuTree>
9+
</el-submenu>
10+
<el-menu-item v-else :key="item.index" :index="item.index" @click="goto(item)">{{item.label}}</el-menu-item>
11+
</template>
12+
</div>
13+
</template>
14+
<script>
15+
export default {
16+
props: ['menuLIst'],
17+
name: 'MenuTree',
18+
methods: {
19+
goto (item) {
20+
this.$emit('clickMenuItem', item);
21+
},
22+
clickMenu(item){
23+
this.goto(item);
24+
}
25+
}
26+
}
27+
</script>

src/store/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import demo from './modules/demo'
22
import routerTab from './modules/router-tab'
3+
import menuList from './modules/menu-list'
34

45
export default {
56
demo,
6-
routerTab
7+
routerTab,
8+
menuList
79
}

src/store/modules/menu-list.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import { MENU_LIST } from '../mutations'
2+
3+
const state = {
4+
list: [
5+
{ moduleName: '学校管理', menuList: []},
6+
{ moduleName: '教务管理', menuList: [
7+
{ index: '1', label: '学生管理', children: [
8+
{ index: '1-1', label: '学生信息', name: 'demoList', path: '/demo/list' }, // 注意:必须与路由router的name、path对应
9+
{ index: '1-2', label: 'test', children: [
10+
{ index: '1-2-1', label: 'test_1', name: 'test_1', path: '/demo/test_1' }
11+
]}]
12+
}
13+
]},
14+
{ moduleName: '教职工管理', menuList: [
15+
{ index: '1', label: '学生管理', children: [
16+
{ index: '1-1', label: 'test_2', name: 'test_2', path: '/demo/test_2' }]
17+
}
18+
]},
19+
{ moduleName: '行政办公', menuList: []},
20+
],
21+
activeModuleName: '',
22+
activeMenuIndex: '-1'
23+
24+
}
25+
26+
const getters = {
27+
// 模块名数组
28+
modules: () => {
29+
return state.list.map(item => item.moduleName)
30+
},
31+
// 获取相应模块下的菜单列表
32+
menuList: () => {
33+
let current = state.list.filter(item => item.moduleName === state.activeModuleName);
34+
return current.length ? current[0].menuList : [];
35+
},
36+
}
37+
38+
const mutations = {
39+
// 设置当前的模块名
40+
[MENU_LIST.SET_ACTICE_MODULE_NAME] (state, moduleName) {
41+
state.activeModuleName = moduleName;
42+
},
43+
// 设置当前菜单的index
44+
[MENU_LIST.SET_ACTICE_MENU_INDEX] (state, menuIndex) {
45+
state.activeMenuIndex = menuIndex;
46+
},
47+
}
48+
49+
export default {
50+
state,
51+
getters,
52+
mutations
53+
}

src/store/modules/router-tab.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ const state = {
77

88
const mutations = {
99
// 添加tabs
10-
[ROUTER_TAB.ADD] (state, data) {
10+
[ROUTER_TAB.ROUTER_ADD] (state, data) {
1111
state.openTab.push(data);
1212
},
1313
// 删除tabs
14-
[ROUTER_TAB.DELETE] (state, path) {
14+
[ROUTER_TAB.ROUTER_DELETE] (state, path) {
1515
let index = 0;
1616
for (let option of state.openTab) {
1717
if (option.path === path) {
@@ -22,11 +22,11 @@ const mutations = {
2222
state.openTab.splice(index, 1);
2323
},
2424
// 清空tabs
25-
[ROUTER_TAB.CLEAR] (state) {
25+
[ROUTER_TAB.ROUTER_CLEAR] (state) {
2626
state.openTab = [];
2727
},
2828
// 设置当前激活的tab
29-
[ROUTER_TAB.SET_ACTICE_INDEX] (state, index) {
29+
[ROUTER_TAB.SET_ACTICE_ROUTER_INDEX] (state, index) {
3030
state.activeIndex = index;
3131
},
3232
}

src/store/mutations.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,14 @@ export const DEMO = {
33
}
44

55
export const ROUTER_TAB = {
6-
ADD: 'add',
7-
DELETE: 'delete',
8-
CLEAR: 'clear',
9-
SET_ACTICE_INDEX: 'set_active_index',
6+
ROUTER_ADD: 'router_add',
7+
ROUTER_DELETE: 'router_delete',
8+
ROUTER_CLEAR: 'router_clear',
9+
SET_ACTICE_ROUTER_INDEX: 'set_active_router_index',
1010
}
11+
12+
export const MENU_LIST = {
13+
SET_ACTICE_MODULE_NAME: 'set_active_module_name',
14+
SET_ACTICE_MENU_INDEX: 'set_active_menu_index',
15+
}
16+

src/views/common/container.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
</div>
1818
</template>
1919
<script>
20-
import { routerTab } from "../../components";
20+
import routerTab from "./router-tab";
2121
import navigationBar from './navigationBar'
2222
import menuAside from './menuAside'
2323
export default {

src/views/common/login.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
</div>
3030
</template>
3131
<script>
32+
import { MENU_LIST } from "../../store/mutations.js";
3233
export default {
3334
data () {
3435
return {

0 commit comments

Comments
 (0)