Header.vue 5.6 KB

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