index.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <template>
  2. <div>
  3. <div
  4. :class="{ 'has-logo': showLogo, }"
  5. :style="{
  6. backgroundColor:
  7. settings.sideTheme === 'theme-dark' ? '#f0f2f5' : '#ffffff',
  8. }"
  9. >
  10. <logo v-if="showLogo" :collapse="isCollapse" />
  11. <div class="scro">
  12. <el-scrollbar :class="settings.sideTheme" wrap-class="scrollbar-wrapper">
  13. <el-menu
  14. :default-active="activeMenu"
  15. :collapse="isCollapse"
  16. :background-color="
  17. settings.sideTheme === 'theme-dark' ? '#f0f2f5' : '#ffffff'
  18. "
  19. :text-color="
  20. settings.sideTheme === 'theme-dark' ? '#bfcbd9' : 'rgba(0,0,0,.70)'
  21. "
  22. :unique-opened="true"
  23. :active-text-color="settings.theme"
  24. :collapse-transition="false"
  25. mode="vertical"
  26. >
  27. <sidebar-item
  28. v-for="(route, index) in sidebarRouters"
  29. :key="route.path + index"
  30. :item="route"
  31. :base-path="'/' + route.path"
  32. />
  33. </el-menu>
  34. </el-scrollbar>
  35. </div>
  36. <div class="bottomBox">
  37. <hamburger
  38. id="hamburger-container"
  39. :is-active="sidebar.opened"
  40. class="hamburger-container"
  41. @toggleClick="toggleSideBar"
  42. />
  43. </div>
  44. </div>
  45. </div>
  46. </template>
  47. <script>
  48. import { mapGetters, mapState } from "vuex";
  49. import Logo from "./Logo";
  50. import SidebarItem from "./SidebarItem";
  51. import Hamburger from "@/components/Hamburger";
  52. export default {
  53. components: { SidebarItem, Logo, Hamburger },
  54. computed: {
  55. ...mapState(["settings"]),
  56. ...mapGetters(["sidebarRouters", "sidebar"]),
  57. activeMenu() {
  58. const route = this.$route;
  59. const { meta, path } = route;
  60. // if set path, the sidebar will highlight the path you set
  61. if (meta.activeMenu) {
  62. return meta.activeMenu;
  63. }
  64. return path;
  65. },
  66. showLogo() {
  67. return this.$store.state.settings.sidebarLogo;
  68. },
  69. isCollapse() {
  70. return !this.sidebar.opened;
  71. },
  72. },
  73. methods: {
  74. toggleSideBar() {
  75. this.$store.dispatch("app/toggleSideBar");
  76. },
  77. },
  78. };
  79. </script>
  80. <style lang="scss" scoped>
  81. .hamburger {
  82. width: 100%;
  83. height: 100%;
  84. background-color: #f0f2f5;
  85. }
  86. .scro {
  87. position: relative;
  88. height: 90vh;
  89. width: 100%;
  90. overflow-y: auto !important;
  91. }
  92. .bottomBox {
  93. // position: absolute;
  94. position: relative;
  95. width: 100%;
  96. margin-top: 10px;
  97. padding-left: 10px;
  98. bottom: 2%;
  99. border-top: #ccc;
  100. .hamburger-container {
  101. // text-align: center;
  102. cursor: pointer;
  103. transition: background 0.3s;
  104. -webkit-tap-highlight-color: transparent;
  105. &:hover {
  106. background: rgba(0, 0, 0, 0.025);
  107. }
  108. }
  109. }
  110. </style>