index.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <template>
  2. <div :class="{'has-logo':showLogo}" :style="{ backgroundColor: settings.sideTheme === 'theme-dark' ? variables.menuBackground : variables.menuLightBackground }">
  3. <logo v-if="showLogo" :collapse="isCollapse" />
  4. <el-scrollbar :class="settings.sideTheme" wrap-class="scrollbar-wrapper">
  5. <el-menu
  6. :default-active="activeMenu"
  7. :collapse="isCollapse"
  8. :background-color="settings.sideTheme === 'theme-dark' ? variables.menuBackground : variables.menuLightBackground"
  9. :text-color="settings.sideTheme === 'theme-dark' ? variables.menuColor : variables.menuLightColor"
  10. :unique-opened="true"
  11. :active-text-color="settings.theme"
  12. :collapse-transition="false"
  13. mode="vertical"
  14. >
  15. <sidebar-item
  16. v-for="(route, index) in sidebarRouters"
  17. :key="route.path + index"
  18. :item="route"
  19. :base-path="route.path"
  20. />
  21. </el-menu>
  22. </el-scrollbar>
  23. </div>
  24. </template>
  25. <script>
  26. import { mapGetters, mapState } from "vuex";
  27. import Logo from "./Logo";
  28. import SidebarItem from "./SidebarItem";
  29. import variables from "@/assets/styles/variables.scss";
  30. export default {
  31. components: { SidebarItem, Logo },
  32. computed: {
  33. ...mapState(["settings"]),
  34. ...mapGetters(["sidebarRouters", "sidebar"]),
  35. activeMenu() {
  36. const route = this.$route;
  37. const { meta, path } = route;
  38. // if set path, the sidebar will highlight the path you set
  39. if (meta.activeMenu) {
  40. return meta.activeMenu;
  41. }
  42. return path;
  43. },
  44. showLogo() {
  45. return this.$store.state.settings.sidebarLogo;
  46. },
  47. variables() {
  48. return variables;
  49. },
  50. isCollapse() {
  51. return !this.sidebar.opened;
  52. }
  53. },
  54. created() {
  55. }
  56. };
  57. </script>
  58. <style lang="scss" scoped>
  59. @import "@/assets/styles/variables.scss";
  60. .scrollbar-wrapper {
  61. height: calc(100% - 50px);
  62. .menu-wrapper {
  63. display: flex;
  64. height: 100%;
  65. .menu-main {
  66. width: $base-sidebar-width;
  67. border-right: 1px solid #dcdfe6;
  68. .el-menu {
  69. border-right: none;
  70. }
  71. }
  72. .menu-sub {
  73. width: $base-sidebar-width;
  74. border-right: 1px solid #dcdfe6;
  75. background-color: #fff;
  76. .el-menu {
  77. border-right: none;
  78. }
  79. }
  80. }
  81. }
  82. // 处理折叠状态
  83. .el-menu--collapse {
  84. width: 54px !important;
  85. }
  86. :deep(.el-scrollbar__wrap) {
  87. overflow-x: hidden !important;
  88. }
  89. // 优化菜单项样式
  90. .el-menu-item {
  91. display: flex;
  92. align-items: center;
  93. .svg-icon {
  94. margin-right: 10px;
  95. }
  96. }
  97. </style>