index.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <template>
  2. <div
  3. :class="{ 'has-logo': showLogo }"
  4. :style="{
  5. backgroundColor:
  6. settings.sideTheme === 'theme-dark'
  7. ? variables.menuBackground
  8. : variables.menuLightBackground,
  9. }"
  10. >
  11. <logo v-if="showLogo" :collapse="isCollapse" />
  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'
  18. ? variables.menuBackground
  19. : variables.menuLightBackground
  20. "
  21. :text-color="
  22. settings.sideTheme === 'theme-dark'
  23. ? variables.menuColor
  24. : variables.menuLightColor
  25. "
  26. :unique-opened="true"
  27. :active-text-color="settings.theme"
  28. :collapse-transition="false"
  29. mode="vertical"
  30. menu-trigger="click"
  31. >
  32. <!-- 左侧菜单bug menu-trigger="click" -->
  33. <sidebar-item
  34. v-for="(route, index) in sidebarRouters"
  35. :key="route.path + index"
  36. :item="route"
  37. :base-path="route.path"
  38. />
  39. </el-menu>
  40. </el-scrollbar>
  41. </div>
  42. </template>
  43. <script>
  44. import { mapGetters, mapState } from "vuex";
  45. import Logo from "./Logo";
  46. import SidebarItem from "./SidebarItem";
  47. import variables from "@/assets/styles/variables.scss";
  48. export default {
  49. components: { SidebarItem, Logo },
  50. data() {
  51. return {
  52. isCollapse: false,
  53. };
  54. },
  55. computed: {
  56. ...mapState(["settings"]),
  57. ...mapGetters(["sidebarRouters", "sidebar"]),
  58. activeMenu() {
  59. const route = this.$route;
  60. const { meta, path } = route;
  61. // if set path, the sidebar will highlight the path you set
  62. if (meta.activeMenu) {
  63. return meta.activeMenu;
  64. }
  65. return path;
  66. },
  67. showLogo() {
  68. return this.$store.state.settings.sidebarLogo;
  69. },
  70. variables() {
  71. return variables;
  72. },
  73. // isCollapse() {
  74. // // return !this.sidebar.opened;
  75. // // return true
  76. // return false;
  77. // },
  78. },
  79. methods: {
  80. onLayoutResize() {
  81. console.log("resize");
  82. const clientWidth = document.documentElement.clientWidth;
  83. if (clientWidth < 1000) {
  84. this.isCollapse = true;
  85. } else {
  86. this.isCollapse = false;
  87. }
  88. },
  89. },
  90. mounted() {
  91. window.addEventListener("resize", this.onLayoutResize);
  92. },
  93. onUnmounted() {
  94. window.removeEventListener("resize");
  95. },
  96. };
  97. </script>