left.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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. console.log(JSON.parse(item))
  74. const menu = JSON.parse(item)
  75. this.active = menu.active
  76. this.subActive = menu.subActive
  77. }
  78. },
  79. menus() {
  80. this.$api.common.getMenus().then(res => {
  81. if (res.code === 200) {
  82. this.data = res.data
  83. this.init()
  84. }
  85. })
  86. },
  87. navClick(item, index) {
  88. this.active = index
  89. if (item.children && item.children.length > 0) {
  90. this.subActive = 0
  91. this.$router.push(item.children[0].path)
  92. localStorage.setItem(
  93. 'data-type',
  94. item.children[0].remark ? item.children[0].remark : 'project'
  95. )
  96. } else {
  97. this.$router.push(item.path)
  98. localStorage.setItem('data-type', item.remark ? item.remark : 'project')
  99. }
  100. const menu = { active: this.active, subActive: this.subActive }
  101. localStorage.setItem('index', JSON.stringify(menu))
  102. },
  103. subClick(item, index) {
  104. this.subActive = index
  105. localStorage.setItem('data-type', item.remark ? item.remark : 'project')
  106. this.$router.push(item.path)
  107. const menu = { active: this.active, subActive: this.subActive }
  108. localStorage.setItem('index', JSON.stringify(menu))
  109. }
  110. }
  111. }
  112. </script>
  113. <style scoped>
  114. .box-shadow-blue {
  115. position: fixed;
  116. width: 200px;
  117. left: 0;
  118. z-index: 2;
  119. background-color: white;
  120. box-shadow: 5px 0 10px -5px rgba(0, 0, 0, 0.1);
  121. }
  122. .item-bg {
  123. border-top: 1px solid #d1d1d1;
  124. border-bottom: 1px solid #d1d1d1;
  125. }
  126. .item-s {
  127. width: 160px;
  128. border-radius: 14px;
  129. margin-top: 30px;
  130. color: white;
  131. background-color: #ab7630;
  132. box-shadow: 2px 2px 10px 2px rgba(242, 162, 58, 0.49);
  133. }
  134. .item {
  135. width: 150px;
  136. border-radius: 14px;
  137. margin-top: 30px;
  138. color: #707070;
  139. }
  140. .item-sub {
  141. width: 160px;
  142. border-bottom-left-radius: 14px;
  143. border-bottom-right-radius: 14px;
  144. margin-top: -10px;
  145. padding-top: 20px;
  146. color: #939393;
  147. background-color: #e4e4e4;
  148. }
  149. .item-sub-active {
  150. background-color: #d3d3d3;
  151. }
  152. </style>