1
0

Header.vue 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428
  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 currMenu"
  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. <el-dropdown
  25. size="small"
  26. trigger="click"
  27. :hide-on-click="true"
  28. popper-class="dropdown"
  29. @command="handleCommand"
  30. >
  31. <span class="el-dropdown-link">
  32. <i class="fa fa-user"></i>{{ userName }}
  33. </span>
  34. <template #dropdown>
  35. <el-dropdown-menu>
  36. <el-dropdown-item command="logout"> 退出登录 </el-dropdown-item>
  37. </el-dropdown-menu>
  38. </template>
  39. </el-dropdown>
  40. </li>
  41. </ul>
  42. </div>
  43. </template>
  44. <script>
  45. import $ from "jquery";
  46. import { getCookie } from "@/utills/auth";
  47. import tools from "../../tools/encryption.js";
  48. import { logout } from "@/api/common.js";
  49. export default {
  50. data() {
  51. return {
  52. themeName: false,
  53. menus: [
  54. {
  55. id: "home",
  56. text: "首页",
  57. path: "/home",
  58. isActive: true,
  59. },
  60. {
  61. id: "stateMonitor",
  62. text: "监视中心",
  63. path: "/stateMonitor",
  64. isActive: true,
  65. },
  66. {
  67. id: "economicsOperation",
  68. text: "经济运行",
  69. path: "/economicsOperation",
  70. isActive: false,
  71. },
  72. {
  73. id: "health",
  74. text: "智慧检修",
  75. // path: '/sandtable',
  76. path: "/health",
  77. isActive: false,
  78. },
  79. // {
  80. // id: "decision",
  81. // text: "决策支持",
  82. // path: "/decision/decision1",
  83. // isActive: false,
  84. // },
  85. // {
  86. // id: "save",
  87. // text: "安全管控",
  88. // path: "/save",
  89. // isActive: false,
  90. // },
  91. // {
  92. // id: "znbb",
  93. // text: "智能报表",
  94. // path: "/znbb/reportPandect",
  95. // isActive: false,
  96. // },
  97. // {
  98. // id: "zhbj",
  99. // text: "综合报警",
  100. // path: "",
  101. // },
  102. // {
  103. // id: "fdnlpt",
  104. // text: "发电能力分析",
  105. // path: "",
  106. // },
  107. {
  108. id: "others",
  109. text: "综合报表",
  110. path: "/others",
  111. isActive: false,
  112. },
  113. ],
  114. activeIndex: 0,
  115. // menusDropdown: [
  116. // {
  117. // text: "子菜单1",
  118. // code: "submenu1",
  119. // },
  120. // {
  121. // text: "子菜单2",
  122. // code: "submenu2",
  123. // },
  124. // {
  125. // text: "子菜单3",
  126. // code: "submenu3",
  127. // },
  128. // ],
  129. // dropdown: false,
  130. firsttime: 0,
  131. };
  132. },
  133. mounted() {
  134. let that = this;
  135. $(document).keydown((event) => {
  136. if (event.keyCode == 192) {
  137. // c
  138. // let firstDate = new Date();
  139. // if (that.firsttime == 0) {
  140. // that.firsttime = firstDate.getTime();
  141. // } else {
  142. // var lastDate = new Date();
  143. // var lastTime = lastDate.getTime();
  144. // if (lastTime - that.firsttime < 1000) {
  145. // that.changeTheme();
  146. // that.firsttime = 0;
  147. // }
  148. // }
  149. that.changeTheme();
  150. }
  151. });
  152. },
  153. computed: {
  154. userName() {
  155. return getCookie("username") || this.$store.state.user.username;
  156. },
  157. // activeClass(data) {
  158. // return data.isActive ? "active" : "";
  159. // },
  160. currMenu() {
  161. let stateRoutes = this.$store.state.routes.routes;
  162. let currMenu = [];
  163. if (stateRoutes.length) {
  164. stateRoutes.forEach((route) => {
  165. if (route.path !== "/login") {
  166. currMenu.push({
  167. id: route.name,
  168. text: route.meta.title,
  169. path: route.path,
  170. isActive: false,
  171. });
  172. }
  173. });
  174. // currMenu.push(
  175. // {
  176. // id: "zhbj",
  177. // text: "综合报警",
  178. // path: "",
  179. // },
  180. // );
  181. return currMenu;
  182. } else {
  183. return [];
  184. }
  185. },
  186. },
  187. methods: {
  188. click(index, data) {
  189. if (data.id === "zhbj") {
  190. let userName = "admin";
  191. let jiami = tools.hex_md5(`${userName}gyee_alarm`);
  192. let url = `http://10.81.3.154:8078/#/check?userName=${userName}&mark=${jiami}`;
  193. window.open(url);
  194. return;
  195. }
  196. if (data.id === "fdnlpt") {
  197. let url = `http://10.81.3.155:8083/fdfx`;
  198. window.open(url);
  199. return;
  200. }
  201. this.activeIndex = index;
  202. this.$router.push(data.path);
  203. const ActiveModule = this.currMenu.find((ele) => {
  204. return ele.path === data.path;
  205. });
  206. if (ActiveModule) {
  207. this.$store.dispatch("changeModuleName", ActiveModule.text);
  208. }
  209. },
  210. clickSubMenu(index, code) {},
  211. clickMenu() {
  212. this.dropdown = !this.dropdown;
  213. },
  214. changeTheme() {
  215. $("#appBody").toggleClass("dark light");
  216. this.$store.dispatch("changeTheme", $("#appBody").attr("class"));
  217. this.$store.state.themeName === "dark"
  218. ? (this.themeName = false)
  219. : (this.themeName = true);
  220. localStorage.setItem("themeName", this.$store.state.themeName);
  221. },
  222. handleCommand(command) {
  223. if (command == "logout") {
  224. logout({
  225. token: getCookie("authToken"),
  226. userId: getCookie("userId"),
  227. }).then((res) => {
  228. this.$store.commit("user/REMOVE_TOKEN");
  229. this.$router.push("/login");
  230. });
  231. }
  232. },
  233. },
  234. watch: {
  235. $route: {
  236. handler: function (val, oldVal) {
  237. if (this.currMenu.length) {
  238. this.currMenu.some((t, index) => {
  239. if (val.path.includes(t.id)) {
  240. this.activeIndex = index;
  241. const ActiveModule = this.currMenu.find((ele) => {
  242. return ele.path === val.path;
  243. });
  244. if (ActiveModule) {
  245. this.$store.dispatch("changeModuleName", ActiveModule.text);
  246. }
  247. }
  248. });
  249. }
  250. },
  251. //深度观察监听
  252. deep: true,
  253. },
  254. },
  255. };
  256. </script>
  257. <style lang="less" scoped>
  258. .header-menu {
  259. display: flex;
  260. flex-direction: row;
  261. width: 100%;
  262. height: 100%;
  263. font-size: @fontsize;
  264. .header-menu-list {
  265. margin: 0;
  266. padding: 0;
  267. list-style: none;
  268. margin-left: auto;
  269. display: flex;
  270. flex-direction: row;
  271. height: 100%;
  272. .header-menu-item {
  273. display: flex;
  274. align-items: center;
  275. justify-content: center;
  276. padding: 0 15px;
  277. // width: 9.259vh;
  278. height: 100%;
  279. color: @font-color;
  280. cursor: pointer;
  281. transition: color 0.2s ease-in-out;
  282. &.active {
  283. color: @green;
  284. position: relative;
  285. background: @greenLinearTop;
  286. transition: color 0.2s ease-in-out;
  287. &::after {
  288. content: "";
  289. position: absolute;
  290. width: 100%;
  291. height: 0.463vh;
  292. border: 0.093vh solid @green;
  293. border-top: 0;
  294. left: 0;
  295. bottom: 0;
  296. box-sizing: border-box;
  297. }
  298. }
  299. }
  300. }
  301. .header-menu-dropdown {
  302. width: 11.111vh;
  303. height: 100%;
  304. margin: 0;
  305. padding: 0;
  306. list-style: none;
  307. .header-menu-dropdown-title {
  308. display: flex;
  309. align-items: center;
  310. justify-content: center;
  311. width: 100%;
  312. height: 100%;
  313. color: @gray;
  314. cursor: pointer;
  315. i {
  316. margin: 0 0.741vh;
  317. transition: all 0.3s;
  318. }
  319. }
  320. .header-menu-dropdown-list {
  321. display: none;
  322. margin: 0;
  323. padding: 0;
  324. list-style: none;
  325. margin-left: auto;
  326. position: absolute;
  327. .header-menu-dropdown-item {
  328. display: flex;
  329. align-items: center;
  330. justify-content: center;
  331. width: 11.111vh;
  332. height: 3.704vh;
  333. color: @gray;
  334. cursor: pointer;
  335. position: relative;
  336. z-index: 1;
  337. background-color: fade(@write, 5%);
  338. &::after {
  339. content: "";
  340. position: absolute;
  341. width: 100%;
  342. height: 0.463vh;
  343. border: 0.093vh solid @green;
  344. border-top: 0;
  345. left: 0;
  346. bottom: 0;
  347. box-sizing: border-box;
  348. }
  349. &:hover {
  350. color: @write;
  351. background-color: fade(@write, 10%);
  352. }
  353. }
  354. }
  355. &.dropdown {
  356. .header-menu-dropdown-title {
  357. .down {
  358. transform: rotate(180deg);
  359. }
  360. }
  361. .header-menu-dropdown-list {
  362. display: flex;
  363. flex-direction: column;
  364. }
  365. }
  366. }
  367. .header-menu-user {
  368. width: 16.667vh;
  369. height: 100%;
  370. margin: 0;
  371. padding: 0;
  372. list-style: none;
  373. .header-menu-user-title {
  374. display: flex;
  375. align-items: center;
  376. justify-content: center;
  377. width: 100%;
  378. height: 100%;
  379. color: @gray;
  380. cursor: pointer;
  381. i {
  382. margin: 0 0.741vh;
  383. font-size: 14px;
  384. }
  385. .el-dropdown-link {
  386. color: #05bb4c;
  387. font-size: 14px;
  388. }
  389. }
  390. }
  391. }
  392. .warning {
  393. display: flex;
  394. align-items: center;
  395. color: #7a8385;
  396. }
  397. .dropdown {
  398. .el-dropdown-menu {
  399. background: #111d1c;
  400. border-radius: 3px;
  401. .el-dropdown-menu__item {
  402. color: #dfeef1;
  403. &:hover {
  404. color: #05bb4c;
  405. }
  406. }
  407. }
  408. }
  409. </style>