You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

84 lines
2.4 KiB

  1. <script setup lang="ts">
  2. import Logo from "./logo.vue";
  3. import { emitter } from "/@/utils/mitt";
  4. import SidebarItem from "./sidebarItem.vue";
  5. import { algorithm } from "/@/utils/algorithm";
  6. import { storageLocal } from "/@/utils/storage";
  7. import { useRoute, useRouter } from "vue-router";
  8. import { computed, ref, onBeforeMount } from "vue";
  9. import { useAppStoreHook } from "/@/store/modules/app";
  10. import { usePermissionStoreHook } from "/@/store/modules/permission";
  11. const route = useRoute();
  12. const pureApp = useAppStoreHook();
  13. const router = useRouter().options.routes;
  14. const routeStore = usePermissionStoreHook();
  15. const showLogo = ref(storageLocal.getItem("logoVal") || "1");
  16. const isCollapse = computed(() => {
  17. return !pureApp.getSidebarStatus;
  18. });
  19. const activeMenu = computed((): string => {
  20. const { meta, path } = route;
  21. if (meta.activeMenu) {
  22. // @ts-ignore
  23. return meta.activeMenu;
  24. }
  25. return path;
  26. });
  27. const menuSelect = (indexPath: string): void => {
  28. let parentPath = "";
  29. let parentPathIndex = indexPath.lastIndexOf("/");
  30. if (parentPathIndex > 0) {
  31. parentPath = indexPath.slice(0, parentPathIndex);
  32. }
  33. // 找到当前路由的信息
  34. // eslint-disable-next-line no-inner-declarations
  35. function findCurrentRoute(routes) {
  36. return routes.map(item => {
  37. if (item.path === indexPath) {
  38. // 切换左侧菜单 通知标签页
  39. emitter.emit("changLayoutRoute", {
  40. indexPath,
  41. parentPath
  42. });
  43. } else {
  44. if (item.children) findCurrentRoute(item.children);
  45. }
  46. });
  47. }
  48. findCurrentRoute(algorithm.increaseIndexes(router));
  49. };
  50. onBeforeMount(() => {
  51. emitter.on("logoChange", key => {
  52. showLogo.value = key;
  53. });
  54. });
  55. </script>
  56. <template>
  57. <div :class="['sidebar-container', showLogo ? 'has-logo' : '']">
  58. <Logo v-if="showLogo === '1'" :collapse="isCollapse" />
  59. <el-scrollbar wrap-class="scrollbar-wrapper">
  60. <el-menu
  61. :default-active="activeMenu"
  62. :collapse="isCollapse"
  63. unique-opened
  64. router
  65. :collapse-transition="false"
  66. mode="vertical"
  67. class="outer-most"
  68. @select="menuSelect"
  69. >
  70. <sidebar-item
  71. v-for="route in routeStore.wholeRoutes"
  72. :key="route.path"
  73. :item="route"
  74. class="outer-most"
  75. :base-path="route.path"
  76. />
  77. </el-menu>
  78. </el-scrollbar>
  79. </div>
  80. </template>