index.vue 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. mode="vertical"
  15. >
  16. <sidebar-item v-for="(route, index) in sidebarRouters" :key="route.path + index" :item="route" :base-path="route.path" />
  17. </el-menu>
  18. </transition>
  19. </el-scrollbar>
  20. </div>
  21. </template>
  22. <script setup lang="ts">
  23. import Logo from './Logo.vue';
  24. import SidebarItem from './SidebarItem.vue';
  25. import variables from '@/assets/styles/variables.module.scss';
  26. import useAppStore from '@/store/modules/app';
  27. import useSettingsStore from '@/store/modules/settings';
  28. import usePermissionStore from '@/store/modules/permission';
  29. import { RouteRecordRaw } from 'vue-router';
  30. const { proxy } = getCurrentInstance() as ComponentInternalInstance;
  31. const route = useRoute();
  32. const appStore = useAppStore();
  33. const settingsStore = useSettingsStore();
  34. const permissionStore = usePermissionStore();
  35. const sidebarRouters = computed<RouteRecordRaw[]>(() => permissionStore.sidebarRouters);
  36. const showLogo = computed(() => settingsStore.sidebarLogo);
  37. const sideTheme = computed(() => settingsStore.sideTheme);
  38. const theme = computed(() => settingsStore.theme);
  39. const isCollapse = computed(() => !appStore.sidebar.opened);
  40. const activeMenu = computed(() => {
  41. const { meta, path } = route;
  42. // if set path, the sidebar will highlight the path you set
  43. if (meta.activeMenu) {
  44. return meta.activeMenu;
  45. }
  46. return path;
  47. });
  48. const bgColor = computed(() => (sideTheme.value === 'theme-dark' ? variables.menuBackground : variables.menuLightBackground));
  49. const textColor = computed(() => (sideTheme.value === 'theme-dark' ? variables.menuColor : variables.menuLightColor));
  50. </script>