left.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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 (this.data[this.active].hasChildren === true) {
  82. this.activeCollapse = this.data[this.active].name
  83. this.data[this.active].children[this.subActive].checked = true
  84. } else {
  85. this.activeCollapse = this.data[this.active].name
  86. this.data[this.active].checked = true
  87. }
  88. },
  89. menus() {
  90. this.$api.common.getMenus().then(res => {
  91. console.log('fuck' + new Date().getTime())
  92. if (res.code === 200) {
  93. this.data = res.data.map(sub => {
  94. sub.hasChildren = Object.hasOwn(sub, 'children')
  95. sub.checked = false
  96. return sub
  97. })
  98. this.init()
  99. }
  100. })
  101. },
  102. navClick(index, type, subIndex) {
  103. this.data.forEach(item => {
  104. item.checked = false
  105. if (item.hasChildren) {
  106. item.children.forEach(ele => {
  107. ele.checked = false
  108. })
  109. }
  110. })
  111. if (type === 2) {
  112. this.data[index].children[subIndex].checked = true
  113. } else {
  114. this.data[index].checked = true
  115. }
  116. if (this.data[index].path.startsWith('http')) {
  117. window.open(this.data[index].path, '_blank')
  118. } else if (type === 2) {
  119. this.$router.push(this.data[index].children[subIndex].path)
  120. localStorage.setItem(
  121. 'data-type',
  122. this.data[index].children[subIndex].remark
  123. ? this.data[index].children[subIndex].remark
  124. : 'project'
  125. )
  126. this.$bus.emit(
  127. 'navChange',
  128. this.data[index].children[subIndex].remark
  129. ? this.data[index].children[subIndex].remark
  130. : 'project'
  131. )
  132. } else {
  133. // this.$router.push(this.data[index].path)
  134. localStorage.setItem(
  135. 'data-type',
  136. this.data[index].remark ? this.data[index].remark : 'project'
  137. )
  138. this.$bus.emit(
  139. 'navChange',
  140. this.data[index].remark ? this.data[index].remark : 'project'
  141. )
  142. }
  143. const menu = { active: index, subActive: subIndex }
  144. localStorage.setItem('index', JSON.stringify(menu))
  145. this.$emit('closeMenu')
  146. }
  147. }
  148. }
  149. </script>
  150. <style scoped>
  151. .item {
  152. font-weight: 500;
  153. font-size: 15px;
  154. padding: 15px 10px;
  155. z-index: 999;
  156. }
  157. .item:hover {
  158. background-color: #efefef;
  159. }
  160. :deep(.el-collapse) {
  161. --el-collapse-content-bg-color: transparent !important;
  162. --el-collapse-header-bg-color: transparent !important;
  163. --el-collapse-content-font-size: 15px !important;
  164. --el-collapse-header-font-size: 15px !important;
  165. --el-collapse-border-color: transparent !important;
  166. border-top: none;
  167. border-bottom: none;
  168. margin: 0;
  169. width: 100%;
  170. }
  171. :deep(.el-collapse-item__header) {
  172. padding-left: 10px;
  173. }
  174. :deep(.el-collapse-item__header):hover {
  175. background-color: #efefef;
  176. }
  177. :deep(.el-collapse-item__content) {
  178. padding-bottom: 0 !important;
  179. line-height: 1 !important;
  180. padding-left: 10px;
  181. }
  182. </style>