index.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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. mode="vertical"
  29. :default-openeds="defaultpath"
  30. :default-active="$route.path"
  31. >
  32. <!-- @click.native="a(route,index)" -->
  33. <sidebar-item
  34. v-for="(route, index) in routs"
  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. import Cookies from "js-cookie";
  49. export default {
  50. data() {
  51. return {
  52. routs: [],
  53. p: null,
  54. defaultpath: null
  55. };
  56. },
  57. components: { SidebarItem, Logo },
  58. computed: {
  59. ...mapState(["settings"]),
  60. ...mapGetters(["sidebarRouters", "sidebar"]),
  61. activeMenu() {
  62. const route = this.$route;
  63. const { meta, path } = route;
  64. // if set path, the sidebar will highlight the path you set
  65. if (meta.activeMenu) {
  66. return meta.activeMenu;
  67. }
  68. return path;
  69. },
  70. showLogo() {
  71. return this.$store.state.settings.sidebarLogo;
  72. },
  73. variables() {
  74. return variables;
  75. },
  76. isCollapse() {
  77. return !this.sidebar.opened;
  78. }
  79. },
  80. created() {
  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. a(route, index) {},
  91. sidebarRoutersfun() {
  92. console.log("this.$route.query.name", this.$route.query.name);
  93. this.sidebarRouters.map(item => {
  94. if (item.path == this.$route.query.name) {
  95. console.log("item.path", item.path)
  96. // console.log("this.routs1", this.routs)
  97. // console.log("this.routs1", this.routs)
  98. // console.log(item);
  99. console.log("this.routs1", this.routs)
  100. this.routs.push(item);
  101. console.log("this.routs2", this.routs)
  102. if (this.$route.name == "Notice") {
  103. // this.p = this.routs[0].path + "/" + this.routs[0].children[0].path;
  104. this.$router.push({ path: "/system/notice" });
  105. } else {
  106. console.log("this.routs[0]", this.routs[0])
  107. if (this.routs[0].children && this.routs[0].children[0].children) {
  108. this.defaultpath = [this.routs[0].children[0].path];
  109. this.p =
  110. this.routs[0].path
  111. + "/" + this.routs[0].children[0].path
  112. + "/" + this.routs[0].children[0].children[0].path;
  113. } else if (this.routs[0].children) {
  114. this.defaultpath = [this.routs[0].path];
  115. this.p =
  116. this.routs[0].path
  117. + "/" + this.routs[0].children[0].path;
  118. } else {
  119. this.defaultpath = [this.routs[0].path];
  120. this.p =
  121. this.routs[0].path
  122. }
  123. console.log("this.p", this.p)
  124. this.$router.push({ path: this.p });
  125. }
  126. }
  127. // console.log(this.routs.length)
  128. });
  129. console.log("this.routs", this.routs)
  130. console.log(" this.$router", this.$router)
  131. if (this.routs.length <= 0) {
  132. // window.open(`/phone`, "_self");
  133. this.$router
  134. .push({
  135. name: "pt",
  136. params: {
  137. name: "您暂无权限访问"
  138. }
  139. })
  140. .catch(() => {});
  141. }
  142. }
  143. }
  144. };
  145. </script>