classic.vue 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <template>
  2. <el-container class="layout-container flex-center">
  3. <LayoutHeader />
  4. <el-container class="layout-mian-height-50">
  5. <LayoutAside />
  6. <div class="flex-center layout-backtop">
  7. <LayoutTagsView v-if="isTagsview" />
  8. <LayoutMain ref="layoutMainRef" />
  9. </div>
  10. </el-container>
  11. </el-container>
  12. </template>
  13. <script setup lang="ts" name="layoutClassic">
  14. import { defineAsyncComponent, computed, ref, watch, nextTick, onMounted } from 'vue';
  15. import { useRoute } from 'vue-router';
  16. import { storeToRefs } from 'pinia';
  17. import { useThemeConfig } from '/@/stores/themeConfig';
  18. // 引入组件
  19. const LayoutAside = defineAsyncComponent(() => import('/@/layout/component/aside.vue'));
  20. const LayoutHeader = defineAsyncComponent(() => import('/@/layout/component/header.vue'));
  21. const LayoutMain = defineAsyncComponent(() => import('/@/layout/component/main.vue'));
  22. const LayoutTagsView = defineAsyncComponent(() => import('/@/layout/navBars/tagsView/tagsView.vue'));
  23. // 定义变量内容
  24. const layoutMainRef = ref<InstanceType<typeof LayoutMain>>();
  25. const route = useRoute();
  26. const storesThemeConfig = useThemeConfig();
  27. const { themeConfig } = storeToRefs(storesThemeConfig);
  28. // 判断是否显示 tasgview
  29. const isTagsview = computed(() => {
  30. return themeConfig.value.isTagsview;
  31. });
  32. // 重置滚动条高度,更新子级 scrollbar
  33. const updateScrollbar = () => {
  34. layoutMainRef.value?.layoutMainScrollbarRef.update();
  35. };
  36. // 重置滚动条高度,由于组件是异步引入的
  37. const initScrollBarHeight = () => {
  38. nextTick(() => {
  39. setTimeout(() => {
  40. updateScrollbar();
  41. // '!' not null 断言操作符,不执行运行时检查
  42. if (layoutMainRef.value) layoutMainRef.value!.layoutMainScrollbarRef.wrapRef.scrollTop = 0;
  43. }, 500);
  44. });
  45. };
  46. // 页面加载时
  47. onMounted(() => {
  48. initScrollBarHeight();
  49. });
  50. // 监听路由的变化,切换界面时,滚动条置顶
  51. watch(
  52. () => route.path,
  53. () => {
  54. initScrollBarHeight();
  55. }
  56. );
  57. // 监听 themeConfig 配置文件的变化,更新菜单 el-scrollbar 的高度
  58. watch(
  59. themeConfig,
  60. () => {
  61. updateScrollbar();
  62. },
  63. {
  64. deep: true,
  65. }
  66. );
  67. </script>