menus.vue
4.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
<template>
<Menu theme="dark" width="auto" :accordion="true" :open-names="openNames" @on-select="open" :active-name="activeName">
<div class="layout-logo-left"></div>
<Submenu :name="purview.id" v-for="purview in purviews" :key="purview.id" >
<template slot="title">
<div class="nor">
<Icon type="ios-navigate"></Icon>
{{purview.menu_name}}
</div>
<div class="collapse">
{{purview.menu_name[0]}}
</div>
</template>
<Menu-item :name="subPurview.id" v-for="subPurview in purview.sub" :key="subPurview.id">{{subPurview.menu_name}}</Menu-item>
</Submenu>
</Menu>
</template>
<script>
import _ from 'lodash';
export default {
name: 'purview-menu',
data() {
return {
purviews: this.$oriPurviews, // TODO 根据用户权限,初始化菜单
openNames: [],
activeName: ''
};
},
created() {
this.render(_.get(this.$router, 'history.current'));
},
methods: {
render(to) {
let path = to.path;
let menu = _.find(this.$purviews, purview => purview.menu_url === path);
if (menu) {
this.activeName = menu.id;
if (menu.pMenu) {
this.openNames = [menu.pMenu.id];
}
}
},
open(menuId) {
let menu = _.find(this.$purviews, purview => purview.id === menuId);
if (menu) {
setTimeout(() => {
this.$router.push(menu.menu_url);
}, 100);
}
}
},
watch: {
$route(newRoute) {
this.render(newRoute);
}
}
};
</script>
<style lang="scss">
$collapseMenuWidth: 200px;
$collapseWidth: 50px;
$collapseLeftBorder: 2px;
@mixin submenuHover {
.ivu-menu-submenu-title {
margin-left: 0;
border-left: solid 2px #fff;
background-color: #313540 !important;
transition: border 0s;
}
}
.ivu-menu-item-group-title {
color: #9ea7b4 !important;
}
.ivu-menu-submenu-title {
.collapse {
display: none;
}
.nor {
display: inline-block;
}
}
.menu-collapse {
.layout-logo-left {
background: none;
color: #fff;
font-size: 18px;
text-align: center;
font-style: italic;
&:before {
content: "Yoho!";
}
}
.ivu-menu-submenu {
position: relative;
margin-left: 2px;
&:hover {
.ivu-menu {
display: block !important;
}
.nor {
display: block;
}
}
&:hover,
&.ivu-menu-item-active {
@include submenuHover;
}
.ivu-menu {
display: none;
position: absolute;
top: 49px;
left: $collapseWidth - $collapseLeftBorder;
z-index: 2;
width: $collapseMenuWidth;
}
}
.ivu-menu-submenu-title {
position: initial !important;
padding: 0 !important;
width: 100%;
height: $collapseWidth - $collapseLeftBorder;
justify-content: center;
align-items: center;
display: flex;
.ivu-icon-ios-arrow-down {
display: none;
}
.nor {
display: none;
position: absolute;
height: 49px;
width: $collapseMenuWidth;
left: $collapseWidth - $collapseLeftBorder;
top: 0;
background-color: #313540;
z-index: 2;
line-height: 49px;
padding-left: 43px;
color: #fff !important;
cursor: initial;
}
.collapse {
width: 30px;
height: 30px;
margin: 0 auto;
display: block;
line-height: 30px;
text-align: center;
font-size: 20px;
background-color: #fff;
color: #464c5b;
border-radius: 50%;
overflow: hidden;
}
}
}
</style>