Skip to content

Commit 99d53ee

Browse files
authored
refactor[ScrollBar]: use el-scrollbar (PanJiaChen#646)
1 parent f9d510e commit 99d53ee

File tree

4 files changed

+49
-79
lines changed

4 files changed

+49
-79
lines changed

src/components/ScrollBar/index.vue

Lines changed: 0 additions & 57 deletions
This file was deleted.

src/styles/sidebar.scss

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
11
#app {
2-
32
// 主体区域
43
.main-container {
54
min-height: 100%;
65
transition: margin-left .28s;
76
margin-left: 180px;
87
}
9-
10-
// 侧边栏
8+
// 侧边栏
119
.sidebar-container {
12-
.horizontal-collapse-transition {
13-
transition: 0s width ease-in-out, 0s padding-left ease-in-out, 0s padding-right ease-in-out;
14-
}
15-
transition: width .28s;
10+
transition: width 0.28s;
1611
width: 180px !important;
1712
height: 100%;
1813
position: fixed;
@@ -22,19 +17,33 @@
2217
left: 0;
2318
z-index: 1001;
2419
overflow: hidden;
20+
//reset element-ui css
21+
.horizontal-collapse-transition {
22+
transition: 0s width ease-in-out, 0s padding-left ease-in-out, 0s padding-right ease-in-out;
23+
}
24+
.scrollbar-wrapper {
25+
height: calc(100% + 15px);
26+
.el-scrollbar__view {
27+
height: 100%;
28+
}
29+
}
30+
.is-horizontal {
31+
display: none;
32+
}
2533
a {
2634
display: inline-block;
2735
width: 100%;
36+
overflow: hidden;
2837
}
2938
.svg-icon {
3039
margin-right: 16px;
3140
}
3241
.el-menu {
3342
border: none;
43+
height: 100%;
3444
width: 100% !important;
3545
}
3646
}
37-
3847
.hideSidebar {
3948
.sidebar-container {
4049
width: 36px !important;
@@ -50,22 +59,28 @@
5059
}
5160
}
5261
.el-submenu {
62+
overflow: hidden;
5363
&>.el-submenu__title {
5464
padding-left: 10px !important;
55-
&>span {
56-
height: 0;
57-
width: 0;
58-
overflow: hidden;
59-
visibility: hidden;
60-
display: inline-block;
61-
}
6265
.el-submenu__icon-arrow {
6366
display: none;
6467
}
6568
}
6669
}
70+
.el-menu--collapse {
71+
.el-submenu {
72+
&>.el-submenu__title {
73+
&>span {
74+
height: 0;
75+
width: 0;
76+
overflow: hidden;
77+
visibility: hidden;
78+
display: inline-block;
79+
}
80+
}
81+
}
82+
}
6783
}
68-
6984
.sidebar-container .nest-menu .el-submenu>.el-submenu__title,
7085
.sidebar-container .el-submenu .el-menu-item {
7186
min-width: 180px !important;
@@ -84,7 +99,6 @@
8499
margin-left: 0px;
85100
}
86101
.sidebar-container {
87-
top: 50px;
88102
transition: transform .28s;
89103
width: 180px !important;
90104
}
@@ -95,7 +109,6 @@
95109
}
96110
}
97111
}
98-
99112
.withoutAnimation {
100113
.main-container,
101114
.sidebar-container {

src/views/layout/Layout.vue

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<template>
22
<div class="app-wrapper" :class="classObj">
3+
<div v-if="device==='mobile'&&sidebar.opened" class="drawer-bg" @click="handleClickOutside"></div>
34
<sidebar class="sidebar-container"></sidebar>
45
<div class="main-container">
56
<navbar></navbar>
@@ -36,6 +37,11 @@ export default {
3637
mobile: this.device === 'mobile'
3738
}
3839
}
40+
},
41+
methods: {
42+
handleClickOutside() {
43+
this.$store.dispatch('closeSideBar', { withoutAnimation: false })
44+
}
3945
}
4046
}
4147
</script>
@@ -48,4 +54,13 @@ export default {
4854
height: 100%;
4955
width: 100%;
5056
}
57+
.drawer-bg {
58+
background: #000;
59+
opacity: 0.3;
60+
width: 100%;
61+
top: 0;
62+
height: 100%;
63+
position: absolute;
64+
z-index: 999;
65+
}
5166
</style>

src/views/layout/components/Sidebar/index.vue

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<scroll-bar>
2+
<el-scrollbar wrapClass="scrollbar-wrapper">
33
<el-menu
44
mode="vertical"
55
:show-timeout="200"
@@ -11,16 +11,15 @@
1111
>
1212
<sidebar-item :routes="permission_routers"></sidebar-item>
1313
</el-menu>
14-
</scroll-bar>
14+
</el-scrollbar>
1515
</template>
1616

1717
<script>
1818
import { mapGetters } from 'vuex'
1919
import SidebarItem from './SidebarItem'
20-
import ScrollBar from '@/components/ScrollBar'
2120
2221
export default {
23-
components: { SidebarItem, ScrollBar },
22+
components: { SidebarItem },
2423
computed: {
2524
...mapGetters([
2625
'permission_routers',

0 commit comments

Comments
 (0)