Header.vue 5.5 KB

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