index.vue 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 :default-active="activeMenu" :collapse="isCollapse" :background-color="bgColor" :text-color="textColor" :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 Logo from './Logo.vue';
  15. import SidebarItem from './SidebarItem.vue';
  16. import variables from '@/assets/styles/variables.module.scss';
  17. import useAppStore from '@/store/modules/app';
  18. import useSettingsStore from '@/store/modules/settings';
  19. import usePermissionStore from '@/store/modules/permission';
  20. import { RouteRecordRaw } from 'vue-router';
  21. import { useSideNumStore } from '@/store/modules/sideNum';
  22. const { proxy } = getCurrentInstance() as ComponentInternalInstance;
  23. const route = useRoute();
  24. const appStore = useAppStore();
  25. const settingsStore = useSettingsStore();
  26. const permissionStore = usePermissionStore();
  27. const sidebarRouters = computed<RouteRecordRaw[]>(() => permissionStore.getSidebarRoutes());
  28. const showLogo = computed(() => settingsStore.sidebarLogo);
  29. const sideTheme = computed(() => settingsStore.sideTheme);
  30. const theme = computed(() => settingsStore.theme);
  31. const isCollapse = computed(() => !appStore.sidebar.opened);
  32. const activeMenu = computed(() => {
  33. const { meta, path } = route;
  34. console.log(route);
  35. // if set path, the sidebar will highlight the path you set
  36. if (route.name) {
  37. console.log(route.name);
  38. return (route.path as string).split('-')[0];
  39. }
  40. return path;
  41. });
  42. // const activeMenu = computed(() => {
  43. // const { meta, path } = route;
  44. // // if set path, the sidebar will highlight the path you set
  45. // if (route.name) {
  46. // return (route.name as string).split('-')[0];
  47. // }
  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. onMounted(() => {
  52. // 设置侧边栏数字配置
  53. useSideNumStore().setMultipleApiConfigs({
  54. '/appointment-record/experience': {
  55. apiUrl: '/dgtmedicine/bookingInfo/getUnconfirmedCount',
  56. },
  57. '/appointment-record/appointment-record': {
  58. isParent: true,
  59. children: ['/appointment-record/experience']
  60. },
  61. });
  62. // 刷新侧边栏数字
  63. useSideNumStore().refreshAllCounts();
  64. console.log(useSideNumStore().menuCounts);
  65. });
  66. </script>