From c1719929cb4238ca1fb30cceb13823b6d9134b43 Mon Sep 17 00:00:00 2001 From: Pan Date: Wed, 30 Jan 2019 14:18:01 +0800 Subject: [PATCH] perf[Style]: optimize the sidebar style to make it better to set --- src/styles/sidebar.scss | 54 ++++++++++++------- src/styles/variables.scss | 21 +++++++- src/views/layout/components/Sidebar/index.vue | 10 ++-- 3 files changed, 63 insertions(+), 22 deletions(-) diff --git a/src/styles/sidebar.scss b/src/styles/sidebar.scss index 422e617..ce619fd 100644 --- a/src/styles/sidebar.scss +++ b/src/styles/sidebar.scss @@ -1,6 +1,6 @@ #app { - // 主体区域 + // 主体区域 Main container .main-container { min-height: 100%; transition: margin-left .28s; @@ -8,7 +8,7 @@ position: relative; } - // 侧边栏 + // 侧边栏 Sidebar container .sidebar-container { transition: width 0.28s; width: $sideBarWidth !important; @@ -26,10 +26,6 @@ transition: 0s width ease-in-out, 0s padding-left ease-in-out, 0s padding-right ease-in-out; } - .el-scrollbar__bar.is-vertical { - right: 0px; - } - .scrollbar-wrapper { overflow-x: hidden !important; @@ -38,6 +34,10 @@ } } + .el-scrollbar__bar.is-vertical { + right: 0px; + } + .is-horizontal { display: none; } @@ -58,8 +58,26 @@ width: 100% !important; } + // menu hover + .submenu-title-noDropdown, + .el-submenu__title { + &:hover { + background-color: $menuHover !important; + } + } + .is-active>.el-submenu__title { - color: #f4f4f5 !important; + color: $subMenuActiveText !important; + } + + & .nest-menu .el-submenu>.el-submenu__title, + & .el-submenu .el-menu-item { + min-width: $sideBarWidth !important; + background-color: $subMenuBg !important; + + &:hover { + background-color: $subMenuHover !important; + } } } @@ -108,21 +126,11 @@ } } - .sidebar-container .nest-menu .el-submenu>.el-submenu__title, - .sidebar-container .el-submenu .el-menu-item { - min-width: $sideBarWidth !important; - background-color: $subMenuBg !important; - - &:hover { - background-color: $menuHover !important; - } - } - .el-menu--collapse .el-menu .el-submenu { min-width: $sideBarWidth !important; } - //适配移动端 + // 适配移动端, Mobile responsive .mobile { .main-container { margin-left: 0px; @@ -135,6 +143,7 @@ &.hideSidebar { .sidebar-container { + pointer-events: none; transition-duration: 0.3s; transform: translate3d(-$sideBarWidth, 0, 0); } @@ -150,10 +159,19 @@ } } +// when menu collapsed .el-menu--vertical { &>.el-menu { .svg-icon { margin-right: 16px; } } + + .nest-menu .el-submenu>.el-submenu__title, + .el-menu-item { + &:hover { + // You can use $subMenuHover + background-color: $menuHover !important; + } + } } diff --git a/src/styles/variables.scss b/src/styles/variables.scss index f68216e..3bd185f 100644 --- a/src/styles/variables.scss +++ b/src/styles/variables.scss @@ -1,5 +1,24 @@ //sidebar +$menuText:#bfcbd9; +$menuActiveText:#409EFF; +$subMenuActiveText:#f4f4f5; //https://github.com/ElemeFE/element/issues/12951 + $menuBg:#304156; +$menuHover:#263445; + $subMenuBg:#1f2d3d; -$menuHover:#001528; +$subMenuHover:#001528; + $sideBarWidth: 180px; + +// the :export directive is the magic sauce for webpack +:export { + menuText: $menuText; + menuActiveText: $menuActiveText; + subMenuActiveText: $subMenuActiveText; + menuBg: $menuBg; + menuHover: $menuHover; + subMenuBg: $subMenuBg; + subMenuHover: $subMenuHover; + sideBarWidth: $sideBarWidth; +} diff --git a/src/views/layout/components/Sidebar/index.vue b/src/views/layout/components/Sidebar/index.vue index 75a6d06..467f812 100644 --- a/src/views/layout/components/Sidebar/index.vue +++ b/src/views/layout/components/Sidebar/index.vue @@ -4,10 +4,10 @@ :show-timeout="200" :default-active="$route.path" :collapse="isCollapse" + :background-color="variables.menuBg" + :text-color="variables.menuText" + :active-text-color="variables.menuActiveText" mode="vertical" - background-color="#304156" - text-color="#bfcbd9" - active-text-color="#409EFF" > @@ -16,6 +16,7 @@