main.vue 2.1 KB

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