MenuHD.vue 9.4 KB

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