main.vue 2.2 KB

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