index.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. <template>
  2. <div :class="{ 'has-logo': showLogo }">
  3. <!-- <logo v-if="showLogo"
  4. :collapse="false" /> -->
  5. <el-scrollbar wrap-class="scrollbar-wrapper">
  6. <!-- -->
  7. <el-menu
  8. :default-active="activeMenu"
  9. :collapse="false"
  10. :background-color="variables.menuBg"
  11. :text-color="variables.menuText"
  12. :unique-opened="true"
  13. :active-text-color="variables.menuActiveText2"
  14. :collapse-transition="true"
  15. mode="vertical"
  16. >
  17. <template v-for="route in permission_routes">
  18. <template v-if="!route.hidden">
  19. <!-- <sidebar-item v-for="route2 in route.children" :key="route.path + '/' + route2.path" :item="route2" :base-path="route.path" :resolve-path="route.path" :active-top-menu="getTopMenuActive" /> -->
  20. <!-- <sidebar-menu-item v-for="route2 in route.children" :key="route.path + '/' + route2.path" :routes="route2" :base-path="route.path" :resolve-path="route.path" :active-top-menu="getTopMenuActive"/> -->
  21. <sidebar-item
  22. v-for="route2 in route.children"
  23. :key="route2.id"
  24. :item="route2"
  25. :active-top-menu="getTopMenuActive"
  26. :base-path="route2.path"
  27. />
  28. </template>
  29. </template>
  30. <!-- <sidebar-item v-for="(route,index) in permission_routes"
  31. :key="index"
  32. :item="route"
  33. :base-path="route.path" /> -->
  34. </el-menu>
  35. </el-scrollbar>
  36. </div>
  37. </template>
  38. <script>
  39. import { mapGetters } from "vuex";
  40. import Logo from "./Logo";
  41. import SidebarMenuItem from "./SidebarMenuItem";
  42. import SidebarItem from "./SidebarItem";
  43. import variables from "@/styles/variables.scss";
  44. import {
  45. getBelongTopMenuPath,
  46. getActiveSidebarMenuPath,
  47. } from "@/utils/permission";
  48. export default {
  49. components: { SidebarItem, Logo, SidebarMenuItem },
  50. // mounted () {
  51. // },
  52. computed: {
  53. ...mapGetters(["sidebar", "permission_routes"]),
  54. // routes () {
  55. // return this.$router.options.routes
  56. // },
  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. // 设置高亮的位置
  62. if (meta.activeMenu) {
  63. return meta.activeMenu;
  64. }
  65. // (meta, path)
  66. return path;
  67. },
  68. showLogo() {
  69. return this.$store.state.settings.sidebarLogo;
  70. },
  71. variables() {
  72. return variables;
  73. },
  74. isCollapse() {
  75. return false;
  76. },
  77. getSidebarMenuActive: function () {
  78. const route = this.$route;
  79. return getActiveSidebarMenuPath(route);
  80. },
  81. getTopMenuActive() {
  82. let route = this.$route;
  83. // (getBelongTopMenuPath(route))
  84. return getBelongTopMenuPath(route);
  85. },
  86. },
  87. mounted() {
  88. // (this.permission_routes)
  89. this.menuIsShow(this.$route);
  90. },
  91. watch: {
  92. $route() {
  93. this.menuIsShow(this.$route);
  94. },
  95. },
  96. methods: {
  97. menuIsShow(route) {
  98. let activeTopMenu;
  99. const { meta } = route;
  100. if (meta.belongTopMenu) {
  101. activeTopMenu = meta.belongTopMenu;
  102. }
  103. let permissions = this.permission_routes || [];
  104. let childList = [];
  105. permissions.forEach((item) => {
  106. if (item.path == activeTopMenu) {
  107. ('childList',item)
  108. childList = item;
  109. }
  110. });
  111. // (childList.children)
  112. let index = this.menuOperation(childList.children);
  113. //重写逻辑
  114. let status = index > 0 ? true : false;
  115. let routeParentName = sessionStorage.getItem("routeParentName");
  116. let params = {
  117. status: status,
  118. };
  119. if (routeParentName != meta.belongTopMenu) {
  120. params.isCollapse = true;
  121. sessionStorage.setItem("routeParentName", meta.belongTopMenu);
  122. }
  123. this.$emit("childStatus", params);
  124. },
  125. menuOperation(arr) {
  126. let index = 0;
  127. if (arr?.length > 0) {
  128. for (let i = 0; i < arr.length; i++) {
  129. if (arr[i].hidden) {
  130. continue;
  131. }
  132. // (arr[i]);
  133. if (arr[i].children?.length > 0) {
  134. let isChildrenList = false;
  135. arr[i].children.forEach((ii) => {
  136. if (!ii.hidden) {
  137. isChildrenList = true;
  138. }
  139. });
  140. if (isChildrenList) {
  141. index = this.menuOperation(arr[i].children);
  142. }else{
  143. index = 1
  144. }
  145. } else {
  146. index++;
  147. }
  148. }
  149. }
  150. return index;
  151. },
  152. },
  153. };
  154. </script>
  155. <style lang="scss" scoped>
  156. .el-menu-item {
  157. &:nth-last-child(1) {
  158. padding-bottom: 20px;
  159. }
  160. }
  161. /deep/.el-submenu__title,
  162. /deep/.el-menu-item {
  163. font-size: 14px;
  164. }
  165. // /deep/.el-menu-item.is-active {
  166. // font-weight: bold;
  167. // background-color: #eef4f4 !important;
  168. // color: var(--color-primary) !important;
  169. // position: relative;
  170. // &::after {
  171. // position: absolute;
  172. // top: 0;
  173. // right: 0;
  174. // content: " ";
  175. // width: 6px;
  176. // background-color: var(--color-primary);
  177. // display: block;
  178. // height: 100%;
  179. // }
  180. // }
  181. // /deep/.el-submenu .el-menu-item.is-active {
  182. // color: var(--color-primary) !important;
  183. // }
  184. /deep/.el-menu .menu-wrapper .el-menu-item {
  185. color: #666666;
  186. }
  187. /deep/.el-menu-item,
  188. /deep/.el-submenu__title {
  189. height: 56px !important;
  190. line-height: 56px !important;
  191. }
  192. /deep/.el-submenu .el-menu-item {
  193. color: #666666 !important;
  194. }
  195. /deep/.el-submenu__icon-arrow {
  196. font-size: 14px;
  197. }
  198. </style>