Header.vue 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  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"></li>
  42. </ul>
  43. </div>
  44. </template>
  45. <script>
  46. import $ from "jquery";
  47. import { getCookie } from "@/utills/auth";
  48. import tools from "../../tools/encryption.js";
  49. import { logout } from "@/api/common.js";
  50. import { encrypt, decrypt } from "@/utills/jsencrypt.js";
  51. import SvgIcon from "@/components/coms/icon/svg-icon.vue";
  52. export default {
  53. data() {
  54. return {
  55. themeName: false,
  56. menus: [
  57. {
  58. id: "home",
  59. text: "首页",
  60. path: "/home",
  61. isActive: true,
  62. },
  63. {
  64. id: "stateMonitor",
  65. text: "监视中心",
  66. path: "/stateMonitor",
  67. isActive: true,
  68. },
  69. {
  70. id: "integratedAlarm",
  71. text: "综合报警",
  72. path: "/integratedAlarm",
  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: "report",
  90. text: "智能报表",
  91. path: "/report",
  92. isActive: false,
  93. },
  94. ],
  95. activeIndex: 0,
  96. // menusDropdown: [
  97. // {
  98. // text: "子菜单1",
  99. // code: "submenu1",
  100. // },
  101. // {
  102. // text: "子菜单2",
  103. // code: "submenu2",
  104. // },
  105. // {
  106. // text: "子菜单3",
  107. // code: "submenu3",
  108. // },
  109. // ],
  110. // dropdown: false,
  111. firsttime: 0,
  112. };
  113. },
  114. components: { SvgIcon },
  115. mounted() {
  116. // let that = this;
  117. // $(document).keydown((event) => {
  118. // if (event.keyCode == 192) {
  119. // // c
  120. // // let firstDate = new Date();
  121. // // if (that.firsttime == 0) {
  122. // // that.firsttime = firstDate.getTime();
  123. // // } else {
  124. // // var lastDate = new Date();
  125. // // var lastTime = lastDate.getTime();
  126. // // if (lastTime - that.firsttime < 1000) {
  127. // // that.changeTheme();
  128. // // that.firsttime = 0;
  129. // // }
  130. // // }
  131. // that.changeTheme();
  132. // }
  133. // });
  134. },
  135. computed: {
  136. userName() {
  137. return getCookie("username") || this.$store.state.user.username;
  138. },
  139. // activeClass(data) {
  140. // return data.isActive ? "active" : "";
  141. // },
  142. currMenu() {
  143. let stateRoutes = this.$store.state.routes.routes;
  144. let currMenu = [];
  145. if (stateRoutes.length) {
  146. stateRoutes.forEach((route) => {
  147. if (route.path !== "/login") {
  148. currMenu.push({
  149. id: route.name,
  150. text: route.meta.title,
  151. path: route.path,
  152. isActive: false,
  153. });
  154. }
  155. });
  156. // currMenu.splice(2, 0, {
  157. // id: "zhbj",
  158. // text: "综合报警",
  159. // path: "",
  160. // });
  161. // currMenu.splice(5, 0, {
  162. // id: "fdfx",
  163. // text: "发电能力分析",
  164. // path: "",
  165. // });
  166. // currMenu.push();
  167. return currMenu;
  168. } else {
  169. return [];
  170. }
  171. },
  172. },
  173. methods: {
  174. click(index, data) {
  175. if (data.id === "zhbj") {
  176. let jiami = encrypt(getCookie("jiami")).replace(/\+/g, " ");
  177. // let url = `http://192.168.1.117:3002/#/check?username=${getCookie(
  178. // "username"
  179. // )}&jiami=${jiami}`;
  180. let url = `http://10.81.3.154:8083/#/check?username=${getCookie(
  181. "username"
  182. )}&jiami=${jiami}`;
  183. window.open(url);
  184. return;
  185. } else if (data.id === "fdfx") {
  186. let jiami = encrypt(getCookie("jiami")).replace(/\+/g, " ");
  187. // let url = `http://192.168.1.117:3002/#/check?username=${getCookie(
  188. // "username"
  189. // )}&jiami=${jiami}`;
  190. let url = `http://10.81.3.155:8083/dlfx/#/check?username=${getCookie(
  191. "username"
  192. )}&jiami=${jiami}`;
  193. window.open(url);
  194. return;
  195. } else if (data.id === "home") {
  196. this.$emit("changeShowSisView", true);
  197. this.activeIndex = index;
  198. this.$router.push(data.path);
  199. const ActiveModule = this.currMenu.find((ele) => {
  200. return ele.path === data.path;
  201. });
  202. if (ActiveModule) {
  203. this.$store.dispatch("changeModuleName", ActiveModule.text);
  204. }
  205. return;
  206. }
  207. this.activeIndex = index;
  208. this.$router.push(data.path);
  209. const ActiveModule = this.currMenu.find((ele) => {
  210. return ele.path === data.path;
  211. });
  212. if (ActiveModule) {
  213. this.$store.dispatch("changeModuleName", ActiveModule.text);
  214. }
  215. },
  216. clickSubMenu(index, code) {},
  217. clickMenu() {
  218. this.dropdown = !this.dropdown;
  219. },
  220. changeTheme() {
  221. $("#appBody").toggleClass("dark light");
  222. this.$store.dispatch("changeTheme", $("#appBody").attr("class"));
  223. this.$store.state.themeName === "dark"
  224. ? (this.themeName = false)
  225. : (this.themeName = true);
  226. localStorage.setItem("themeName", this.$store.state.themeName);
  227. },
  228. handleCommand(command) {
  229. if (command == "logout") {
  230. logout({
  231. token: getCookie("authToken"),
  232. userId: getCookie("userId"),
  233. }).then((res) => {
  234. this.$store.commit("user/REMOVE_TOKEN");
  235. this.$store.commit("changeStationAll", []);
  236. this.$router.push("/login");
  237. });
  238. }
  239. },
  240. // 跳转到管理系统
  241. goToAdmin() {
  242. let jiami = encrypt(getCookie("jiami")).replace(/\+/g, " ");
  243. // let url = `http://192.168.1.104:80/#/check?username=${getCookie(
  244. let url = `http://10.81.3.127:8083/#/check?username=${getCookie(
  245. "username"
  246. )}&jiami=${jiami}`;
  247. window.open(url);
  248. },
  249. },
  250. watch: {
  251. $route: {
  252. handler: function (val, oldVal) {
  253. if (this.currMenu.length) {
  254. this.currMenu.some((t, index) => {
  255. if (val.path.includes(t.id)) {
  256. this.activeIndex = index;
  257. const ActiveModule = this.currMenu.find((ele) => {
  258. return ele.path === t.path;
  259. });
  260. if (ActiveModule) {
  261. this.$store.dispatch("changeModuleName", ActiveModule.text);
  262. }
  263. }
  264. });
  265. }
  266. },
  267. //深度观察监听
  268. deep: true,
  269. },
  270. },
  271. };
  272. </script>
  273. <style>
  274. .admin-set-tooltip {
  275. font-size: 14px !important;
  276. }
  277. </style>
  278. <style lang="less" scoped>
  279. .header-menu {
  280. display: flex;
  281. width: 100%;
  282. height: 100%;
  283. font-size: @fontsize;
  284. justify-content: flex-end;
  285. .header-menu-list {
  286. margin: 0;
  287. padding: 0;
  288. list-style: none;
  289. display: flex;
  290. height: 100%;
  291. .header-menu-item {
  292. display: flex;
  293. align-items: center;
  294. justify-content: center;
  295. padding: 0 15px;
  296. // width: 9.259vh;
  297. height: 100%;
  298. color: @font-color;
  299. cursor: pointer;
  300. transition: color 0.2s ease-in-out;
  301. &.active {
  302. color: @green;
  303. position: relative;
  304. background: @greenLinearTop;
  305. transition: color 0.2s ease-in-out;
  306. &::after {
  307. content: "";
  308. position: absolute;
  309. width: 100%;
  310. height: 3px;
  311. border: 1px solid @green;
  312. border-top: 0;
  313. left: 0;
  314. bottom: 0;
  315. box-sizing: border-box;
  316. }
  317. }
  318. }
  319. }
  320. .header-menu-user {
  321. width: 10%;
  322. height: 100%;
  323. margin: 0;
  324. padding: 0;
  325. list-style: none;
  326. display: flex;
  327. align-items: center;
  328. .header-menu-user-title {
  329. display: flex;
  330. align-items: center;
  331. justify-content: center;
  332. width: 100%;
  333. height: 100%;
  334. color: @gray;
  335. cursor: pointer;
  336. i {
  337. margin: 0 5px;
  338. font-size: 16px;
  339. }
  340. .el-dropdown-link {
  341. color: #05bb4c;
  342. font-size: 16px;
  343. }
  344. }
  345. }
  346. }
  347. .warning {
  348. display: flex;
  349. align-items: center;
  350. color: #7a8385;
  351. }
  352. .dropdown {
  353. .el-dropdown-menu {
  354. background: #111d1c;
  355. border-radius: 3px;
  356. .el-dropdown-menu__item {
  357. color: #dfeef1;
  358. font-size: 14px !important;
  359. &:hover {
  360. color: #05bb4c;
  361. }
  362. }
  363. }
  364. }
  365. </style>