LeftSideMenuLv2Item.vue
4.26 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>
<div class="com-left-side-menu-lv2-item">
<div v-for="item in menus" :key="item.id">
<!-- 没有三级级菜单的二级菜单 -->
<div class="el-submenu" :class="{ active: `${current.lv1}-${current.lv2}` == item.id }" v-if="isMenuNoChildren(item)" @click.stop="handleModuleClick(item)">
<div class="el-submenu__title hasNoChild">
<span>{{ item.title }}</span>
</div>
</div>
<!-- 有三级菜单的二级菜单 -->
<el-submenu v-else :index="item.id">
<span slot="title">{{ item.title }}</span>
<!-- 渲染三级菜单 -->
<LeftSideMenuLv3 :menuItems="item.children"></LeftSideMenuLv3>
</el-submenu>
</div>
</div>
</template>
<script>
import { mapGetters } from 'vuex'
import { currentId } from './mixins/index'
export default {
name: 'LeftSideMenuLv2Item',
mixins: [currentId],
inject: ['bus', 'isPop'],
props: {
isPop: {
type: Boolean,
default: false
}
},
data() {
return {
menus: []
}
},
computed: {
...mapGetters(['app', 'menu'])
},
watch: {
'menu.isCollapse': {
handler() {
this.reload()
}
},
current: {
handler() {
this.reload()
}
}
},
mounted() {
this.bus.$on('menuChanged', this.handleMenuChanged)
this.reload()
},
beforeDestroy() {
this.bus.$off('menuChanged', this.handleMenuChanged)
},
methods: {
handleModuleClick({ path, id }) {
const { lv1, lv2 } = this.current
if (id == `${lv1}-${lv2}`) return
if (path && path.startsWith('/') && !path.startsWith('/^')) {
this.$router.push(path)
}
this.bus.$emit('menu3Changed', [])
},
isMenuNoChildren({ children = [] }) {
return children.noHidden().length == 0
},
handleMenuChanged({ menus = [], isReload = false }) {
// 如果是菜单收起状态 并且不是 popover 或者待更新的数据与当前数据想同 则不更新视图
if (this.menus[0]?.id == menus[0]?.id) return
if (isReload) {
this.reload()
return
}
this.menus = menus
this.bus.$emit('menuOpenedsChanged', { menus })
},
reload() {
if (this.menu.isCollapse || this.isPop) return
const { lv1 } = this.current
const [pid] = this.menus[0]?.id.split('-') || []
if (lv1 == pid) return
const menus = this.app.menuList.find(({ id }) => id == lv1).children.noHidden()
this.handleMenuChanged({ menus })
}
}
}
</script>
<style lang="scss" scoped>
@import '~@/assets/style/collapse.scss';
@import '~@/assets/style/mixins.scss';
// $active-background-color: rgba(88, 80, 255, 0.2) !important;
.com-left-side-menu-lv2-item {
height: 100%;
padding: 8px;
::v-deep.el-submenu {
height: 100%;
border-radius: 4px;
.el-menu {
width: 144px !important;
}
&.is-opened {
.el-icon-arrow-down {
transform: rotate(90deg);
}
}
// padding: 0 8px;
&__title {
height: 36px;
line-height: 36px;
background-color: transparent !important;
padding: 0 0 0 24px !important;
margin-bottom: 1px;
span {
-webkit-text-stroke: 0.2px #333;
// text-shadow: 0 0 1px #666;
// filter: drop-shadow(0 0 0.2px #ccc);
@include menu-title-span-haspage;
}
.el-icon-arrow-down {
left: 2px;
right: unset;
margin-top: -6px;
&::before {
content: '\e791';
}
}
// &:not(.hasNoChild) {
// // has children title
// cursor: default !important;
// border-bottom: 1px solid #eee;
// span {
// font-size: 13px !important;
// color: #999 !important;
// font-weight: 400 !important;
// cursor: default !important;
// }
// }
&.hasNoChild:hover {
@include menu-title-hover;
}
}
// &.is-active {
// .el-submenu__title {
// background-color: transparent !important;
// span,
// i {
// color: $main-color !important;
// }
// }
// }
&.active {
@include menu-highlight;
span {
-webkit-text-stroke-color: $main-color;
color: $main-color !important;
}
}
}
}
</style>