index.vue 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <template>
  2. <div :class="{ 'has-logo': showLogo }" :style="{ backgroundColor: sideTheme === 'theme-dark' ? variables.menuBackground : variables.menuLightBackground }">
  3. <logo v-if="showLogo" :collapse="isCollapse" />
  4. <el-scrollbar :class="sideTheme" wrap-class="scrollbar-wrapper">
  5. <el-menu
  6. :default-active="activeMenu"
  7. :collapse="isCollapse"
  8. :background-color="sideTheme === 'theme-dark' ? variables.menuBackground : variables.menuLightBackground"
  9. :text-color="sideTheme === 'theme-dark' ? variables.menuColor : variables.menuLightColor"
  10. :unique-opened="true"
  11. :active-text-color="theme"
  12. :collapse-transition="false"
  13. mode="vertical"
  14. >
  15. <sidebar-item
  16. v-for="(route, index) in sidebarRouters"
  17. :key="route.path + index"
  18. :item="route"
  19. :base-path="route.path"
  20. />
  21. </el-menu>
  22. </el-scrollbar>
  23. </div>
  24. </template>
  25. <script setup>
  26. import Logo from './Logo'
  27. import SidebarItem from './SidebarItem'
  28. import variables from '@/assets/styles/variables.module.scss'
  29. import useAppStore from '@/store/modules/app'
  30. import useSettingsStore from '@/store/modules/settings'
  31. import usePermissionStore from '@/store/modules/permission'
  32. const route = useRoute();
  33. const appStore = useAppStore()
  34. const settingsStore = useSettingsStore()
  35. const permissionStore = usePermissionStore()
  36. const sidebarRouters = computed(() => permissionStore.sidebarRouters);
  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. </script>