Header.vue 5.8 KB

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