LeftSideMenuLv2Item.vue
3.28 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
<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">
<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'],
data() {
return {
menus: []
}
},
computed: {
...mapGetters(['app', 'menu'])
},
watch: {
'menu.isCollapse': {
handler(n) {
!n && this.reload()
}
},
current: {
handler() {
this.reload()
}
}
},
mounted() {
this.bus.$on('menuChanged', this.handleMenuChanged)
!this.menu.isCollapse && this.reload()
},
beforeDestroy() {
this.bus.$off('menuChanged', this.handleMenuChanged)
},
methods: {
handleModuleClick(menu) {
this.$router.push(menu.path)
},
isMenuNoChildren({ children = [] }) {
return children.noHidden().length == 0
},
handleMenuChanged({ menus = [], isReload = false }) {
if (isReload) {
this.reload()
return
}
// console.log('待修改:'+menus[0]?.title , '当前,'+this.menus[0]?.title);
if (this.menus[0]?.id == menus[0]?.id) return
this.menus = menus
// console.log(JSON.stringify(menus))
this.bus.$emit('menuOpenedsChanged', { menus })
},
reload() {
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;
/deep/.el-submenu {
height: 100%;
border-radius: 4px;
.el-menu {
width: 144px !important;
}
// padding: 0 8px;
&__title {
height: 36px;
line-height: 36px;
background-color: transparent !important;
padding: 0 8px !important;
&:hover {
// background-color: #fff !important;
span,
i {
color: $main-color !important;
}
}
span {
font-size: 16px;
color: #444;
font-weight: 600;
}
.el-submenu__icon-arrow {
right: 0;
}
}
&.is-active {
.el-submenu__title {
background-color: transparent !important;
span,
i {
color: $main-color !important;
}
}
}
&.active {
@include menu-highlight;
span {
color: $main-color !important;
}
}
}
}
</style>