index.vue 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <template>
  2. <div :class="{ 'has-logo': showLogo }" :style="{ backgroundColor: bgColor }">
  3. <logo v-if="showLogo" :collapse="isCollapse" />
  4. <el-scrollbar :class="sideTheme" wrap-class="scrollbar-wrapper">
  5. <transition :enter-active-class="proxy?.animate.menuSearchAnimate.enter" mode="out-in">
  6. <el-menu
  7. :default-active="activeMenu"
  8. :collapse="isCollapse"
  9. :background-color="bgColor"
  10. :text-color="textColor"
  11. :unique-opened="true"
  12. :active-text-color="theme"
  13. :collapse-transition="false"
  14. :popper-offset="12"
  15. mode="vertical"
  16. >
  17. <sidebar-item v-for="(r, index) in sidebarRouters" :key="r.path + index" :item="r" :base-path="r.path" />
  18. </el-menu>
  19. </transition>
  20. </el-scrollbar>
  21. </div>
  22. </template>
  23. <script setup lang="ts">
  24. import Logo from './Logo.vue';
  25. import SidebarItem from './SidebarItem.vue';
  26. import variables from '@/assets/styles/variables.module.scss';
  27. import { useAppStore } from '@/store/modules/app';
  28. import { useSettingsStore } from '@/store/modules/settings';
  29. import { usePermissionStore } from '@/store/modules/permission';
  30. import { RouteRecordRaw } from 'vue-router';
  31. const { proxy } = getCurrentInstance() as ComponentInternalInstance;
  32. const route = useRoute();
  33. const appStore = useAppStore();
  34. const settingsStore = useSettingsStore();
  35. const permissionStore = usePermissionStore();
  36. const sidebarRouters = computed<RouteRecordRaw[]>(() => permissionStore.getSidebarRoutes());
  37. const showLogo = computed(() => settingsStore.sidebarLogo);
  38. const sideTheme = computed(() => settingsStore.sideTheme);
  39. const theme = computed(() => settingsStore.theme);
  40. const isCollapse = computed(() => !appStore.sidebar.opened);
  41. const activeMenu = computed(() => {
  42. const { meta, path } = route;
  43. // if set path, the sidebar will highlight the path you set
  44. if (meta.activeMenu) {
  45. return meta.activeMenu;
  46. }
  47. return path;
  48. });
  49. const bgColor = computed(() => (sideTheme.value === 'theme-dark' ? variables.menuBackground : variables.menuLightBackground));
  50. const textColor = computed(() => (sideTheme.value === 'theme-dark' ? variables.menuColor : variables.menuLightColor));
  51. </script>