Menu.vue 9.3 KB

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