index.vue 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <template>
  2. <div :class="{ 'has-logo': showLogo }">
  3. <logo v-if="showLogo" :collapse="isCollapse" />
  4. <el-scrollbar wrap-class="scrollbar-wrapper">
  5. <el-menu
  6. v-if="menuList && menuList.length > 0"
  7. :default-active="activeMenu"
  8. :collapse="isCollapse"
  9. router
  10. :background-color="variables.menuBg"
  11. :text-color="variables.menuText"
  12. :active-text-color="variables.menuActiveText"
  13. :unique-opened="false"
  14. :collapse-transition="false"
  15. mode="vertical"
  16. >
  17. <el-menu-item
  18. v-for="(route, index) in menuList"
  19. :key="route.path + index"
  20. :route="route.path"
  21. :index="index + ''"
  22. >
  23. <template v-if="!route.hidden">
  24. <i :class="route.meta.icon"></i>
  25. <span slot="title">{{ route.meta.title }}</span>
  26. </template>
  27. </el-menu-item>
  28. </el-menu>
  29. </el-scrollbar>
  30. </div>
  31. </template>
  32. <script>
  33. import { mapGetters } from "vuex";
  34. import Logo from "./Logo";
  35. import variables from "@/styles/variables.scss";
  36. export default {
  37. components: {
  38. Logo,
  39. },
  40. data() {
  41. return {
  42. active: -1,
  43. menuList: [],
  44. };
  45. },
  46. computed: {
  47. ...mapGetters(["navList", "sidebar"]),
  48. activeMenu() {
  49. const route = this.$route;
  50. const { path } = route;
  51. let list = path.split("/");
  52. return (
  53. this.menuList.findIndex((v1) => v1.path === list[list.length - 1]) + ""
  54. );
  55. },
  56. showLogo() {
  57. return true;
  58. },
  59. variables() {
  60. return variables;
  61. },
  62. isCollapse() {
  63. return !true;
  64. },
  65. },
  66. watch: {
  67. $route(route) {
  68. if (route.path.startsWith("/redirect/")) {
  69. return;
  70. }
  71. this.getBreadcrumb();
  72. },
  73. },
  74. created() {
  75. this.getBreadcrumb();
  76. },
  77. methods: {
  78. getBreadcrumb() {
  79. let matched = this.$route.matched.filter(
  80. (item) => item.meta && item.meta.title
  81. );
  82. let index = -1;
  83. if (matched.length > 1 && matched[0] && matched[0].path) {
  84. const { path } = matched[0];
  85. index = this.navList.findIndex((v1) => v1.path === path);
  86. }
  87. if (index !== this.active) {
  88. this.menuList = this.navList[index].children;
  89. this.active = index;
  90. }
  91. },
  92. },
  93. };
  94. </script>