MenuHD.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  1. 56<template>
  2. <el-menu
  3. collapse-transition
  4. ref="menu"
  5. mode="horizontal"
  6. class="mt-3 el-menu-vertical-demo"
  7. @open="handleOpen"
  8. @close="handleClose"
  9. :active-text-color="activeTextColor"
  10. :router="true"
  11. :default-active="defaultActive"
  12. :default-openeds="openMenus"
  13. >
  14. <template v-for="(item, indexMenu) in routerList">
  15. <!-- 判断是否是中间位置 -->
  16. <el-menu-item
  17. class="hdMenuTitle"
  18. v-if="indexMenu === Math.floor(routerList.length / 2) + 1"
  19. >
  20. <div class="titles">
  21. <span class="headerText">风电机组健康度诊断平台</span>
  22. </div>
  23. </el-menu-item>
  24. <el-submenu
  25. class="menuParentItem"
  26. :style="{
  27. transform:
  28. indexMenu < Math.floor(routerList.length / 2) + 1
  29. ? 'scaleX(-1)'
  30. : 'scaleX(1)',
  31. }"
  32. v-if="
  33. item.children && item.children.length && item.meta?.hidden === false
  34. "
  35. :index="item.path"
  36. >
  37. <template slot="title">
  38. <span
  39. :style="{
  40. transform:
  41. indexMenu < Math.floor(routerList.length / 2) + 1
  42. ? 'scaleX(-1)'
  43. : 'scaleX(1)',
  44. }"
  45. >{{ item.name }}</span
  46. >
  47. </template>
  48. <el-menu-item
  49. v-for="child in item.children"
  50. v-if="child.meta?.hidden === false"
  51. :key="child.id"
  52. :index="`${child.path}?id=${child.id}`"
  53. @click="handleChangeMenuUrl(child, `${child.path}?id=${child.id}`)"
  54. >
  55. <span>{{ child.name }}</span>
  56. </el-menu-item>
  57. </el-submenu>
  58. <el-menu-item
  59. class="menuParentItem"
  60. :style="{
  61. transform:
  62. indexMenu < Math.floor(routerList.length / 2) + 1
  63. ? 'scaleX(-1)'
  64. : 'scaleX(1)',
  65. color: '#fff',
  66. }"
  67. v-else-if="item.meta?.hidden === false"
  68. :key="item.id"
  69. :index="`${item.path}?id=${item.id}`"
  70. @click="handleChangeMenuUrl(item, `${item.path}?id=${item.id}`)"
  71. >
  72. <span
  73. :style="{
  74. transform:
  75. indexMenu < Math.floor(routerList.length / 2) + 1
  76. ? 'scaleX(-1)'
  77. : 'scaleX(1)',
  78. }"
  79. >{{ item.name }}</span
  80. >
  81. </el-menu-item>
  82. </template>
  83. </el-menu>
  84. </template>
  85. <script>
  86. import { mapActions, mapState } from "vuex";
  87. import { orgList } from "./mockData";
  88. import Vue from "vue";
  89. export default {
  90. data() {
  91. return {
  92. isExpanded: false, // 控制是否展开所有子菜单
  93. openMenus: [], // 用来存储展开的菜单
  94. isCollapse: true,
  95. orgList: orgList,
  96. searchInputValue: "",
  97. defaultActive: this.$route.fullPath,
  98. activeIndex: false,
  99. keyObject: {},
  100. activeTextColor: Vue.prototype.$backgroundColor,
  101. routerList: [
  102. {
  103. id: 1,
  104. path: "/home/cockpitManage",
  105. name: "首页",
  106. iconName: "gps",
  107. meta: {
  108. hidden: false,
  109. },
  110. },
  111. ],
  112. };
  113. },
  114. created() {
  115. this.routerList = [
  116. ...this.routerList,
  117. ...this.$store.state.auth.dynamicRouter,
  118. ];
  119. },
  120. computed: {
  121. ...mapState({
  122. currentMenuIndex: (state) => state.breadStore?.currentUrl?.routeUrl,
  123. }),
  124. // 获取所有父级菜单的 index
  125. allMenuIndexes() {
  126. return this.routerList.map((item) => {
  127. if (
  128. item.children &&
  129. item.children.length &&
  130. item.meta?.hidden === false
  131. ) {
  132. return item.path;
  133. } else {
  134. return `${item.path}?id=${item.id}`;
  135. }
  136. });
  137. },
  138. },
  139. watch: {
  140. currentMenuIndex: {
  141. deep: true,
  142. handler(newVale, oldVal) {
  143. if (newVale) {
  144. this.$refs.menu.close(newVale);
  145. }
  146. },
  147. },
  148. keyObject: {
  149. deep: true,
  150. handler(newVale) {
  151. if (newVale && newVale.key === this.defaultActive) {
  152. this.getBreadcrumbList(newVale.keyPath);
  153. }
  154. },
  155. },
  156. },
  157. methods: {
  158. ...mapActions("menuTag", ["addTag"]),
  159. // 切换展开/收起所有菜单
  160. toggleAllMenus() {
  161. this.isExpanded = !this.isExpanded;
  162. if (this.isExpanded) {
  163. // 展开所有子菜单
  164. this.openMenus = this.routerList
  165. .filter((item) => item.children && item.children.length)
  166. .map((item) => item.path);
  167. } else {
  168. // 收起所有子菜单
  169. this.openMenus = [];
  170. }
  171. },
  172. handleChangeMenuUrl(item, path) {
  173. this.defaultActive = path;
  174. this.$router.push(path); // 跳转到指定的路由
  175. },
  176. isElPrefix(str) {
  177. const regex = /^el-/;
  178. return regex.test(str);
  179. },
  180. getBreadcrumbList(keyPath) {
  181. const urls = keyPath;
  182. const result = urls.map((url, index) => {
  183. const params = new URLSearchParams(url.split("?")[1]);
  184. const id = params.get("id");
  185. const name = params.get("name");
  186. const routeUrl = url;
  187. if (index === urls.length - 1) {
  188. return { id, name, routeUrl, currentPage: true };
  189. }
  190. return { id, name, routeUrl };
  191. });
  192. this.$store.commit("breadStore/ADD_BREAD", result);
  193. return result;
  194. },
  195. handleOpen(key, keyPath) {
  196. this.activeIndex = false;
  197. this.keyObject = {
  198. key,
  199. keyPath,
  200. };
  201. },
  202. handleClose(key, keyPath) {
  203. this.activeIndex = false;
  204. this.keyObject = {
  205. key,
  206. keyPath,
  207. };
  208. },
  209. shrinkTree() {
  210. this.$refs.menu.close(`/orgsPage?id=${orgList.id}&name=${orgList.name}`);
  211. },
  212. handleChangeRouter() {
  213. this.activeIndex = true;
  214. this.defaultActive = "";
  215. this.$store.commit("breadStore/ADD_BREAD", []);
  216. this.$refs.menu.close(`/orgsPage?id=${orgList.id}&name=${orgList.name}`);
  217. this.$router.push("/");
  218. },
  219. handleChangeMenuUrl(item, key) {
  220. this.defaultActive = key;
  221. if (item) {
  222. item.activeIndex = true;
  223. }
  224. const tag = {
  225. path: key,
  226. name: item.name,
  227. label: item.name,
  228. };
  229. this.addTag(tag);
  230. this.$router.push({
  231. path: key,
  232. });
  233. },
  234. },
  235. };
  236. </script>
  237. <style lang="scss" scoped>
  238. ::v-deep.menuParentItem .el-submenu__title,
  239. ::v-deep.menuParentItem .el-submenu__title:hover {
  240. background: #eff1f300 !important;
  241. color: #fff !important;
  242. }
  243. :v-deep.menuParentItem .el-submenu__title:hover {
  244. color: #eee !important;
  245. }
  246. ::v-deep .menuParentItem,
  247. ::v-deep .menuParentItem:hover {
  248. background-image: url("../../../assets/head-tab.png") !important;
  249. background-repeat: no-repeat !important;
  250. background-position: center !important;
  251. background-size: 100%, 100% !important;
  252. height: 60px !important;
  253. width: 140px !important;
  254. display: flex !important;
  255. align-items: center !important;
  256. justify-content: center !important;
  257. background-color: #eff1f300 !important;
  258. }
  259. ::v-deep.el-menu {
  260. background-color: #eff1f300 !important;
  261. }
  262. ::v-deep.hdMenuTitle,
  263. ::v-deep.hdMenuTitle:hover {
  264. background-color: #1b3b7f !important;
  265. padding: 0px !important;
  266. }
  267. ::v-deep.titles,
  268. ::v-deep.titles:hover {
  269. width: 100% !important;
  270. background-image: url("../../../assets/headerBorder.png") !important;
  271. background-size: 35%, 100% !important;
  272. background-repeat: repeat-x !important;
  273. padding: 0px !important;
  274. }
  275. ::v-deep.headerText {
  276. pointer-events: none;
  277. background-image: url("../../../assets/headerText.png") !important;
  278. background-size: 100% 100%;
  279. color: #fff;
  280. font-size: 18px;
  281. font-weight: 600;
  282. text-align: center;
  283. display: block;
  284. width: 100%;
  285. height: 45px;
  286. padding: 0px 30px;
  287. display: flex;
  288. align-items: center;
  289. justify-content: center;
  290. }
  291. ::v-deep.mt-3 {
  292. margin-top: 0px !important;
  293. padding-left: 20px;
  294. }
  295. .stop-animation,
  296. .active-animation {
  297. font-size: 0px;
  298. }
  299. .flexCenter {
  300. display: flex;
  301. align-items: center !important;
  302. justify-content: space-between !important;
  303. width: 200px;
  304. }
  305. .foldBox {
  306. position: fixed;
  307. bottom: 10px;
  308. left: 20px;
  309. padding: 10px;
  310. .icon {
  311. cursor: pointer;
  312. color: #666;
  313. font-size: 14px;
  314. }
  315. }
  316. ::v-deep .el-submenu__title {
  317. display: flex;
  318. align-items: center;
  319. margin-left: 15px;
  320. }
  321. ::v-deep .el-submenu__icon-arrow {
  322. right: 30px;
  323. }
  324. ::v-deep .svnIcon {
  325. vertical-align: middle;
  326. margin-right: 5px;
  327. width: 24px;
  328. text-align: center;
  329. font-size: 18px;
  330. }
  331. ::-webkit-scrollbar {
  332. width: 6px;
  333. display: none;
  334. }
  335. ::-webkit-scrollbar-thumb {
  336. border-radius: 10px;
  337. background-color: #aaabaa;
  338. cursor: pointer;
  339. }
  340. ::-webkit-scrollbar-thumb:hover {
  341. background-color: #efeff0;
  342. }
  343. ::-webkit-scrollbar-track-piece {
  344. background-color: #efeff0;
  345. border-radius: 10px;
  346. }
  347. .asideBox:hover ::-webkit-scrollbar {
  348. display: block !important;
  349. }
  350. /* 当前选中项的颜色 */
  351. .el-menu--horizontal .el-menu-item.is-active {
  352. color: #fff !important;
  353. }
  354. </style>