Header.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. <template>
  2. <div class="header-menu">
  3. <ul class="header-menu-list">
  4. <li class="header-menu-item"
  5. v-for="(menu, index) of menus"
  6. :key="menu"
  7. @click="click(index, menu)"
  8. :class="{ active: activeIndex == index }">
  9. {{ menu.text }}
  10. </li>
  11. </ul>
  12. <!-- <ul class="header-menu-dropdown" :class="{ dropdown: dropdown }">
  13. <li class="header-menu-dropdown-title" @click="clickMenu()"><i class="fa fa-gear"></i>菜单<i class="fa fa-sort-down down"></i></li>
  14. <ul class="header-menu-dropdown-list">
  15. <li class="header-menu-dropdown-item" v-for="(menu, index) of menusDropdown" :key="menu" @click="clickSubMenu(index, menu.code)">
  16. {{ menu.text }}
  17. </li>
  18. </ul>
  19. </ul> -->
  20. <ul class="header-menu-user">
  21. <li class="header-menu-user-title"><i class="fa fa-user"></i>白玉杰</li>
  22. </ul>
  23. </div>
  24. </template>
  25. <script>
  26. export default {
  27. data() {
  28. return {
  29. menus: [
  30. {
  31. id: 'monitor',
  32. text: '驾驶舱',
  33. path: '/monitor/home',
  34. isActive: true
  35. },
  36. {
  37. id: 'decision',
  38. text: '经济运行',
  39. path: '/decision/pb',
  40. isActive: false
  41. },
  42. {
  43. id: 'health',
  44. text: '智慧检修',
  45. // path: '/sandtable',
  46. path: '/health/sandtable',
  47. isActive: false
  48. },
  49. // {
  50. // id: "decision",
  51. // text: "决策支持",
  52. // path: "/decision/decision1",
  53. // isActive: false,
  54. // },
  55. {
  56. id: 'personnel',
  57. text: '安全管控',
  58. path: '/new/personnel',
  59. isActive: false
  60. },
  61. {
  62. id: "znbb",
  63. text: "智能报表",
  64. path: "/znbb/reportPandect",
  65. isActive: false,
  66. },
  67. {
  68. id: 'realSearch',
  69. text: '其他',
  70. path: '/realSearch',
  71. isActive: false
  72. }
  73. ],
  74. activeIndex: 0
  75. // menusDropdown: [
  76. // {
  77. // text: "子菜单1",
  78. // code: "submenu1",
  79. // },
  80. // {
  81. // text: "子菜单2",
  82. // code: "submenu2",
  83. // },
  84. // {
  85. // text: "子菜单3",
  86. // code: "submenu3",
  87. // },
  88. // ],
  89. // dropdown: false,
  90. }
  91. },
  92. methods: {
  93. click(index, data) {
  94. this.activeIndex = index
  95. this.$router.push(data.path)
  96. },
  97. clickSubMenu(index, code) {
  98. console.log(index, code)
  99. },
  100. clickMenu() {
  101. this.dropdown = !this.dropdown
  102. }
  103. },
  104. computed: {
  105. activeClass(data) {
  106. return data.isActive ? 'active' : ''
  107. }
  108. },
  109. watch: {
  110. $route: {
  111. handler: function(val, oldVal) {
  112. this.menus.some((t, index) => {
  113. if (val.path.includes(t.id)) {
  114. this.activeIndex = index
  115. }
  116. })
  117. },
  118. //深度观察监听
  119. deep: true
  120. }
  121. }
  122. }
  123. </script>
  124. <style lang="less">
  125. .header-menu {
  126. display: flex;
  127. flex-direction: row;
  128. width: 100%;
  129. height: 100%;
  130. font-size: @fontsize;
  131. .header-menu-list {
  132. margin: 0;
  133. padding: 0;
  134. list-style: none;
  135. margin-left: auto;
  136. display: flex;
  137. flex-direction: row;
  138. height: 100%;
  139. .header-menu-item {
  140. display: flex;
  141. align-items: center;
  142. justify-content: center;
  143. width: 9.259vh;
  144. height: 100%;
  145. color: @font-color;
  146. cursor: pointer;
  147. transition: color 0.2s ease-in-out;
  148. &.active {
  149. color: @green;
  150. position: relative;
  151. background: @greenLinearTop;
  152. transition: color 0.2s ease-in-out;
  153. &::after {
  154. content: '';
  155. position: absolute;
  156. width: 100%;
  157. height: 0.463vh;
  158. border: 0.093vh solid @green;
  159. border-top: 0;
  160. left: 0;
  161. bottom: 0;
  162. box-sizing: border-box;
  163. }
  164. }
  165. }
  166. }
  167. .header-menu-dropdown {
  168. width: 11.111vh;
  169. height: 100%;
  170. margin: 0;
  171. padding: 0;
  172. list-style: none;
  173. .header-menu-dropdown-title {
  174. display: flex;
  175. align-items: center;
  176. justify-content: center;
  177. width: 100%;
  178. height: 100%;
  179. color: @gray;
  180. cursor: pointer;
  181. i {
  182. margin: 0 0.741vh;
  183. transition: all 0.3s;
  184. }
  185. }
  186. .header-menu-dropdown-list {
  187. display: none;
  188. margin: 0;
  189. padding: 0;
  190. list-style: none;
  191. margin-left: auto;
  192. position: absolute;
  193. .header-menu-dropdown-item {
  194. display: flex;
  195. align-items: center;
  196. justify-content: center;
  197. width: 11.111vh;
  198. height: 3.704vh;
  199. color: @gray;
  200. cursor: pointer;
  201. position: relative;
  202. z-index: 1;
  203. background-color: fade(@write, 5%);
  204. &::after {
  205. content: '';
  206. position: absolute;
  207. width: 100%;
  208. height: 0.463vh;
  209. border: 0.093vh solid @green;
  210. border-top: 0;
  211. left: 0;
  212. bottom: 0;
  213. box-sizing: border-box;
  214. }
  215. &:hover {
  216. color: @write;
  217. background-color: fade(@write, 10%);
  218. }
  219. }
  220. }
  221. &.dropdown {
  222. .header-menu-dropdown-title {
  223. .down {
  224. transform: rotate(180deg);
  225. }
  226. }
  227. .header-menu-dropdown-list {
  228. display: flex;
  229. flex-direction: column;
  230. }
  231. }
  232. }
  233. .header-menu-user {
  234. width: 16.667vh;
  235. height: 100%;
  236. margin: 0;
  237. padding: 0;
  238. list-style: none;
  239. .header-menu-user-title {
  240. display: flex;
  241. align-items: center;
  242. justify-content: center;
  243. width: 100%;
  244. height: 100%;
  245. color: @gray;
  246. cursor: pointer;
  247. i {
  248. margin: 0 0.741vh;
  249. }
  250. }
  251. }
  252. }
  253. </style>