Menu.vue 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  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. <SvgIcons
  16. name="dnao"
  17. class="dnao"
  18. width="40px"
  19. height="40px"
  20. color="#222"
  21. ></SvgIcons>
  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. collapse-transition
  38. ref="menu"
  39. class="mt-3 el-menu-vertical-demo"
  40. @open="handleOpen"
  41. @select="handleOpen"
  42. @close="handleClose"
  43. background-color="#eff1f3"
  44. text-color="#000"
  45. active-text-color="#0754a1"
  46. :router="false"
  47. :default-active="defaultActive"
  48. :unique-opened="true"
  49. :collapse="isCollapse"
  50. >
  51. <el-submenu
  52. v-for="(item, index) in orgList"
  53. :key="index"
  54. :index="item.id"
  55. >
  56. <template slot="title">
  57. <div class="flex items-center justify-start">
  58. <i
  59. class="flex items-center justify-center mr-2"
  60. style="margin-left: 3px"
  61. >
  62. <SvgIcons
  63. :name="item.iconName"
  64. class="dnao"
  65. width="20px"
  66. height="22px"
  67. color="#222"
  68. ></SvgIcons>
  69. </i>
  70. <span
  71. slot="title"
  72. style="display: inline-block"
  73. :class="{
  74. 'active-menu':
  75. defaultActive ===
  76. `/windField?id=${item.id}&name=${item.name}`,
  77. }"
  78. >{{ item.name }}</span
  79. >
  80. </div>
  81. </template>
  82. <el-menu-item
  83. v-for="(child, childIndex) in item.children"
  84. :key="childIndex"
  85. :index="`/home/${item.path}/${child.path}?id=${child.id}&name=${child.name}`"
  86. >
  87. <template slot="title">
  88. <span
  89. slot="title"
  90. style="padding-left: 22px; width: 100%; display: inline-block"
  91. :class="{
  92. 'active-menu':
  93. defaultActive === `/dynamo?id=${item.id}&name=${item.name}`,
  94. }"
  95. @click="
  96. handleChangeMenuUrl(
  97. item,
  98. `/home/${item.path}/${child.path}?id=${item.id}&name=${item.name}`
  99. )
  100. "
  101. >{{ child.name }}</span
  102. >
  103. </template>
  104. </el-menu-item>
  105. </el-submenu>
  106. </el-menu>
  107. <div class="foldBox flexCenter">
  108. <span
  109. v-show="isCollapse"
  110. class="el-icon-s-unfold icon"
  111. @click="isCollapse = false"
  112. >展开</span
  113. >
  114. <span
  115. v-show="!isCollapse"
  116. class="el-icon-s-fold icon"
  117. @click="isCollapse = true"
  118. >收起</span
  119. >
  120. </div>
  121. </el-aside>
  122. </template>
  123. <script>
  124. import { orgList } from "./mockData";
  125. export default {
  126. data() {
  127. return {
  128. // 展开收起
  129. isCollapse: false,
  130. // 三级菜单数组
  131. orgList: orgList,
  132. // 搜索值
  133. searchInputValue: "",
  134. defaultActive: "",
  135. activeIndex: false,
  136. keyObject: {},
  137. };
  138. },
  139. computed: {
  140. currentMenuIndex() {
  141. return this.$store.state.breadStore?.currentUrl?.routeUrl;
  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. created() {},
  163. methods: {
  164. getBreadcrumbList(keyPath) {
  165. const urls = keyPath;
  166. const result = urls.map((url, index) => {
  167. const params = new URLSearchParams(url.split("?")[1]); // 解析 URL 参数
  168. const id = params.get("id");
  169. const name = params.get("name");
  170. const routeUrl = url;
  171. // 如果是最后一个路由,则添加额外属性
  172. if (index === urls.length - 1) {
  173. return { id, name, routeUrl, currentPage: true };
  174. }
  175. return { id, name, routeUrl };
  176. });
  177. // console.log(result)
  178. this.$store.commit("breadStore/ADD_BREAD", result);
  179. return result;
  180. },
  181. handleOpen(key, keyPath) {
  182. // console.log(key, keyPath)
  183. this.activeIndex = false;
  184. this.keyObject = {
  185. key,
  186. keyPath,
  187. };
  188. },
  189. handleClose(key, keyPath) {
  190. // console.log(key, keyPath)
  191. this.activeIndex = false;
  192. this.keyObject = {
  193. key,
  194. keyPath,
  195. };
  196. },
  197. shrinkTree() {
  198. this.$refs.menu.close(`/orgsPage?id=${orgList.id}&name=${orgList.name}`);
  199. },
  200. handleChangeRouter() {
  201. this.activeIndex = true;
  202. this.defaultActive = "";
  203. this.$store.commit("breadStore/ADD_BREAD", []);
  204. this.$refs.menu.close(`/orgsPage?id=${orgList.id}&name=${orgList.name}`);
  205. this.$router.push("/");
  206. },
  207. handleChangeMenuUrl(item, key) {
  208. this.defaultActive = key;
  209. if (item) {
  210. item.activeIndex = true;
  211. }
  212. this.$router.push({
  213. path: key,
  214. });
  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. // border-bottom: 1px solid #409eff;
  303. }
  304. // background-color: rgb(64, 158, 255, 0.6);
  305. transition: width 0.5s ease, transform 0.5s ease;
  306. /* 过渡效果 */
  307. transform-origin: left;
  308. /* 设置变换的原点在左侧 */
  309. }
  310. .left {
  311. left: 50%;
  312. transform: scaleX(0);
  313. /* 初始时将左侧元素宽度设为 0 */
  314. }
  315. .right {
  316. left: 0;
  317. transform: scaleX(0);
  318. /* 初始时将右侧元素宽度设为 0 */
  319. }
  320. }
  321. }
  322. .el-menu {
  323. margin-bottom: 10px;
  324. border: none;
  325. overflow-y: auto;
  326. width: 100% !important;
  327. height: 100%;
  328. }
  329. }
  330. .flexCenter {
  331. display: flex;
  332. align-items: center !important;
  333. justify-content: center !important;
  334. }
  335. .foldBox {
  336. position: fixed;
  337. bottom: 10px;
  338. left: 20px;
  339. padding: 10px;
  340. .icon {
  341. cursor: pointer;
  342. color: #666;
  343. font-size: 14px;
  344. }
  345. }
  346. ::v-deep .el-submenu__title {
  347. padding-left: 30px !important;
  348. }
  349. ::v-deep .el-submenu__icon-arrow {
  350. right: 30px;
  351. }
  352. ::-webkit-scrollbar {
  353. width: 6px;
  354. display: none;
  355. }
  356. /* 滚动条上的滚动滑块 */
  357. ::-webkit-scrollbar-thumb {
  358. border-radius: 10px;
  359. background-color: #aaabaa;
  360. cursor: pointer;
  361. }
  362. ::-webkit-scrollbar-thumb:hover {
  363. background-color: #efeff0;
  364. }
  365. /* 滚动条没有滑块的轨道部分 */
  366. ::-webkit-scrollbar-track-piece {
  367. background-color: #efeff0;
  368. border-radius: 10px;
  369. }
  370. .asideBox:hover ::-webkit-scrollbar {
  371. display: block !important;
  372. }
  373. </style>