left.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <template>
  2. <div class="box-shadow-blue full-height" style="background-color: #f4f3ee">
  3. <div class="padding mt-20">
  4. <div class="flex flex-center mt-10" style="margin-bottom: 60px">
  5. <img src="@/assets/svg/logo.svg" />
  6. </div>
  7. </div>
  8. <div>
  9. <div
  10. class="flex flex-center flex-col bold font-18 item-bg padding-bottom full-width"
  11. >
  12. <div
  13. v-for="(item, index) in data"
  14. :key="item.id"
  15. class="full-width flex flex-col flex-center pointer"
  16. >
  17. <div
  18. class="full-width flex flex-center padding"
  19. style="z-index: 2"
  20. :class="active === index ? 'item-s' : 'item'"
  21. @click="navClick(item, index)"
  22. >
  23. <img :src="item.source" />
  24. <span class="flex-child-average">{{ item.name }}</span>
  25. </div>
  26. <div
  27. v-if="item.children && item.children.length > 0 && active === index"
  28. class="flex flex-col flex-center item-sub padding"
  29. >
  30. <div
  31. v-for="(sub, subIndex) in item.children"
  32. :key="sub.id"
  33. class="padding full-width flex flex-center"
  34. :class="subIndex === subActive ? 'item-sub-active' : ''"
  35. @click="subClick(sub, subIndex)"
  36. >
  37. <div class="mr-10 main-color">·</div>
  38. <span>{{ sub.name }}</span>
  39. </div>
  40. </div>
  41. </div>
  42. </div>
  43. </div>
  44. </div>
  45. </template>
  46. <script>
  47. export default {
  48. data() {
  49. return {
  50. active: 0,
  51. subActive: 0,
  52. data: [],
  53. currentPage: ''
  54. }
  55. },
  56. watch: {
  57. $route: {
  58. immediate: false,
  59. handler() {
  60. this.currentPage = window.location.href
  61. this.init()
  62. }
  63. }
  64. },
  65. created() {
  66. this.currentPage = window.location.href
  67. this.menus()
  68. },
  69. methods: {
  70. init() {
  71. const item = localStorage.getItem('index')
  72. if (item) {
  73. const menu = JSON.parse(item)
  74. this.active = menu.active
  75. this.subActive = menu.subActive
  76. }
  77. },
  78. menus() {
  79. this.$api.common.getMenus().then(res => {
  80. if (res.code === 200) {
  81. this.data = res.data
  82. this.init()
  83. }
  84. })
  85. },
  86. navClick(item, index) {
  87. this.active = index
  88. if (item.children && item.children.length > 0) {
  89. this.subActive = 0
  90. this.$router.push(item.children[0].path)
  91. localStorage.setItem(
  92. 'data-type',
  93. item.children[0].remark ? item.children[0].remark : 'project'
  94. )
  95. this.$bus.emit(
  96. 'navChange',
  97. item.remark ? item.children[0].remark : 'project'
  98. )
  99. } else {
  100. this.$router.push(item.path)
  101. localStorage.setItem('data-type', item.remark ? item.remark : 'project')
  102. this.$bus.emit('navChange', item.remark ? item.remark : 'project')
  103. }
  104. const menu = { active: this.active, subActive: this.subActive }
  105. localStorage.setItem('index', JSON.stringify(menu))
  106. },
  107. subClick(item, index) {
  108. this.subActive = index
  109. localStorage.setItem('data-type', item.remark ? item.remark : 'project')
  110. this.$router.push(item.path)
  111. const menu = { active: this.active, subActive: this.subActive }
  112. localStorage.setItem('index', JSON.stringify(menu))
  113. this.$bus.emit('navChange', item.remark ? item.remark : 'project')
  114. }
  115. }
  116. }
  117. </script>
  118. <style scoped>
  119. .box-shadow-blue {
  120. position: fixed;
  121. width: 200px;
  122. left: 0;
  123. z-index: 2;
  124. background-color: white;
  125. box-shadow: 5px 0 10px -5px rgba(0, 0, 0, 0.1);
  126. }
  127. .item-bg {
  128. border-top: 1px solid #d1d1d1;
  129. border-bottom: 1px solid #d1d1d1;
  130. }
  131. .item-s {
  132. width: 160px;
  133. border-radius: 14px;
  134. margin-top: 30px;
  135. color: white;
  136. background-color: #ab7630;
  137. box-shadow: 2px 2px 10px 2px rgba(242, 162, 58, 0.49);
  138. }
  139. .item {
  140. width: 150px;
  141. border-radius: 14px;
  142. margin-top: 30px;
  143. color: #707070;
  144. }
  145. .item-sub {
  146. width: 160px;
  147. border-bottom-left-radius: 14px;
  148. border-bottom-right-radius: 14px;
  149. margin-top: -10px;
  150. padding-top: 20px;
  151. color: #939393;
  152. background-color: #e4e4e4;
  153. }
  154. .item-sub-active {
  155. background-color: #d3d3d3;
  156. }
  157. </style>