index.vue 4.8 KB

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