index.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <template>
  2. <div class="sign_box">
  3. <div class="sign_item" v-for="item in this.sidebarRouters.filter(res => {
  4. return res.hidden == false || res.redirect == 'index'
  5. })"
  6. @click="tabBtn(item)">
  7. <img src="@/assets/images/pic_tabbg@2x.png" draggable="false" v-show="activeMenu.includes((item.path||item.redirect))"
  8. alt="" class="img">
  9. <item v-if="item.meta" :icon="item.meta && item.meta.icon" :title="item.meta.title" />
  10. <item v-if="!item.meta" :icon="item.meta && item.meta.icon" :title="'首页'" />
  11. </div>
  12. </div>
  13. </template>
  14. <script>
  15. import {
  16. mapGetters,
  17. mapState
  18. } from "vuex";
  19. import Item from '@/layout/components/Sidebar/Item'
  20. export default {
  21. data() {
  22. return {
  23. indexs: 1,
  24. newArr: [],
  25. }
  26. },
  27. components: {
  28. Item
  29. },
  30. computed: {
  31. ...mapGetters(["sidebarRouters", "sidebar", "tabIndex"]),
  32. activeMenu() {
  33. // const route = this.$route;
  34. // const { meta, path } = route;
  35. // // if set path, the sidebar will highlight the path you set
  36. // if (meta.activeMenu) {
  37. // return meta.activeMenu;
  38. // }
  39. console.log(this.tabIndex, 887)
  40. return this.tabIndex;
  41. },
  42. },
  43. mounted() {
  44. this.init()
  45. },
  46. watch: {
  47. },
  48. methods: {
  49. tabBtn(item) {
  50. if(this.activeMenu.includes((item.path||item.redirect))){
  51. return
  52. }
  53. if (item.redirect == 'index') {
  54. if(this.$route.path!=='/index'){
  55. this.$router.push({
  56. path: '/index'
  57. })
  58. }
  59. this.$store.dispatch('TabFn', item.redirect)
  60. return
  61. }
  62. this.$store.dispatch('TabFn', item.path)
  63. },
  64. init() {
  65. const route = this.$route;
  66. const {
  67. meta,
  68. path
  69. } = route;
  70. // if set path, the sidebar will highlight the path you set
  71. console.log(route)
  72. if (meta.activeMenu) {
  73. this.$store.dispatch('TabFn', meta.activeMenu)
  74. }
  75. this.$store.dispatch('TabFn', path)
  76. }
  77. }
  78. }
  79. </script>
  80. <style lang="scss" scoped>
  81. .sign_box {
  82. padding-left: 52px;
  83. .sign_item {
  84. cursor: pointer;
  85. float: left;
  86. display: flex;
  87. height: 60px;
  88. justify-content: center;
  89. align-items: center;
  90. position: relative;
  91. width: 153px;
  92. padding-top: 10px;
  93. box-sizing: border-box;
  94. color: #fff;
  95. .img {
  96. width: 153px;
  97. height: 48px;
  98. position: absolute;
  99. left: 0;
  100. bottom: 0;
  101. }
  102. .icon {
  103. position: relative;
  104. z-index: 1;
  105. width: 20px;
  106. height: 20px;
  107. margin-right: 8px;
  108. }
  109. span {
  110. position: relative;
  111. z-index: 1;
  112. color: #fff !important;
  113. font-size: 17px !important;
  114. }
  115. svg {
  116. color: #fff !important;
  117. z-index: 2;
  118. line-height: 1;
  119. margin-right: 5px;
  120. }
  121. }
  122. }
  123. </style>