Header.vue 5.0 KB

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