main.vue 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <template>
  2. <el-main class="layout-main" :style="isFixedHeader ? `height: calc(100% - ${setMainHeight})` : `minHeight: calc(100% - ${setMainHeight})`">
  3. <el-scrollbar
  4. ref="layoutMainScrollbarRef"
  5. class="layout-main-scroll layout-backtop-header-fixed"
  6. wrap-class="layout-main-scroll"
  7. view-class="layout-main-scroll"
  8. >
  9. <LayoutParentView />
  10. <LayoutFooter v-if="isFooter" />
  11. </el-scrollbar>
  12. <el-backtop :target="setBacktopClass" />
  13. </el-main>
  14. </template>
  15. <script setup lang="ts" name="layoutMain">
  16. import { defineAsyncComponent, onMounted, computed, ref } from 'vue';
  17. import { useRoute } from 'vue-router';
  18. import { storeToRefs } from 'pinia';
  19. import { useTagsViewRoutes } from '/@/stores/tagsViewRoutes';
  20. import { useThemeConfig } from '/@/stores/themeConfig';
  21. import { NextLoading } from '/@/utils/loading';
  22. // 引入组件
  23. const LayoutParentView = defineAsyncComponent(() => import('/@/layout/routerView/parent.vue'));
  24. const LayoutFooter = defineAsyncComponent(() => import('/@/layout/footer/index.vue'));
  25. // 定义变量内容
  26. const layoutMainScrollbarRef = ref();
  27. const route = useRoute();
  28. const storesTagsViewRoutes = useTagsViewRoutes();
  29. const storesThemeConfig = useThemeConfig();
  30. const { themeConfig } = storeToRefs(storesThemeConfig);
  31. const { isTagsViewCurrenFull } = storeToRefs(storesTagsViewRoutes);
  32. // 设置 footer 显示/隐藏
  33. const isFooter = computed(() => {
  34. return themeConfig.value.isFooter && !route.meta.isIframe;
  35. });
  36. // 设置 header 固定
  37. const isFixedHeader = computed(() => {
  38. return themeConfig.value.isFixedHeader;
  39. });
  40. // 设置 Backtop 回到顶部
  41. const setBacktopClass = computed(() => {
  42. if (themeConfig.value.isFixedHeader) return `.layout-backtop-header-fixed .el-scrollbar__wrap`;
  43. else return `.layout-backtop .el-scrollbar__wrap`;
  44. });
  45. // 设置主内容区的高度
  46. const setMainHeight = computed(() => {
  47. if (isTagsViewCurrenFull.value) return '0px';
  48. const { isTagsview, layout } = themeConfig.value;
  49. if (isTagsview && layout !== 'classic') return '85px';
  50. else return '51px';
  51. });
  52. // 页面加载前
  53. onMounted(() => {
  54. NextLoading.done(600);
  55. });
  56. // 暴露变量
  57. defineExpose({
  58. layoutMainScrollbarRef,
  59. });
  60. </script>