index.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. :collapse="false"
  15. :background-color="
  16. settings.sideTheme === 'theme-dark'
  17. ? variables.menuBackground
  18. : variables.menuLightBackground
  19. "
  20. :text-color="
  21. settings.sideTheme === 'theme-dark'
  22. ? variables.menuColor
  23. : variables.menuLightColor
  24. "
  25. :unique-opened="true"
  26. :active-text-color="settings.theme"
  27. :collapse-transition="false"
  28. :default-openeds="defaultpath"
  29. mode="vertical"
  30. :default-active="$route.path"
  31. >
  32. <sidebar-item
  33. v-for="(route, index) in routs"
  34. :key="route.path + index"
  35. :item="route"
  36. :base-path="route.path"
  37. />
  38. </el-menu>
  39. </el-scrollbar>
  40. </div>
  41. </template>
  42. <script>
  43. import { mapGetters, mapState } from "vuex";
  44. import Logo from "./Logo";
  45. import SidebarItem from "./SidebarItem";
  46. import variables from "@/assets/styles/variables.scss";
  47. import Cookies from "js-cookie";
  48. export default {
  49. data() {
  50. return {
  51. routs: [],
  52. p: null,
  53. defaultpath: null
  54. };
  55. },
  56. components: { SidebarItem, Logo },
  57. computed: {
  58. ...mapState(["settings"]),
  59. ...mapGetters(["sidebarRouters", "sidebar"]),
  60. activeMenu() {
  61. const route = this.$route;
  62. const { meta, path } = route;
  63. // if set path, the sidebar will highlight the path you set
  64. if (meta.activeMenu) {
  65. return meta.activeMenu;
  66. }
  67. return path;
  68. },
  69. showLogo() {
  70. return this.$store.state.settings.sidebarLogo;
  71. },
  72. variables() {
  73. return variables;
  74. },
  75. isCollapse() {
  76. return !this.sidebar.opened;
  77. }
  78. },
  79. created() {
  80. console.log(this.$route.name);
  81. if (this.$route.query.name) {
  82. this.sidebarRoutersfun();
  83. } else {
  84. this.$route.query.name = "/" + this.$route.path.split("/")[1];
  85. this.sidebarRoutersfun();
  86. }
  87. // window.location.reload()
  88. },
  89. methods: {
  90. sidebarRoutersfun() {
  91. this.sidebarRouters.map(item => {
  92. // console.log(this.$route.query.name);
  93. if (item.path == this.$route.query.name) {
  94. // console.log(item);
  95. this.routs.push(item);
  96. if (this.$route.name == "Notice") {
  97. // this.p = this.routs[0].path + "/" + this.routs[0].children[0].path;
  98. this.$router.push({ path: "/system/notice" });
  99. } else {
  100. if (this.routs[0].children[0].children) {
  101. this.defaultpath = [this.routs[0].children[0].path];
  102. this.p =
  103. this.routs[0].path +
  104. "/" +
  105. this.routs[0].children[0].path +
  106. "/" +
  107. this.routs[0].children[0].children[0].path;
  108. this.$router.push({ path: this.p });
  109. } else {
  110. this.defaultpath = [this.routs[0].path];
  111. this.p =
  112. this.routs[0].path + "/" + this.routs[0].children[0].path;
  113. this.$router.push({ path: this.p });
  114. }
  115. }
  116. }
  117. // console.log(this.routs.length)
  118. });
  119. if (this.routs.length <= 0) {
  120. // window.open(`/pt`, "_self");
  121. this.$router
  122. .push({
  123. name: "pt",
  124. params: {
  125. name: "您暂无权限访问"
  126. }
  127. })
  128. .catch(() => {});
  129. }
  130. }
  131. }
  132. };
  133. </script>