Menu.vue 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430
  1. <template>
  2. <el-aside :width="!isCollapse ? '250px' : '100px'" class="asideBox">
  3. <div class="homeBox">
  4. <div class="logoItem" :class="{ 'flexCenter ': isCollapse }">
  5. <div
  6. class="logoImg"
  7. v-show="isCollapse"
  8. @click="
  9. handleChangeMenuUrl(
  10. { name: '驾驶舱', id: 1, path: 'cockpitManage', iconName: 'gps' },
  11. `/home/cockpitManage?name=驾驶舱`
  12. )
  13. "
  14. >
  15. <SvgIcons
  16. name="dnao"
  17. class="dnao"
  18. width="40px"
  19. height="40px"
  20. color="#222"
  21. ></SvgIcons>
  22. </div>
  23. <span v-if="!isCollapse" @click="
  24. handleChangeMenuUrl(
  25. { name: '驾驶舱', id: 1, path: 'cockpitManage', iconName: 'gps' },
  26. `/home/cockpitManage?name=驾驶舱`
  27. )
  28. " :class="isCollapse ? 'stop-animation' : 'active-animation'">
  29. 风机运行管理平台
  30. </span>
  31. </div>
  32. </div>
  33. <el-menu
  34. collapse-transition
  35. ref="menu"
  36. class="mt-3 el-menu-vertical-demo"
  37. @open="handleOpen"
  38. @close="handleClose"
  39. background-color="#eff1f3"
  40. text-color="#000"
  41. active-text-color="#0754a1"
  42. :router="true"
  43. :default-active="defaultActive"
  44. :unique-opened="true"
  45. :collapse="isCollapse"
  46. >
  47. <div v-for="item in routerList" :key="item.id">
  48. <el-submenu
  49. :index="item.path"
  50. v-if="item.children && item.children.length > 0"
  51. >
  52. <template slot="title">
  53. <i class="el-icon-menu" v-if="isElPrefix(item.iconName)"></i>
  54. <i v-else class="svnIcon"
  55. ><svg-icon :icon-class="item.iconName"
  56. /></i>
  57. <span>{{ item.name }}</span>
  58. </template>
  59. <el-menu-item
  60. v-for="child in item.children"
  61. :key="child.id"
  62. :index="`/home/${item.path}/${child.path}?id=${child.id}&name=${child.name}`"
  63. >
  64. <i class="el-icon-menu" v-if="isElPrefix(child.iconName)"></i>
  65. <i v-else class="svnIcon"
  66. ><svg-icon :icon-class="child.iconName"
  67. /></i>
  68. <span>{{ child.name }}</span>
  69. </el-menu-item>
  70. </el-submenu>
  71. <el-menu-item
  72. :key="item.id"
  73. :index="`/home/${item.path}?id=${item.id}&name=${item.name}`"
  74. v-else
  75. >
  76. <i class="el-icon-menu" v-if="isElPrefix(item.iconName)"></i>
  77. <i v-else class="svnIcon"><svg-icon :icon-class="item.iconName" /></i>
  78. <span>{{ item.name }}</span>
  79. </el-menu-item>
  80. </div>
  81. </el-menu>
  82. <div class="foldBox flexCenter">
  83. <span v-show="isCollapse" class="el-icon-s-unfold icon" @click="debouncedToggleCollapse(false)">
  84. 展开
  85. </span>
  86. <span v-show="!isCollapse" class="el-icon-s-fold icon" @click="debouncedToggleCollapse(true)">
  87. 收起
  88. </span>
  89. </div>
  90. </el-aside>
  91. </template>
  92. <script>
  93. import debounce from "lodash/debounce";
  94. import { orgList } from "./mockData";
  95. export default {
  96. data() {
  97. return {
  98. isCollapse: false,
  99. orgList: orgList,
  100. searchInputValue: "",
  101. defaultActive: "",
  102. activeIndex: false,
  103. keyObject: {},
  104. routerList: [
  105. {
  106. id: 1,
  107. path: "cockpitManage",
  108. name: "驾驶舱",
  109. iconName: "gps",
  110. meta: {
  111. hidden: false,
  112. },
  113. children: [
  114. {
  115. id: 11,
  116. iconName: "gps",
  117. path: "electronic-map",
  118. name: "电子地图",
  119. meta: {
  120. hidden: false,
  121. },
  122. },
  123. ],
  124. },
  125. ],
  126. };
  127. },
  128. created() {
  129. this.routerList = [
  130. ...this.routerList,
  131. ...this.$store.state.auth.dynamicRouter,
  132. ];
  133. console.log(this.routerList, "组件内dynamicRouter");
  134. // Debounce the toggle collapse function to prevent rapid toggling
  135. this.debouncedToggleCollapse = debounce(this.toggleCollapse, 300);
  136. },
  137. computed: {
  138. // currentMenuIndex() {
  139. // return this.$store.state.breadStore?.currentUrl?.routeUrl;
  140. // },
  141. },
  142. watch: {
  143. // currentMenuIndex: {
  144. // deep: true,
  145. // handler(newVale, oldVal) {
  146. // if (newVale) {
  147. // this.$refs.menu.close(newVale);
  148. // }
  149. // },
  150. // },
  151. keyObject: {
  152. deep: true,
  153. handler(newVale) {
  154. if (newVale && newVale.key === this.defaultActive) {
  155. this.getBreadcrumbList(newVale.keyPath);
  156. }
  157. },
  158. },
  159. },
  160. methods: {
  161. isElPrefix(str) {
  162. const regex = /^el-/;
  163. return regex.test(str);
  164. },
  165. getBreadcrumbList(keyPath) {
  166. const urls = keyPath;
  167. const result = urls.map((url, index) => {
  168. const params = new URLSearchParams(url.split("?")[1]);
  169. const id = params.get("id");
  170. const name = params.get("name");
  171. const routeUrl = url;
  172. if (index === urls.length - 1) {
  173. return { id, name, routeUrl, currentPage: true };
  174. }
  175. return { id, name, routeUrl };
  176. });
  177. this.$store.commit("breadStore/ADD_BREAD", result);
  178. return result;
  179. },
  180. handleOpen(key, keyPath) {
  181. this.activeIndex = false;
  182. this.keyObject = {
  183. key,
  184. keyPath,
  185. };
  186. },
  187. handleClose(key, keyPath) {
  188. this.activeIndex = false;
  189. this.keyObject = {
  190. key,
  191. keyPath,
  192. };
  193. },
  194. // shrinkTree() {
  195. // this.$refs.menu.close(`/orgsPage?id=${orgList.id}&name=${orgList.name}`);
  196. // },
  197. // handleChangeRouter() {
  198. // this.activeIndex = true;
  199. // this.defaultActive = "";
  200. // this.$store.commit("breadStore/ADD_BREAD", []);
  201. // this.$refs.menu.close(`/orgsPage?id=${orgList.id}&name=${orgList.name}`);
  202. // this.$router.push("/");
  203. // },
  204. handleChangeMenuUrl(item, key) {
  205. this.defaultActive = key;
  206. if (item) {
  207. item.activeIndex = true;
  208. }
  209. this.$router.push({
  210. path: key,
  211. });
  212. },
  213. toggleCollapse(value) {
  214. this.isCollapse = value;
  215. },
  216. },
  217. };
  218. </script>
  219. <style lang="scss" scoped>
  220. .el-menu-vertical-demo:not(.el-menu--collapse) {
  221. width: 200px;
  222. min-height: 400px;
  223. }
  224. ::v-deep .el-submenu__title {
  225. display: flex;
  226. align-items: center;
  227. }
  228. .asideBox {
  229. position: relative;
  230. padding-bottom: 40px;
  231. padding-top: 16px;
  232. box-sizing: border-box;
  233. display: flex;
  234. align-items: flex-start;
  235. justify-content: flex-start;
  236. flex-direction: column;
  237. border-right: 1px solid #d8d8d8;
  238. position: relative;
  239. .homeBox {
  240. width: 100%;
  241. padding: 0 20px;
  242. display: flex;
  243. flex-direction: column;
  244. align-items: flex-start;
  245. justify-content: flex-start;
  246. box-sizing: border-box;
  247. .logoItem {
  248. display: flex;
  249. width: 100%;
  250. cursor: pointer;
  251. box-sizing: border-box;
  252. span {
  253. line-height: 50px;
  254. margin: 0 auto;
  255. }
  256. .logoImg {
  257. img {
  258. height: 100%;
  259. width: inherit;
  260. }
  261. width: 50px;
  262. height: 50px;
  263. }
  264. }
  265. .search {
  266. display: flex;
  267. width: 100%;
  268. align-items: center;
  269. justify-content: center;
  270. .el-icon-search {
  271. margin-top: 28px;
  272. }
  273. .el-input {
  274. width: inherit;
  275. }
  276. }
  277. .frame {
  278. display: flex;
  279. justify-content: space-between;
  280. align-items: center;
  281. color: #666;
  282. width: 100%;
  283. margin-top: 20px;
  284. margin-bottom: 10px;
  285. cursor: pointer;
  286. .homeIndex {
  287. display: flex;
  288. justify-content: center;
  289. align-items: center;
  290. font-size: 18px;
  291. .home_active {
  292. margin-right: 2px;
  293. }
  294. p {
  295. color: #666;
  296. font-size: 18px;
  297. }
  298. }
  299. &:hover {
  300. p {
  301. color: #19436d;
  302. }
  303. transition: width 0.5s ease, transform 0.5s ease;
  304. transform-origin: left;
  305. }
  306. .left {
  307. left: 50%;
  308. transform: scaleX(0);
  309. }
  310. .right {
  311. left: 0;
  312. transform: scaleX(0);
  313. }
  314. }
  315. }
  316. .el-menu {
  317. margin-bottom: 10px;
  318. border: none;
  319. overflow-y: auto;
  320. width: 100% !important;
  321. height: 100%;
  322. }
  323. }
  324. .flexCenter {
  325. display: flex;
  326. align-items: center !important;
  327. justify-content: center !important;
  328. }
  329. // .foldBox {
  330. // position: fixed;
  331. // bottom: 10px;
  332. // left: 20px;
  333. // padding: 10px;
  334. // .icon {
  335. // cursor: pointer;
  336. // color: #666;
  337. // font-size: 14px;
  338. // }
  339. // }
  340. /* 添加过渡效果 */
  341. .foldBox .icon {
  342. transition: opacity 0.3s ease;
  343. }
  344. /* 菜单 icon 居中展示 */
  345. .foldBox {
  346. display: flex;
  347. align-items: center;
  348. }
  349. .foldBox .icon {
  350. cursor: pointer;
  351. color: #666;
  352. font-size: 14px;
  353. margin-right: 8px;
  354. /* 调整图标与文字之间的间距 */
  355. }
  356. .foldBox .icon:last-child {
  357. margin-right: 0;
  358. /* 最后一个图标不设置右边距 */
  359. }
  360. ::v-deep .el-submenu__title {
  361. display: flex;
  362. align-items: center;
  363. }
  364. ::v-deep .el-submenu__icon-arrow {
  365. right: 30px;
  366. }
  367. ::v-deep .svnIcon {
  368. vertical-align: middle;
  369. margin-right: 5px;
  370. width: 24px;
  371. text-align: center;
  372. font-size: 18px;
  373. }
  374. ::-webkit-scrollbar {
  375. width: 6px;
  376. display: none;
  377. }
  378. ::-webkit-scrollbar-thumb {
  379. border-radius: 10px;
  380. background-color: #aaabaa;
  381. cursor: pointer;
  382. }
  383. ::-webkit-scrollbar-thumb:hover {
  384. background-color: #efeff0;
  385. }
  386. ::-webkit-scrollbar-track-piece {
  387. background-color: #efeff0;
  388. border-radius: 10px;
  389. }
  390. .asideBox:hover ::-webkit-scrollbar {
  391. display: block !important;
  392. }
  393. </style>