Header.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. <template>
  2. <div class="header-menu">
  3. <ul class="header-menu-list">
  4. <li
  5. class="header-menu-item"
  6. v-for="(menu, index) of menus"
  7. :key="menu"
  8. @click="click(index, menu)"
  9. :class="{ active: activeIndex == index }"
  10. >
  11. {{ menu.text }}
  12. </li>
  13. </ul>
  14. <!-- <ul class="header-menu-dropdown" :class="{ dropdown: dropdown }">
  15. <li class="header-menu-dropdown-title" @click="clickMenu()"><i class="fa fa-gear"></i>菜单<i class="fa fa-sort-down down"></i></li>
  16. <ul class="header-menu-dropdown-list">
  17. <li class="header-menu-dropdown-item" v-for="(menu, index) of menusDropdown" :key="menu" @click="clickSubMenu(index, menu.code)">
  18. {{ menu.text }}
  19. </li>
  20. </ul>
  21. </ul> -->
  22. <ul class="header-menu-user">
  23. <li class="header-menu-user-title">
  24. <span class="el-dropdown-link"> <i class="fa fa-user"></i>白玉杰 </span>
  25. <el-dropdown
  26. size="small"
  27. trigger="hover"
  28. :hide-on-click="true"
  29. v-if="false"
  30. >
  31. <span class="el-dropdown-link">
  32. <i class="fa fa-user"></i>白玉杰
  33. </span>
  34. <template #dropdown>
  35. <el-dropdown-menu :class="$store.state.themeName + ' curDropdown'">
  36. <el-dropdown-item>
  37. <el-switch
  38. size="small"
  39. active-color="rgb(57, 54, 143)"
  40. inactive-color="#05bb4c"
  41. active-text="亮色主题"
  42. inactive-text="暗色主题"
  43. v-model="themeName"
  44. @change="changeTheme()"
  45. />
  46. </el-dropdown-item>
  47. </el-dropdown-menu>
  48. </template>
  49. </el-dropdown>
  50. </li>
  51. </ul>
  52. </div>
  53. </template>
  54. <script>
  55. import $ from "jquery";
  56. // import store from '@store/index';
  57. export default {
  58. data() {
  59. return {
  60. themeName: false,
  61. menus: [
  62. {
  63. id: "monitor",
  64. text: "驾驶舱",
  65. path: "/monitor/home",
  66. isActive: true,
  67. },
  68. {
  69. id: "decision",
  70. text: "经济运行",
  71. path: "/decision/pb",
  72. isActive: false,
  73. },
  74. {
  75. id: "health",
  76. text: "智慧检修",
  77. // path: '/sandtable',
  78. path: "/health/sandtable",
  79. isActive: false,
  80. },
  81. // {
  82. // id: "decision",
  83. // text: "决策支持",
  84. // path: "/decision/decision1",
  85. // isActive: false,
  86. // },
  87. {
  88. id: "save",
  89. text: "安全管控",
  90. path: "/save",
  91. isActive: false,
  92. },
  93. // {
  94. // id: "znbb",
  95. // text: "智能报表",
  96. // path: "/znbb/reportPandect",
  97. // isActive: false,
  98. // },
  99. {
  100. id: "others",
  101. text: "其他",
  102. path: "/others",
  103. isActive: false,
  104. },
  105. ],
  106. activeIndex: 0,
  107. // menusDropdown: [
  108. // {
  109. // text: "子菜单1",
  110. // code: "submenu1",
  111. // },
  112. // {
  113. // text: "子菜单2",
  114. // code: "submenu2",
  115. // },
  116. // {
  117. // text: "子菜单3",
  118. // code: "submenu3",
  119. // },
  120. // ],
  121. // dropdown: false,
  122. firsttime: 0,
  123. };
  124. },
  125. mounted() {
  126. let that = this;
  127. $(document).keydown((event) => {
  128. if (event.keyCode == 67) {
  129. // c
  130. let firstDate = new Date();
  131. if (that.firsttime == 0) {
  132. that.firsttime = firstDate.getTime();
  133. } else {
  134. var lastDate = new Date();
  135. var lastTime = lastDate.getTime();
  136. if (lastTime - that.firsttime < 1000) {
  137. that.changeTheme();
  138. that.firsttime = 0;
  139. }
  140. }
  141. }
  142. });
  143. },
  144. methods: {
  145. click(index, data) {
  146. this.activeIndex = index;
  147. this.$router.push(data.path);
  148. const ActiveModule = this.menus.find((ele) => {
  149. return ele.path === data.path;
  150. });
  151. if (ActiveModule) {
  152. this.$store.dispatch("changeModuleName", ActiveModule.text);
  153. }
  154. },
  155. clickSubMenu(index, code) {
  156. // console.log(index, code);
  157. },
  158. clickMenu() {
  159. this.dropdown = !this.dropdown;
  160. },
  161. changeTheme() {
  162. $("#appBody").toggleClass("dark light");
  163. this.$store.dispatch("changeTheme", $("#appBody").attr("class"));
  164. this.$store.state.themeName === "dark"
  165. ? (this.themeName = false)
  166. : (this.themeName = true);
  167. localStorage.setItem("themeName", this.$store.state.themeName);
  168. },
  169. },
  170. computed: {
  171. activeClass(data) {
  172. return data.isActive ? "active" : "";
  173. },
  174. },
  175. watch: {
  176. $route: {
  177. handler: function (val, oldVal) {
  178. this.menus.some((t, index) => {
  179. if (val.path.includes(t.id)) {
  180. this.activeIndex = index;
  181. const ActiveModule = this.menus.find((ele) => {
  182. return ele.path === val.path;
  183. });
  184. if (ActiveModule) {
  185. this.$store.dispatch("changeModuleName", ActiveModule.text);
  186. }
  187. }
  188. });
  189. },
  190. //深度观察监听
  191. deep: true,
  192. },
  193. },
  194. };
  195. </script>
  196. <style lang="less">
  197. .header-menu {
  198. display: flex;
  199. flex-direction: row;
  200. width: 100%;
  201. height: 100%;
  202. font-size: @fontsize;
  203. .header-menu-list {
  204. margin: 0;
  205. padding: 0;
  206. list-style: none;
  207. margin-left: auto;
  208. display: flex;
  209. flex-direction: row;
  210. height: 100%;
  211. .header-menu-item {
  212. display: flex;
  213. align-items: center;
  214. justify-content: center;
  215. width: 9.259vh;
  216. height: 100%;
  217. color: @font-color;
  218. cursor: pointer;
  219. transition: color 0.2s ease-in-out;
  220. &.active {
  221. color: @green;
  222. position: relative;
  223. background: @greenLinearTop;
  224. transition: color 0.2s ease-in-out;
  225. &::after {
  226. content: "";
  227. position: absolute;
  228. width: 100%;
  229. height: 0.463vh;
  230. border: 0.093vh solid @green;
  231. border-top: 0;
  232. left: 0;
  233. bottom: 0;
  234. box-sizing: border-box;
  235. }
  236. }
  237. }
  238. }
  239. .header-menu-dropdown {
  240. width: 11.111vh;
  241. height: 100%;
  242. margin: 0;
  243. padding: 0;
  244. list-style: none;
  245. .header-menu-dropdown-title {
  246. display: flex;
  247. align-items: center;
  248. justify-content: center;
  249. width: 100%;
  250. height: 100%;
  251. color: @gray;
  252. cursor: pointer;
  253. i {
  254. margin: 0 0.741vh;
  255. transition: all 0.3s;
  256. }
  257. }
  258. .header-menu-dropdown-list {
  259. display: none;
  260. margin: 0;
  261. padding: 0;
  262. list-style: none;
  263. margin-left: auto;
  264. position: absolute;
  265. .header-menu-dropdown-item {
  266. display: flex;
  267. align-items: center;
  268. justify-content: center;
  269. width: 11.111vh;
  270. height: 3.704vh;
  271. color: @gray;
  272. cursor: pointer;
  273. position: relative;
  274. z-index: 1;
  275. background-color: fade(@write, 5%);
  276. &::after {
  277. content: "";
  278. position: absolute;
  279. width: 100%;
  280. height: 0.463vh;
  281. border: 0.093vh solid @green;
  282. border-top: 0;
  283. left: 0;
  284. bottom: 0;
  285. box-sizing: border-box;
  286. }
  287. &:hover {
  288. color: @write;
  289. background-color: fade(@write, 10%);
  290. }
  291. }
  292. }
  293. &.dropdown {
  294. .header-menu-dropdown-title {
  295. .down {
  296. transform: rotate(180deg);
  297. }
  298. }
  299. .header-menu-dropdown-list {
  300. display: flex;
  301. flex-direction: column;
  302. }
  303. }
  304. }
  305. .header-menu-user {
  306. width: 16.667vh;
  307. height: 100%;
  308. margin: 0;
  309. padding: 0;
  310. list-style: none;
  311. .header-menu-user-title {
  312. display: flex;
  313. align-items: center;
  314. justify-content: center;
  315. width: 100%;
  316. height: 100%;
  317. color: @gray;
  318. cursor: pointer;
  319. i {
  320. margin: 0 0.741vh;
  321. }
  322. }
  323. }
  324. }
  325. </style>