Menu.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566
  1. <template>
  2. <template v-if="$store.state.menuState % 2">
  3. <div class="menu">
  4. <ul class="menu-list l1">
  5. <li
  6. class="menu-item"
  7. v-for="(menu, index) in currentMenu"
  8. :key="index"
  9. @click="click(index)"
  10. :class="{ active: activeIndex == index }"
  11. >
  12. <router-link
  13. :to="menu.path"
  14. v-if="menu?.children?.length"
  15. @mouseenter="subMenuShow(menu?.children, index)"
  16. >
  17. <el-tooltip
  18. class="item"
  19. effect="dark"
  20. :content="menu.text"
  21. placement="bottom"
  22. :show-after="500"
  23. :enterable="false"
  24. hide-after="10"
  25. >
  26. <div
  27. class="menu-icon svg-icon"
  28. :class="
  29. activeIndex == index ? 'svg-icon-green' : 'svg-icon-gray'
  30. "
  31. >
  32. <SvgIcon :svgid="menu.icon" v-if="menu.icon"></SvgIcon>
  33. <el-icon v-else-if="menu.elIcon" :size="20" style="position:relative;left:-4px">
  34. <component :is="menu.elIcon"></component>
  35. </el-icon>
  36. </div>
  37. </el-tooltip>
  38. </router-link>
  39. <router-link :to="menu.path" v-else>
  40. <el-tooltip
  41. class="item"
  42. effect="dark"
  43. :content="menu.text"
  44. placement="bottom"
  45. :show-after="500"
  46. :enterable="false"
  47. hide-after="10"
  48. >
  49. <div
  50. class="menu-icon svg-icon"
  51. :class="
  52. activeIndex == index ? 'svg-icon-green' : 'svg-icon-gray'
  53. "
  54. >
  55. <SvgIcon :svgid="menu.icon" v-if="menu.icon"></SvgIcon>
  56. <el-icon v-else-if="menu.elIcon" :size="20" style="position:relative;left:-4px">
  57. <component :is="menu.elIcon"></component>
  58. </el-icon>
  59. </div>
  60. </el-tooltip>
  61. </router-link>
  62. <!-- <el-tooltip
  63. v-else
  64. class="item"
  65. effect="dark"
  66. :content="menu.text"
  67. placement="bottom"
  68. :show-after="500"
  69. :enterable="false"
  70. hide-after="10"
  71. >
  72. <div
  73. class="menu-icon svg-icon"
  74. :class="activeIndex == index ? 'svg-icon-green' : 'svg-icon-gray'"
  75. >
  76. <SvgIcon :svgid="menu.icon"></SvgIcon>
  77. </div>
  78. </el-tooltip> -->
  79. </li>
  80. </ul>
  81. </div>
  82. <div class="sub-menu" v-show="isShowSubMenu" @mouseleave="subMenuHide">
  83. <ul class="menu-list l2">
  84. <li
  85. class="menu-item"
  86. v-for="(menus, indexs) in subMenu"
  87. @click="subclick(indexs)"
  88. :key="indexs"
  89. :class="{ active: subIndex == parentIndex + '' + indexs }"
  90. >
  91. <router-link :to="menus.path">
  92. <div class="menu-icon svg-icon">
  93. <!-- <SvgIcon :svgid="menu.icon"></SvgIcon> -->
  94. </div>
  95. <div
  96. class="sub-menu-text"
  97. :class="subIndex == activeIndex + '' + indexs ? 'green' : 'gray'"
  98. >
  99. {{ menus.text }}
  100. </div>
  101. </router-link>
  102. </li>
  103. </ul>
  104. </div>
  105. <div
  106. class="icon-fixed svg-icon"
  107. :class="fixed ? 'svg-icon-green' : 'svg-icon-gray'"
  108. @click="handleClickFixed"
  109. >
  110. <SvgIcon svgid="svg-unfixed" v-if="fixed == false"></SvgIcon>
  111. <SvgIcon svgid="svg-fixed" v-if="fixed == true"></SvgIcon>
  112. </div>
  113. </template>
  114. <template v-else>
  115. <div class="menu">
  116. <ul class="menu-list l3">
  117. <li
  118. class="menu-item"
  119. v-for="(menu, index) in currentMenu"
  120. :key="index"
  121. @click="click(index)"
  122. :class="{ active: activeIndex == index }"
  123. >
  124. <router-link
  125. :to="menu.path"
  126. v-if="menu?.children?.length"
  127. @mouseenter="subMenuShow(menu?.children, index)"
  128. >
  129. <el-tooltip
  130. class="item"
  131. effect="dark"
  132. :content="menu.text"
  133. placement="bottom"
  134. :show-after="500"
  135. :enterable="false"
  136. hide-after="10"
  137. >
  138. <div
  139. class="menu-icon svg-icon"
  140. :class="
  141. activeIndex == index ? 'svg-icon-green' : 'svg-icon-gray'
  142. "
  143. >
  144. <SvgIcon :svgid="menu.icon" v-if="menu.icon"></SvgIcon>
  145. <el-icon v-else-if="menu.elIcon" :size="20" style="position:relative;left:-4px">
  146. <component :is="menu.elIcon"></component>
  147. </el-icon>
  148. </div>
  149. </el-tooltip>
  150. </router-link>
  151. <router-link :to="menu.path" v-else>
  152. <el-tooltip
  153. class="item"
  154. effect="dark"
  155. :content="menu.text"
  156. placement="bottom"
  157. :show-after="500"
  158. :enterable="false"
  159. hide-after="10"
  160. >
  161. <div
  162. class="menu-icon svg-icon"
  163. :class="
  164. activeIndex == index ? 'svg-icon-green' : 'svg-icon-gray'
  165. "
  166. >
  167. <SvgIcon :svgid="menu.icon" v-if="menu.icon"></SvgIcon>
  168. <el-icon v-else-if="menu.elIcon" :size="20" style="position:relative;left:-4px">
  169. <component :is="menu.elIcon"></component>
  170. </el-icon>
  171. </div>
  172. </el-tooltip>
  173. </router-link>
  174. <!-- <el-tooltip
  175. v-else
  176. class="item"
  177. effect="dark"
  178. :content="menu.text"
  179. placement="bottom"
  180. :show-after="500"
  181. :enterable="false"
  182. hide-after="10"
  183. >
  184. <div
  185. class="menu-icon svg-icon"
  186. :class="activeIndex == index ? 'svg-icon-green' : 'svg-icon-gray'"
  187. >
  188. <SvgIcon :svgid="menu.icon"></SvgIcon>
  189. </div>
  190. </el-tooltip> -->
  191. </li>
  192. </ul>
  193. </div>
  194. <div class="sub-menu" v-show="isShowSubMenu" @mouseleave="subMenuHide">
  195. <ul class="menu-list l4">
  196. <li
  197. class="menu-item"
  198. v-for="(menus, indexs) in subMenu"
  199. @click="subclick(indexs)"
  200. :key="indexs"
  201. :class="{ active: subIndex == parentIndex + '' + indexs }"
  202. >
  203. <router-link :to="menus.path">
  204. <div class="menu-icon svg-icon">
  205. <!-- <SvgIcon :svgid="menu.icon"></SvgIcon> -->
  206. </div>
  207. <div
  208. class="sub-menu-text"
  209. :class="subIndex == activeIndex + '' + indexs ? 'green' : 'gray'"
  210. >
  211. {{ menus.text }}
  212. </div>
  213. </router-link>
  214. </li>
  215. </ul>
  216. </div>
  217. <div
  218. class="icon-fixed svg-icon"
  219. :class="fixed ? 'svg-icon-green' : 'svg-icon-gray'"
  220. @click="handleClickFixed"
  221. >
  222. <SvgIcon svgid="svg-unfixed" v-if="fixed == false"></SvgIcon>
  223. <SvgIcon svgid="svg-fixed" v-if="fixed == true"></SvgIcon>
  224. </div>
  225. </template>
  226. </template>
  227. <script>
  228. import SvgIcon from "@com/coms/icon/svg-icon.vue";
  229. import { fillterMenuRoutes } from "@/utills/handleRoutes.js";
  230. export default {
  231. components: {
  232. SvgIcon,
  233. },
  234. props: {},
  235. data() {
  236. return {
  237. currRoot: "home",
  238. menuData: [
  239. {
  240. id: "stateMonitor",
  241. text: "全景监视",
  242. data: [],
  243. },
  244. {
  245. id: "economicsOperation",
  246. text: "经济运行",
  247. data: [],
  248. },
  249. {
  250. id: "integratedAlarm",
  251. text: "综合报警",
  252. data: [],
  253. },
  254. {
  255. id: "health",
  256. text: "智慧检修",
  257. data: [],
  258. },
  259. {
  260. id: "generatingCap",
  261. text: "发电能力分析",
  262. data: [],
  263. },
  264. {
  265. id: "powerPrediction",
  266. text: "功率预测",
  267. data: [],
  268. },
  269. {
  270. id: "sxReport",
  271. text: "报表管理",
  272. data: [],
  273. },
  274. ],
  275. activeIndex: 0,
  276. isShowSubMenu: false,
  277. parentIndex: -1,
  278. subMenu: [],
  279. subIndex: -1,
  280. fixed: true,
  281. reFresh: true,
  282. rePagePath: [
  283. "/economicsOperation/stationAnalyse/stationElectricAnalyse",
  284. "/economicsOperation/windAnalyse/singleWindAnasyle",
  285. ],
  286. };
  287. },
  288. methods: {
  289. handleClickFixed() {
  290. this.fixed = !this.fixed;
  291. this.$store.commit("changeIsFixed", this.fixed);
  292. },
  293. fillterMenuRoutes,
  294. click(index) {
  295. // this.reFresh = false;
  296. this.activeIndex = index;
  297. this.subIndex = index + "" + 0;
  298. },
  299. subMenuShow(children, index) {
  300. this.isShowSubMenu = true;
  301. this.parentIndex = index;
  302. this.subMenu = Array.isArray(children) ? children : [];
  303. },
  304. subMenuHide() {
  305. this.isShowSubMenu = false;
  306. this.parentIndex = -1;
  307. this.subMenu = [];
  308. },
  309. subclick(index) {
  310. this.reFresh = false;
  311. this.activeIndex = this.parentIndex;
  312. this.subIndex = this.activeIndex + "" + index;
  313. this.isShowSubMenu = false;
  314. },
  315. },
  316. computed: {
  317. currentMenu() {
  318. let stateRoutes = JSON.parse(
  319. // JSON.stringify(this.$store.state.routes.routes)
  320. JSON.stringify(this.$router.options.routes)
  321. );
  322. if (stateRoutes.length) {
  323. let routeObj = stateRoutes.find((i) => i.path == "/" + this.currRoot);
  324. let currData = [];
  325. if (routeObj && Object.keys(routeObj).length) {
  326. let a = JSON.parse(JSON.stringify(routeObj));
  327. if (a?.children?.length) {
  328. a.children.forEach((path) => {
  329. if (!path.hidden) {
  330. if (path.showChild != true && path?.children?.length) {
  331. currData.push({
  332. text: path.meta.title,
  333. icon: path.meta.icon || "",
  334. elIcon: path.meta.elIcon || "",
  335. fullPath: path.path,
  336. path: `/${this.currRoot}/${path.path}`,
  337. children: [],
  338. });
  339. let cu = currData.find((i) => i.text == path.meta.title);
  340. path.children.forEach((cputh) => {
  341. let caputh = "";
  342. if (cputh.path.includes(":")) {
  343. caputh = `${cputh.path.substring(
  344. 0,
  345. cputh.path.indexOf("/:")
  346. )}/SXJ_KGDL_GJY_FDC_STA/SXJ_KGDL_GJY_F_WT_0001_EQ`;
  347. } else if (cputh.path == "decision1Mx") {
  348. caputh = "";
  349. } else {
  350. caputh = cputh.path;
  351. }
  352. if (caputh.length) {
  353. cu["children"].push({
  354. text: cputh.meta.title,
  355. icon: path.meta.icon || "",
  356. elIcon: path.meta.elIcon || "",
  357. path: `/${this.currRoot}/${path.path}/${caputh}`,
  358. children: [],
  359. });
  360. }
  361. });
  362. cu.path = cu.children[0].path;
  363. } else {
  364. currData.push({
  365. text: path.meta.title,
  366. icon: path.meta.icon || "",
  367. elIcon: path.meta.elIcon || "",
  368. fullPath: path.path,
  369. path: `/${this.currRoot}/${path.path}`,
  370. children: [],
  371. });
  372. }
  373. }
  374. });
  375. this.$store.commit("changeMenuData", currData);
  376. return currData;
  377. } else {
  378. this.$store.commit("changeMenuData", []);
  379. return [];
  380. }
  381. } else {
  382. this.$store.commit("changeMenuData", []);
  383. return [];
  384. }
  385. } else {
  386. this.$store.commit("changeMenuData", []);
  387. return [];
  388. }
  389. },
  390. isFixed() {
  391. return JSON.parse(localStorage.getItem("isFixed"));
  392. },
  393. },
  394. watch: {
  395. isFixed: {
  396. handler(val) {
  397. if (!val) {
  398. this.$store.commit("changeIsFixed", true);
  399. } else {
  400. this.fixed = val;
  401. }
  402. },
  403. immediate: true,
  404. },
  405. // 监听路由
  406. $route: {
  407. handler: function (val, oldVal) {
  408. // if (this.reFresh) {
  409. this.menuData.some((element, index) => {
  410. if (val.path.includes(element.id)) {
  411. this.$nextTick(() => {
  412. this.currRoot = element.id;
  413. this.$nextTick(() => {
  414. this.currentMenu.forEach((element, index) => {
  415. if (val.path.includes(element.fullPath)) {
  416. this.activeIndex = index;
  417. element.children &&
  418. element.children.forEach((i, inx) => {
  419. if (val.path == i.path) {
  420. this.subIndex = index + "" + inx;
  421. }
  422. });
  423. return true;
  424. }
  425. });
  426. });
  427. });
  428. return true;
  429. }
  430. });
  431. if (val.path.includes("/home")) {
  432. this.currRoot = "home";
  433. this.activeIndex = 0;
  434. return;
  435. }
  436. // }
  437. // this.reFresh = true;
  438. const someRes = this.rePagePath.some((path) => {
  439. return path === val.path;
  440. });
  441. if (someRes) {
  442. this.$nextTick(() => {
  443. this.$store.commit("changeMenuState");
  444. });
  445. } else {
  446. this.$store.commit("changeMenuState");
  447. }
  448. },
  449. //深度观察监听
  450. deep: true,
  451. },
  452. },
  453. };
  454. </script>
  455. <style lang="less">
  456. .menu {
  457. padding-top: 20px;
  458. z-index: 3001;
  459. .menu-list {
  460. margin: 0;
  461. padding: 0;
  462. list-style: none;
  463. .menu-item {
  464. padding: 20px 0;
  465. text-align: center;
  466. .menu-icon {
  467. display: flex;
  468. justify-content: center;
  469. }
  470. &.active i {
  471. color: #05bb4c;
  472. transition: color 1s;
  473. }
  474. }
  475. }
  476. i {
  477. font-size: 16px;
  478. color: rgba(255, 255, 255, 50%);
  479. }
  480. }
  481. .sub-menu {
  482. position: absolute;
  483. top: 0;
  484. left: 50px;
  485. width: 184px;
  486. height: 100%;
  487. padding-top: 10px;
  488. background: fade(#192a26, 75);
  489. border-right: 1px solid fade(@green, 50);
  490. box-shadow: inset 11px 0px 20px 0px fade(#021412, 60);
  491. .menu-list {
  492. margin: 0;
  493. padding: 0;
  494. list-style: none;
  495. .menu-item {
  496. display: flex;
  497. text-align: center;
  498. line-height: 1.5;
  499. padding: 8px 0;
  500. background: #121d1c;
  501. a {
  502. display: flex;
  503. width: 100%;
  504. height: 100%;
  505. padding: 0 10px;
  506. font-size: 14px;
  507. text-decoration: unset;
  508. white-space: nowrap;
  509. .menu-icon {
  510. display: flex;
  511. align-items: center;
  512. svg {
  513. width: 14px;
  514. height: 14px;
  515. use {
  516. fill: fade(@green, 75);
  517. }
  518. }
  519. }
  520. }
  521. &.active {
  522. background: #323e70;
  523. .menu-icon {
  524. display: flex;
  525. svg use {
  526. fill: fade(@white, 75);
  527. }
  528. }
  529. }
  530. .sub-menu-text {
  531. margin-left: 10px;
  532. color: @gray-l;
  533. }
  534. & + .menu-item {
  535. border-top: 1px solid fade(@darkgray, 40);
  536. }
  537. }
  538. }
  539. i {
  540. font-size: 2.222vh;
  541. color: rgba(255, 255, 255, 50%);
  542. }
  543. }
  544. .icon-fixed {
  545. padding-bottom: 20px;
  546. }
  547. </style>