Header.vue 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  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
  43. effect="dark"
  44. content="后台管理系统"
  45. placement="bottom"
  46. popper-class="admin-set-tooltip"
  47. >
  48. <i class="svg-icon svg-icon-white" @click="goToAdmin">
  49. <SvgIcon svgid="svg-admin-set"></SvgIcon>
  50. </i>
  51. </el-tooltip>
  52. </li>
  53. </ul>
  54. </div>
  55. </template>
  56. <script>
  57. import $ from "jquery";
  58. import { getCookie } from "@/utills/auth";
  59. import tools from "../../tools/encryption.js";
  60. import { logout } from "@/api/common.js";
  61. import { encrypt, decrypt } from "@/utills/jsencrypt.js";
  62. import SvgIcon from "@/components/coms/icon/svg-icon.vue";
  63. export default {
  64. data() {
  65. return {
  66. themeName: false,
  67. menus: [
  68. {
  69. id: "home",
  70. text: "首页",
  71. path: "/home",
  72. isActive: true,
  73. },
  74. {
  75. id: "stateMonitor",
  76. text: "监视中心",
  77. path: "/stateMonitor",
  78. isActive: true,
  79. },
  80. {
  81. id: "integratedAlarm",
  82. text: "综合报警",
  83. path: "/integratedAlarm",
  84. isActive: true,
  85. },
  86. {
  87. id: "economicsOperation",
  88. text: "经济运行",
  89. path: "/economicsOperation",
  90. isActive: false,
  91. },
  92. {
  93. id: "health",
  94. text: "智慧检修",
  95. // path: '/sandtable',
  96. path: "/health",
  97. isActive: false,
  98. },
  99. {
  100. id: "powerGenerating",
  101. text: "发电能力分析",
  102. // path: '/sandtable',
  103. path: "/powerGenerating",
  104. isActive: false,
  105. },
  106. {
  107. id: "report",
  108. text: "智能报表",
  109. path: "/report",
  110. isActive: false,
  111. },
  112. ],
  113. activeIndex: 0,
  114. // menusDropdown: [
  115. // {
  116. // text: "子菜单1",
  117. // code: "submenu1",
  118. // },
  119. // {
  120. // text: "子菜单2",
  121. // code: "submenu2",
  122. // },
  123. // {
  124. // text: "子菜单3",
  125. // code: "submenu3",
  126. // },
  127. // ],
  128. // dropdown: false,
  129. firsttime: 0,
  130. };
  131. },
  132. components: { SvgIcon },
  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" && route.path !== "/") {
  166. currMenu.push({
  167. id: route.name,
  168. text: route.meta.title,
  169. path: route.path,
  170. isActive: false,
  171. });
  172. }
  173. });
  174. // currMenu.splice(2, 0, {
  175. // id: "zhbj",
  176. // text: "综合报警",
  177. // path: "",
  178. // });
  179. // currMenu.splice(5, 0, {
  180. // id: "fdfx",
  181. // text: "发电能力分析",
  182. // path: "",
  183. // });
  184. // currMenu.push();
  185. return currMenu;
  186. } else {
  187. return [];
  188. }
  189. },
  190. },
  191. methods: {
  192. click(index, data) {
  193. if (data.id === "zhbj") {
  194. let jiami = encrypt(getCookie("jiami")).replace(/\+/g, " ");
  195. // let url = `http://192.168.1.117:3002/#/check?username=${getCookie(
  196. // "username"
  197. // )}&jiami=${jiami}`;
  198. let url = `http://10.81.3.154:8083/#/check?username=${getCookie(
  199. "username"
  200. )}&jiami=${jiami}`;
  201. window.open(url);
  202. return;
  203. } else if (data.id === "fdfx") {
  204. let jiami = encrypt(getCookie("jiami")).replace(/\+/g, " ");
  205. // let url = `http://192.168.1.117:3002/#/check?username=${getCookie(
  206. // "username"
  207. // )}&jiami=${jiami}`;
  208. let url = `http://10.81.3.155:8083/dlfx/#/check?username=${getCookie(
  209. "username"
  210. )}&jiami=${jiami}`;
  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.$store.commit("changeStationAll", []);
  243. this.$router.push("/login");
  244. });
  245. }
  246. },
  247. // 跳转到管理系统
  248. goToAdmin() {
  249. let jiami = encrypt(getCookie("jiami")).replace(/\+/g, " ");
  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 === t.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>
  281. .admin-set-tooltip {
  282. font-size: 14px !important;
  283. }
  284. </style>
  285. <style lang="less" scoped>
  286. .header-menu {
  287. display: flex;
  288. width: 100%;
  289. height: 100%;
  290. font-size: @fontsize;
  291. justify-content: flex-end;
  292. .header-menu-list {
  293. margin: 0;
  294. padding: 0;
  295. list-style: none;
  296. display: flex;
  297. height: 100%;
  298. .header-menu-item {
  299. display: flex;
  300. align-items: center;
  301. justify-content: center;
  302. padding: 0 15px;
  303. // width: 9.259vh;
  304. height: 100%;
  305. color: @font-color;
  306. cursor: pointer;
  307. transition: color 0.2s ease-in-out;
  308. &.active {
  309. color: @green;
  310. position: relative;
  311. background: @greenLinearTop;
  312. transition: color 0.2s ease-in-out;
  313. &::after {
  314. content: "";
  315. position: absolute;
  316. width: 100%;
  317. height: 3px;
  318. border: 1px solid @green;
  319. border-top: 0;
  320. left: 0;
  321. bottom: 0;
  322. box-sizing: border-box;
  323. }
  324. }
  325. }
  326. }
  327. .header-menu-user {
  328. width: 10%;
  329. height: 100%;
  330. margin: 0;
  331. padding: 0;
  332. list-style: none;
  333. display: flex;
  334. align-items: center;
  335. .header-menu-user-title {
  336. display: flex;
  337. align-items: center;
  338. justify-content: center;
  339. width: 100%;
  340. height: 100%;
  341. color: @gray;
  342. cursor: pointer;
  343. i {
  344. margin: 0 5px;
  345. font-size: 16px;
  346. }
  347. .el-dropdown-link {
  348. color: #05bb4c;
  349. font-size: 16px;
  350. }
  351. }
  352. }
  353. }
  354. .warning {
  355. display: flex;
  356. align-items: center;
  357. color: #7a8385;
  358. }
  359. .dropdown {
  360. .el-dropdown-menu {
  361. background: #111d1c;
  362. border-radius: 3px;
  363. .el-dropdown-menu__item {
  364. color: #dfeef1;
  365. font-size: 14px !important;
  366. &:hover {
  367. color: #05bb4c;
  368. }
  369. }
  370. }
  371. }
  372. </style>