Header.vue 5.6 KB

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