Header.vue 11 KB

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