index.vue 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <template>
  2. <div class="sidebar-no-logo" :style="{ backgroundColor: bgColor }">
  3. <el-scrollbar :class="sideTheme" wrap-class="scrollbar-wrapper">
  4. <transition :enter-active-class="proxy?.animate.menuSearchAnimate.enter" mode="out-in">
  5. <el-menu :default-active="activeMenu" :collapse="isCollapse" :background-color="bgColor" :text-color="textColor"
  6. :unique-opened="true" :active-text-color="theme" :collapse-transition="false" mode="vertical">
  7. <sidebar-item v-for="(r, index) in sidebarRouters" :key="r.path + index" :item="r" :base-path="r.path" />
  8. </el-menu>
  9. </transition>
  10. </el-scrollbar>
  11. </div>
  12. </template>
  13. <script setup lang="ts">
  14. import SidebarItem from './SidebarItem.vue';
  15. import variables from '@/assets/styles/variables.module.scss';
  16. import useAppStore from '@/store/modules/app';
  17. import useSettingsStore from '@/store/modules/settings';
  18. import usePermissionStore from '@/store/modules/permission';
  19. import { RouteRecordRaw } from 'vue-router';
  20. const { proxy } = getCurrentInstance() as ComponentInternalInstance;
  21. const route = useRoute();
  22. const appStore = useAppStore();
  23. const settingsStore = useSettingsStore();
  24. const permissionStore = usePermissionStore();
  25. // 只显示当前一级菜单下的二级菜单
  26. const topMenus = computed(() => permissionStore.getTopbarRoutes().filter((menu) => menu.hidden !== true));
  27. const currentTopMenuPath = computed(() => {
  28. // console.log("[Sidebar] route.path", route.path);
  29. // 特例
  30. if (route.path === '/source/push/approval' || route.path.startsWith('/source/split/edit') || route.path.startsWith('/smsb/itemProgram/edit') || route.path.startsWith('/smsb/itemProgram/preview')) {
  31. return '/source';
  32. }
  33. // 取当前路由的一级菜单 path
  34. const matched = route.matched?.[0];
  35. // console.log("[Sidebar] matched", matched);
  36. // console.log("[Sidebar] ret", matched && matched.path !== '/' ? matched.path : (topMenus.value[0]?.path || '/'));
  37. return matched && matched.path !== '/' ? matched.path : topMenus.value[0]?.path || '/';
  38. });
  39. const sidebarRouters = computed<RouteRecordRaw[]>(() => {
  40. const topMenu = topMenus.value.find((menu) => menu.path === currentTopMenuPath.value);
  41. return topMenu && topMenu.children ? topMenu.children.filter((item) => item.hidden !== true) : [];
  42. });
  43. const showLogo = computed(() => settingsStore.sidebarLogo);
  44. const sideTheme = computed(() => settingsStore.sideTheme);
  45. const theme = computed(() => settingsStore.theme);
  46. const isCollapse = computed(() => !appStore.sidebar.opened);
  47. const activeMenu = computed(() => {
  48. const { meta, path } = route;
  49. // if set path, the sidebar will highlight the path you set
  50. if (meta.activeMenu) {
  51. return meta.activeMenu;
  52. }
  53. return path;
  54. });
  55. const bgColor = computed(() => (sideTheme.value === 'theme-dark' ? variables.menuBackground : variables.menuLightBackground));
  56. const textColor = computed(() => (sideTheme.value === 'theme-dark' ? variables.menuColor : variables.menuLightColor));
  57. </script>