SubMenu.vue
2.99 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
<template>
<div class="scrm-base-submenu">
<template v-for="item in subMenu">
<el-submenu v-if="isNotLv3(item)" :key="item.id" :index="item.id">
<template slot="title">
<div @mouseenter="hover(item)" @mouseleave="mouseleave">
<i class="i" :class="genClass(item)" v-if="item.icon"></i>
<span slot="title">{{ item.title }}</span>
</div>
</template>
<sub-menu :subMenu="item.children"></sub-menu>
</el-submenu>
<el-menu-item v-else :key="item.id" :index="item.id" @click="handleSelect(item)">
<span slot="title">{{ item.title }}</span>
</el-menu-item>
</template>
</div>
</template>
<script>
import { mapActions, mapGetters } from 'vuex'
export default {
name: 'SubMenu',
props: {
subMenu: {
type: Array,
required: true
}
},
data() {
return {
activeId: '',
hoverId: '',
openId: ''
}
},
computed: {
...mapGetters(['app', 'menu']),
active() {
if (this.app.currentApp) {
return this.app.currentApp.id
}
return '0'
}
},
mounted() {},
methods: {
handleSelect(item) {
if (item.path) {
this.$router.push(item.path)
}
this.setCurrentNav2(item)
},
genClass(item) {
const active = this.active == item.id || this.menu.hoverId == item.id || this.menu.openId == item.id
return `i-${active ? `${item.icon}-active` : item.icon}`
},
hover(item) {
this.setHoverId(item.id)
},
mouseleave() {
this.setHoverId('')
},
isNotLv3(item) {
// 3级菜单不在左侧menu渲染
return item.children && item.children.length > 0 && item.children[0].id.split('-').length <= 2
},
...mapActions('app', ['setCurrentNav2']),
...mapActions('menu', ['setHoverId'])
}
}
</script>
<style lang="scss" scoped>
@import '~@/assets/style/variables.scss';
$active-background-color: rgba(235, 234, 255, 1) !important;
.scrm-base-submenu {
/deep/.el-submenu {
&__title {
height: 40px;
line-height: 40px;
padding: 0 0 0 10px !important;
border-radius: 4px;
margin: 0 20px;
&:hover {
background-color: $active-background-color;
span {
color: $main-color !important;
}
}
span {
font-size: 14px;
color: #999;
letter-spacing: 0;
font-weight: 600;
margin-left: 10.8px;
}
.el-submenu__icon-arrow {
display: none;
}
}
&.is-opened {
.el-submenu__title {
background-color: $active-background-color;
span {
color: $main-color !important;
}
}
}
}
.el-menu-item {
min-width: $menu-width;
padding-left: 60px !important;
&:hover,
&.is-active {
outline: 0 !important;
color: $main-color !important;
background-color: #fff !important;
border-bottom: none;
}
&:hover {
background-color: transparent !important;
}
}
}
</style>