main.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <template>
  2. <el-main class="layout-main">
  3. <el-scrollbar
  4. class="layout-scrollbar"
  5. ref="layoutScrollbarRef"
  6. v-show="!currentRouteMeta.isLink && !currentRouteMeta.isIframe"
  7. :style="{ minHeight: `calc(100vh - ${headerHeight}` }"
  8. >
  9. <LayoutParentView />
  10. <Footers v-if="getThemeConfig.isFooter" />
  11. </el-scrollbar>
  12. <Links
  13. :style="{ height: `calc(100vh - ${headerHeight}` }"
  14. :meta="currentRouteMeta"
  15. v-if="currentRouteMeta.isLink && !currentRouteMeta.isIframe"
  16. />
  17. <Iframes
  18. :style="{ height: `calc(100vh - ${headerHeight}` }"
  19. :meta="currentRouteMeta"
  20. v-if="currentRouteMeta.isLink && currentRouteMeta.isIframe && isShowLink"
  21. @getCurrentRouteMeta="onGetCurrentRouteMeta"
  22. />
  23. </el-main>
  24. </template>
  25. <script>
  26. import LayoutParentView from '@/layout/routerView/parent.vue';
  27. import Footers from '@/layout/footer/index.vue';
  28. import Links from '@/layout/routerView/link.vue';
  29. import Iframes from '@/layout/routerView/iframes.vue';
  30. export default {
  31. name: 'layoutMain',
  32. components: { LayoutParentView, Footers, Links, Iframes },
  33. data() {
  34. return {
  35. headerHeight: '',
  36. currentRouteMeta: {},
  37. isShowLink: false,
  38. };
  39. },
  40. computed: {
  41. // 获取布局配置信息
  42. getThemeConfig() {
  43. return this.$store.state.themeConfig.themeConfig;
  44. },
  45. },
  46. mounted() {
  47. this.initHeaderHeight();
  48. this.initCurrentRouteMeta(this.$route.meta);
  49. },
  50. methods: {
  51. // 初始化当前路由 meta 信息
  52. initCurrentRouteMeta(meta) {
  53. this.isShowLink = false;
  54. this.currentRouteMeta = meta;
  55. setTimeout(() => {
  56. this.isShowLink = true;
  57. }, 100);
  58. },
  59. // 设置 main 的高度
  60. initHeaderHeight() {
  61. let { isTagsview } = this.$store.state.themeConfig.themeConfig;
  62. if (isTagsview) return (this.headerHeight = `84px`);
  63. else return (this.headerHeight = `50px`);
  64. },
  65. // 子组件触发更新
  66. onGetCurrentRouteMeta() {
  67. this.initCurrentRouteMeta(this.$route.meta);
  68. },
  69. },
  70. watch: {
  71. // 监听 vuex 数据变化
  72. '$store.state.themeConfig.themeConfig': {
  73. handler(val) {
  74. this.headerHeight = val.isTagsview ? '84px' : '50px';
  75. if (val.isFixedHeaderChange !== val.isFixedHeader) {
  76. if (!this.$refs.layoutScrollbarRef) return false;
  77. this.$refs.layoutScrollbarRef.update();
  78. }
  79. },
  80. deep: true,
  81. },
  82. // 监听路由的变化
  83. $route: {
  84. handler(to) {
  85. this.initCurrentRouteMeta(to.meta);
  86. this.$refs.layoutScrollbarRef.wrap.scrollTop = 0;
  87. },
  88. deep: true,
  89. },
  90. },
  91. };
  92. </script>