left.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. <template>
  2. <div class="full-height" style="background-color: #f6f7f8">
  3. <div class="full-height">
  4. <div class="padding-left padding-top">
  5. <el-skeleton :rows="5" animated v-if="data.length === 0" />
  6. <div v-else v-for="(item, index) in data" :key="item.id">
  7. <div
  8. v-if="!item.hasChildren"
  9. class="item flex flex-center flex-justify-start"
  10. @click="navClick(index, 1, 0)"
  11. :style="item.checked ? 'color:#409eff' : ''"
  12. >
  13. <img :src="item.source" style="width: 25px" class="mr-5" />
  14. {{ item.name }}
  15. </div>
  16. <el-collapse v-else v-model="activeCollapse">
  17. <el-collapse-item
  18. :title="item.name"
  19. :name="item.name"
  20. :key="item.name"
  21. >
  22. <template #title>
  23. <div class="flex flex-center flex-justify-start">
  24. <img :src="item.source" style="width: 25px" class="mr-5" />
  25. {{ item.name }}
  26. </div>
  27. </template>
  28. <div
  29. class="full-height"
  30. @click="navClick(index, 2, subIndex)"
  31. v-for="(sub, subIndex) in item.children"
  32. :key="sub.name"
  33. >
  34. <div
  35. class="item flex flex-center flex-justify-start"
  36. style="margin-left: 20px"
  37. :style="sub.checked ? 'color:#ECAB56' : ''"
  38. >
  39. {{ sub.name }}
  40. </div>
  41. </div>
  42. </el-collapse-item>
  43. </el-collapse>
  44. </div>
  45. </div>
  46. </div>
  47. </div>
  48. </template>
  49. <script>
  50. export default {
  51. data() {
  52. return {
  53. active: 0,
  54. subActive: 0,
  55. data: [],
  56. currentPage: '',
  57. activeCollapse: ''
  58. }
  59. },
  60. watch: {
  61. $route: {
  62. immediate: false,
  63. handler() {
  64. this.currentPage = window.location.href
  65. this.init()
  66. }
  67. }
  68. },
  69. created() {
  70. this.currentPage = window.location.href
  71. this.menus()
  72. },
  73. methods: {
  74. init() {
  75. const item = localStorage.getItem('index')
  76. if (item) {
  77. const menu = JSON.parse(item)
  78. this.active = menu.active
  79. this.subActive = menu.subActive
  80. }
  81. if (
  82. Object.hasOwn(this.data[this.active], 'hasChildren') &&
  83. this.data[this.active].hasChildren === true
  84. ) {
  85. this.activeCollapse = this.data[this.active].name
  86. this.data[this.active].children[this.subActive].checked = true
  87. } else {
  88. this.activeCollapse = this.data[this.active].name
  89. this.data[this.active].checked = true
  90. }
  91. },
  92. menus() {
  93. this.$api.common.getMenus().then(res => {
  94. console.log('fuck' + new Date().getTime())
  95. if (res.code === 200 && res.data.length > 0) {
  96. this.data = res.data.map(sub => {
  97. sub.hasChildren = Object.hasOwn(sub, 'children')
  98. sub.checked = false
  99. return sub
  100. })
  101. this.init()
  102. }
  103. })
  104. },
  105. navClick(index, type, subIndex) {
  106. this.data.forEach(item => {
  107. item.checked = false
  108. if (item.hasChildren) {
  109. item.children.forEach(ele => {
  110. ele.checked = false
  111. })
  112. }
  113. })
  114. if (type === 2) {
  115. this.data[index].children[subIndex].checked = true
  116. } else {
  117. this.data[index].checked = true
  118. }
  119. if (this.data[index].path.startsWith('http')) {
  120. window.open(this.data[index].path, '_blank')
  121. } else if (type === 2) {
  122. this.$router.push(this.data[index].children[subIndex].path)
  123. localStorage.setItem(
  124. 'data-type',
  125. this.data[index].children[subIndex].remark
  126. ? this.data[index].children[subIndex].remark
  127. : 'project'
  128. )
  129. this.$bus.emit(
  130. 'navChange',
  131. this.data[index].children[subIndex].remark
  132. ? this.data[index].children[subIndex].remark
  133. : 'project'
  134. )
  135. } else {
  136. this.$router.push(this.data[index].path)
  137. localStorage.setItem(
  138. 'data-type',
  139. this.data[index].remark ? this.data[index].remark : 'project'
  140. )
  141. this.$bus.emit(
  142. 'navChange',
  143. this.data[index].remark ? this.data[index].remark : 'project'
  144. )
  145. }
  146. const menu = { active: index, subActive: subIndex }
  147. localStorage.setItem('index', JSON.stringify(menu))
  148. this.$emit('closeMenu')
  149. }
  150. }
  151. }
  152. </script>
  153. <style scoped>
  154. .item {
  155. font-weight: 500;
  156. font-size: 15px;
  157. padding: 15px 10px;
  158. z-index: 999;
  159. }
  160. .item:hover {
  161. background-color: #efefef;
  162. }
  163. :deep(.el-collapse) {
  164. --el-collapse-content-bg-color: transparent !important;
  165. --el-collapse-header-bg-color: transparent !important;
  166. --el-collapse-content-font-size: 15px !important;
  167. --el-collapse-header-font-size: 15px !important;
  168. --el-collapse-border-color: transparent !important;
  169. border-top: none;
  170. border-bottom: none;
  171. margin: 0;
  172. width: 100%;
  173. }
  174. :deep(.el-collapse-item__header) {
  175. padding-left: 10px;
  176. }
  177. :deep(.el-collapse-item__header):hover {
  178. background-color: #efefef;
  179. }
  180. :deep(.el-collapse-item__content) {
  181. padding-bottom: 0 !important;
  182. line-height: 1 !important;
  183. padding-left: 10px;
  184. }
  185. </style>