From 51313d7116c7ab2ded7e3a65514ea9ac413edecd Mon Sep 17 00:00:00 2001
From: chenkl <321200875@qq.com>
Date: Tue, 15 Dec 2020 17:22:34 +0800
Subject: [PATCH] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20=E9=87=8D=E6=9E=84sider?=
=?UTF-8?q?=E7=BB=84=E4=BB=B6=E4=B8=AD?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/components/Hamburger/index.vue | 36 ++-
src/components/Logo/index.vue | 2 +-
src/components/Sider/Item.vue | 34 +++
src/components/Sider/Link.vue | 27 ++
src/components/Sider/SiderItem.vue | 89 ++++++-
src/components/Sider/index.vue | 78 ++++--
.../index/layout/components/Silder/Item.vue | 4 +-
src/pages/index/layout/modules/Test.vue | 77 ++++--
src/pages/index/router/index.ts | 118 ++++-----
src/pages/index/store/modules/app.ts | 2 +-
src/pages/index/views/level/Menu111.vue | 2 +-
src/pages/index/views/level/Menu12.vue | 2 +-
src/pages/index/views/level/Menu2.vue | 2 +-
src/styles/index.less | 1 +
src/styles/sidebar.less | 234 ++++++++++++++++++
src/styles/variables.less | 30 ++-
src/styles/variables.less.d.ts | 14 ++
17 files changed, 613 insertions(+), 139 deletions(-)
create mode 100644 src/components/Sider/Item.vue
create mode 100644 src/components/Sider/Link.vue
create mode 100644 src/styles/sidebar.less
create mode 100644 src/styles/variables.less.d.ts
diff --git a/src/components/Hamburger/index.vue b/src/components/Hamburger/index.vue
index b97fbc2..d4ea57d 100644
--- a/src/components/Hamburger/index.vue
+++ b/src/components/Hamburger/index.vue
@@ -1,27 +1,23 @@
diff --git a/src/components/Logo/index.vue b/src/components/Logo/index.vue
index 14d8d76..3df1095 100644
--- a/src/components/Logo/index.vue
+++ b/src/components/Logo/index.vue
@@ -50,7 +50,7 @@ export default defineComponent({
padding-left: 18px;
cursor: pointer;
height: @topSilderHeight;
- max-width: 200px;
+ width: 100%;
img {
width: 37px;
height: 37px;
diff --git a/src/components/Sider/Item.vue b/src/components/Sider/Item.vue
new file mode 100644
index 0000000..0931df7
--- /dev/null
+++ b/src/components/Sider/Item.vue
@@ -0,0 +1,34 @@
+
+
+
+
+
+ {{ title }}
+
+
+
+
+
+
+
diff --git a/src/components/Sider/Link.vue b/src/components/Sider/Link.vue
new file mode 100644
index 0000000..54357fa
--- /dev/null
+++ b/src/components/Sider/Link.vue
@@ -0,0 +1,27 @@
+
+
+
+
+
+
+
+
+
+
diff --git a/src/components/Sider/SiderItem.vue b/src/components/Sider/SiderItem.vue
index 4201901..35716c0 100644
--- a/src/components/Sider/SiderItem.vue
+++ b/src/components/Sider/SiderItem.vue
@@ -1,11 +1,94 @@
-
+
+
+
+
+
+ {{ onlyOneChild.meta.title }}
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/components/Sider/index.vue b/src/components/Sider/index.vue
index b2fe396..6c9a3fb 100644
--- a/src/components/Sider/index.vue
+++ b/src/components/Sider/index.vue
@@ -1,21 +1,27 @@
-
-
-
-
-
-
-
+
+
+
+
+
diff --git a/src/pages/index/router/index.ts b/src/pages/index/router/index.ts
index 67a32d4..0ef4c09 100644
--- a/src/pages/index/router/index.ts
+++ b/src/pages/index/router/index.ts
@@ -357,65 +357,65 @@ export const asyncRouterMap: AppRouteRecordRaw[] = [
// }
// ]
// },
- // {
- // path: '/level',
- // component: Layout,
- // redirect: '/level/menu1/menu1-1/menu1-1-1',
- // name: 'Level',
- // meta: {
- // title: '多级菜单缓存',
- // icon: 'nested'
- // },
- // children: [
- // {
- // path: 'menu1',
- // name: 'Menu1Demo',
- // component: getParentLayout('Menu1Demo'),
- // redirect: '/level/menu1/menu1-1/menu1-1-1',
- // meta: {
- // title: 'Menu1'
- // },
- // children: [
- // {
- // path: 'menu1-1',
- // name: 'Menu11Demo',
- // component: getParentLayout('Menu11Demo'),
- // redirect: '/level/menu1/menu1-1/menu1-1-1',
- // meta: {
- // title: 'Menu1-1',
- // alwaysShow: true
- // },
- // children: [
- // {
- // path: 'menu1-1-1',
- // name: 'Menu111Demo',
- // component: () => import('_p/index/views/level/Menu111.vue'),
- // meta: {
- // title: 'Menu1-1-1'
- // }
- // }
- // ]
- // },
- // {
- // path: 'menu1-2',
- // name: 'Menu12Demo',
- // component: () => import('_p/index/views/level/Menu12.vue'),
- // meta: {
- // title: 'Menu1-2'
- // }
- // }
- // ]
- // },
- // {
- // path: 'menu2',
- // name: 'Menu2Demo',
- // component: () => import('_p/index/views/level/Menu2.vue'),
- // meta: {
- // title: 'Menu2'
- // }
- // }
- // ]
- // },
+ {
+ path: '/level',
+ component: Layout,
+ redirect: '/level/menu1/menu1-1/menu1-1-1',
+ name: 'Level',
+ meta: {
+ title: '多级菜单缓存',
+ icon: 'nested'
+ },
+ children: [
+ {
+ path: 'menu1',
+ name: 'Menu1Demo',
+ component: getParentLayout('Menu1Demo'),
+ redirect: '/level/menu1/menu1-1/menu1-1-1',
+ meta: {
+ title: 'Menu1'
+ },
+ children: [
+ {
+ path: 'menu1-1',
+ name: 'Menu11Demo',
+ component: getParentLayout('Menu11Demo'),
+ redirect: '/level/menu1/menu1-1/menu1-1-1',
+ meta: {
+ title: 'Menu1-1',
+ alwaysShow: true
+ },
+ children: [
+ {
+ path: 'menu1-1-1',
+ name: 'Menu111Demo',
+ component: () => import('_p/index/views/level/Menu111.vue'),
+ meta: {
+ title: 'Menu1-1-1'
+ }
+ }
+ ]
+ },
+ {
+ path: 'menu1-2',
+ name: 'Menu12Demo',
+ component: () => import('_p/index/views/level/Menu12.vue'),
+ meta: {
+ title: 'Menu1-2'
+ }
+ }
+ ]
+ },
+ {
+ path: 'menu2',
+ name: 'Menu2Demo',
+ component: () => import('_p/index/views/level/Menu2.vue'),
+ meta: {
+ title: 'Menu2'
+ }
+ }
+ ]
+ },
// {
// path: '/example-demo',
// component: Layout,
diff --git a/src/pages/index/store/modules/app.ts b/src/pages/index/store/modules/app.ts
index f696715..ab571ef 100644
--- a/src/pages/index/store/modules/app.ts
+++ b/src/pages/index/store/modules/app.ts
@@ -14,7 +14,7 @@ export interface AppState {
@Module({ dynamic: true, namespaced: true, store, name: 'app' })
class App extends VuexModule implements AppState {
public collapsed = false // 菜单栏是否栏缩收
- public showLogo = true // 是否显示logo
+ public showLogo = false // 是否显示logo
public showTags = true // 是否显示标签栏
public showNavbar = true // 是否显示navbar
public fixedTags = true // 是否固定标签栏
diff --git a/src/pages/index/views/level/Menu111.vue b/src/pages/index/views/level/Menu111.vue
index c927fe1..9da4f03 100644
--- a/src/pages/index/views/level/Menu111.vue
+++ b/src/pages/index/views/level/Menu111.vue
@@ -1,7 +1,7 @@
diff --git a/src/pages/index/views/level/Menu12.vue b/src/pages/index/views/level/Menu12.vue
index 1b145ed..838b690 100644
--- a/src/pages/index/views/level/Menu12.vue
+++ b/src/pages/index/views/level/Menu12.vue
@@ -1,7 +1,7 @@
diff --git a/src/pages/index/views/level/Menu2.vue b/src/pages/index/views/level/Menu2.vue
index 113f703..ffdce95 100644
--- a/src/pages/index/views/level/Menu2.vue
+++ b/src/pages/index/views/level/Menu2.vue
@@ -1,7 +1,7 @@
diff --git a/src/styles/index.less b/src/styles/index.less
index 3f64fa1..0d2c803 100644
--- a/src/styles/index.less
+++ b/src/styles/index.less
@@ -1,4 +1,5 @@
@import '~element-plus/lib/theme-chalk/index.css';
+// @import './sidebar.less';
@import './transition.less';
@import './silder.less';
@import './glob.less';
diff --git a/src/styles/sidebar.less b/src/styles/sidebar.less
new file mode 100644
index 0000000..5693160
--- /dev/null
+++ b/src/styles/sidebar.less
@@ -0,0 +1,234 @@
+#app {
+
+ // 主体区域 Main container
+ .main-container {
+ min-height: 100%;
+ transition: margin-left .28s;
+ margin-left: @menuWidth;
+ position: relative;
+ }
+
+ // 侧边栏 Sidebar container
+ .sidebar-container {
+ transition: width 0.28s;
+ width: @menuWidth !important;
+ height: 100%;
+ position: fixed;
+ font-size: 0px;
+ top: 0;
+ bottom: 0;
+ left: 0;
+ z-index: 1001;
+ overflow: hidden;
+
+ //reset element-ui css
+ .horizontal-collapse-transition {
+ transition: 0s width ease-in-out, 0s padding-left ease-in-out, 0s padding-right ease-in-out;
+ }
+
+ .scrollbar-wrapper {
+ overflow-x: hidden !important;
+
+ .el-scrollbar__view {
+ height: 100%;
+ }
+ }
+
+ .el-scrollbar__bar.is-vertical {
+ right: 0px;
+ }
+
+ .el-scrollbar {
+ height: 100%;
+ }
+
+ &.has-logo {
+ .el-scrollbar {
+ height: calc(100% - 70px);
+ }
+ }
+
+ .is-horizontal {
+ display: none;
+ }
+
+ a {
+ display: inline-block;
+ width: 100%;
+ overflow: hidden;
+ }
+
+ .svg-icon {
+ margin-right: 16px;
+ }
+
+ .el-menu {
+ border: none;
+ height: 100%;
+ width: 100% !important;
+ }
+
+ // menu hover
+ .submenu-title-noDropdown,
+ .el-submenu__title {
+ color: hsla(0,0%,100%,.7) !important;
+ &:hover {
+ // background-color: @menuHover !important;
+ color: @subMenuActiveText !important;
+ }
+ }
+
+ .is-active>.el-submenu__title {
+ color: @subMenuActiveText !important;
+ }
+
+ .is-active {
+ color: @subMenuActiveText !important;
+ background-color: @menuActiveBg !important;
+ &:hover {
+ color: @subMenuActiveText !important;
+ background-color: @menuActiveBg !important;
+ }
+ & .el-menu-item {
+ background-color: @menuActiveBg !important;
+ &:hover {
+ color: @subMenuActiveText !important;
+ }
+ }
+ }
+
+ & .nest-menu .el-submenu>.el-submenu__title,
+ & .el-submenu .el-menu-item {
+ min-width: @menuWidth !important;
+ background-color: @subMenuBg !important;
+
+ &:hover {
+ color: @subMenuActiveText !important;
+ background-color: @subMenuHover !important;
+ }
+ }
+
+ & .nest-menu {
+ & .is-active {
+ background-color: @menuActiveBg !important;
+ &:hover {
+ color: @subMenuActiveText !important;
+ background-color: @menuActiveBg !important;
+ }
+ }
+ }
+ }
+
+ .hideSidebar {
+ .sidebar-container {
+ width: 36px !important;
+ }
+
+ .main-container {
+ margin-left: 36px;
+ }
+
+ .submenu-title-noDropdown {
+ padding-left: 10px !important;
+ position: relative;
+
+ .el-tooltip {
+ padding: 0 10px !important;
+ }
+ }
+
+ .el-submenu {
+ overflow: hidden;
+
+ &>.el-submenu__title {
+ padding-left: 10px !important;
+
+ .el-submenu__icon-arrow {
+ display: none;
+ }
+ }
+ }
+
+ .el-menu--collapse {
+ .el-submenu {
+ &>.el-submenu__title {
+ &>span {
+ height: 0;
+ width: 0;
+ overflow: hidden;
+ visibility: hidden;
+ display: inline-block;
+ }
+ }
+ }
+ }
+ }
+
+ .el-menu--collapse .el-menu .el-submenu {
+ min-width: @menuWidth !important;
+ }
+
+ // 适配移动端, Mobile responsive
+ .mobile {
+ .main-container {
+ margin-left: 0px;
+ }
+
+ .sidebar-container {
+ transition: transform .28s;
+ width: @menuWidth !important;
+ }
+
+ &.hideSidebar {
+ .sidebar-container {
+ pointer-events: none;
+ transition-duration: 0.3s;
+ transform: translate3d(-@menuWidth, 0, 0);
+ }
+ }
+ }
+
+ .withoutAnimation {
+
+ .main-container,
+ .sidebar-container {
+ transition: none;
+ }
+ }
+}
+
+// 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;
+ }
+ }
+
+ // the scroll bar appears when the subMenu is too long
+ >.el-menu--popup {
+ max-height: 100vh;
+ overflow-y: auto;
+
+ &::-webkit-scrollbar-track-piece {
+ background: #d3dce6;
+ }
+
+ &::-webkit-scrollbar {
+ width: 6px;
+ }
+
+ &::-webkit-scrollbar-thumb {
+ background: #99a9bf;
+ border-radius: 20px;
+ }
+ }
+}
diff --git a/src/styles/variables.less b/src/styles/variables.less
index 46dafb0..dc81f0f 100644
--- a/src/styles/variables.less
+++ b/src/styles/variables.less
@@ -1,15 +1,25 @@
// Silder
+@menuText: #bfcbd9;
+@menuActiveText: #409EFF;
+@menuActiveBg: #2d8cf0;
+
+@menuBg: #001529;
+
+@subMenuBg: #1f2d3d;
+@subMenuHover: #1f2d3d;
+@subMenuActiveText: #fff;
+
+@menuWidth: 200px;
+@menuMinWidth: 64px;
+
@menuLightActiveText: #1890ff;
@menuLightActiveBg: #e6f7ff;
@menuDarkActiveText: #fff;
@menuDarkActiveBg: #1890ff;
-@menuBg: #001529;
@menuLightBg: #fff;
-@menuWidth: 200px;
-
// topSilder
@topSilderHeight: 50px;
@@ -26,4 +36,16 @@
@minWidth: 992px;
// deep
-@deep: ~'::v-deep';
\ No newline at end of file
+@deep: ~'::v-deep';
+
+// the :export directive is the magic sauce for webpack
+:export {
+ menuText: @menuText;
+ menuActiveText: @menuActiveText;
+ menuActiveBg: @menuActiveBg;
+ menuBg: @menuBg;
+ subMenuBg: @subMenuBg;
+ subMenuHover: @subMenuHover;
+ menuWidth: @menuWidth;
+ menuMinWidth: @menuMinWidth;
+}
\ No newline at end of file
diff --git a/src/styles/variables.less.d.ts b/src/styles/variables.less.d.ts
new file mode 100644
index 0000000..476f596
--- /dev/null
+++ b/src/styles/variables.less.d.ts
@@ -0,0 +1,14 @@
+export interface IScssVariables {
+ menuText: string
+ menuActiveText: string
+ menuActiveBg: string
+ menuBg: string
+ subMenuBg: string
+ subMenuHover: string
+ menuWidth: string
+ menuMinWidth: string
+}
+
+export const variables: IScssVariables
+
+export default variables