index.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <template>
  2. <el-scrollbar class="side-bar-container" :class="{ 'is-collapse': collapse }">
  3. <logo />
  4. <el-menu
  5. :background-color="variables['menu-background']"
  6. :text-color="variables['menu-color']"
  7. :active-text-color="variables['menu-color-active']"
  8. :default-active="activeMenu"
  9. :collapse="collapse"
  10. :collapse-transition="false"
  11. :default-openeds="defaultOpens"
  12. :unique-opened="uniqueOpened"
  13. mode="vertical"
  14. >
  15. <template v-for="route in routes">
  16. <side-bar-item
  17. :key="route.path"
  18. :full-path="route.path"
  19. :item="route"
  20. ></side-bar-item>
  21. </template>
  22. </el-menu>
  23. </el-scrollbar>
  24. </template>
  25. <script>
  26. import { Logo } from "@/layouts/components";
  27. import SideBarItem from "./components/SideBarItem";
  28. import variables from "@/styles/variables.scss";
  29. import { mapGetters } from "vuex";
  30. import { defaultOopeneds, uniqueOpened } from "@/config/settings";
  31. export default {
  32. name: "SideBar",
  33. components: { SideBarItem, Logo },
  34. data() {
  35. return {
  36. uniqueOpened,
  37. };
  38. },
  39. computed: {
  40. ...mapGetters({
  41. collapse: "settings/collapse",
  42. routes: "routes/routes",
  43. }),
  44. defaultOpens() {
  45. if (this.collapse) {
  46. }
  47. return defaultOopeneds;
  48. },
  49. activeMenu() {
  50. const route = this.$route;
  51. const { meta, path } = route;
  52. if (meta.activeMenu) {
  53. return meta.activeMenu;
  54. }
  55. return path;
  56. },
  57. variables() {
  58. return variables;
  59. },
  60. },
  61. };
  62. </script>
  63. <style lang="scss" scoped>
  64. @mixin active {
  65. &:hover {
  66. color: $base-color-white;
  67. background-color: $base-menu-background-active !important;
  68. }
  69. &.is-active {
  70. color: $base-color-white;
  71. background-color: $base-menu-background-active !important;
  72. }
  73. }
  74. .side-bar-container {
  75. position: fixed;
  76. top: 0;
  77. bottom: 0;
  78. left: 0;
  79. z-index: $base-z-index;
  80. width: $base-left-menu-width;
  81. height: 100vh;
  82. overflow: hidden;
  83. background: $base-menu-background;
  84. box-shadow: 2px 0 6px rgba(0, 21, 41, 0.35);
  85. transition: width $base-transition-time;
  86. &.is-collapse {
  87. width: $base-left-menu-width-min;
  88. border-right: 0;
  89. ::v-deep {
  90. .el-menu {
  91. transition: width $base-transition-time;
  92. }
  93. .el-menu--collapse {
  94. border-right: 0;
  95. .el-submenu__icon-arrow {
  96. right: 10px;
  97. margin-top: -3px;
  98. }
  99. }
  100. }
  101. }
  102. ::v-deep {
  103. .el-scrollbar__wrap {
  104. overflow-x: hidden;
  105. }
  106. .el-menu {
  107. border: 0;
  108. .vab-fas-icon {
  109. padding-right: 3px;
  110. font-size: $base-font-size-default;
  111. }
  112. .vab-remix-icon {
  113. padding-right: 3px;
  114. font-size: $base-font-size-default + 2;
  115. }
  116. }
  117. .el-menu-item,
  118. .el-submenu__title {
  119. height: $base-menu-item-height;
  120. overflow: hidden;
  121. line-height: $base-menu-item-height;
  122. text-overflow: ellipsis;
  123. white-space: nowrap;
  124. vertical-align: middle;
  125. }
  126. .el-menu-item {
  127. @include active;
  128. }
  129. }
  130. }
  131. </style>