2020-12-31 11:47:52 +08:00
|
|
|
|
<template>
|
2021-03-15 12:44:58 +08:00
|
|
|
|
<el-main class="layout-main">
|
|
|
|
|
<el-scrollbar
|
|
|
|
|
class="layout-scrollbar"
|
|
|
|
|
ref="layoutScrollbarRef"
|
2021-07-07 20:16:31 +08:00
|
|
|
|
:style="{
|
2021-10-17 12:32:28 +08:00
|
|
|
|
minHeight: `calc(100vh - ${headerHeight})`,
|
2021-07-07 20:16:31 +08:00
|
|
|
|
padding: currentRouteMeta.isLink && currentRouteMeta.isIframe ? 0 : '',
|
|
|
|
|
transition: 'padding 0.3s ease-in-out',
|
|
|
|
|
}"
|
2021-03-15 12:44:58 +08:00
|
|
|
|
>
|
|
|
|
|
<LayoutParentView />
|
|
|
|
|
<Footer v-if="getThemeConfig.isFooter" />
|
|
|
|
|
</el-scrollbar>
|
|
|
|
|
</el-main>
|
2020-12-31 11:47:52 +08:00
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script lang="ts">
|
2021-03-15 12:44:58 +08:00
|
|
|
|
import { computed, defineComponent, toRefs, reactive, getCurrentInstance, watch, onBeforeMount } from 'vue';
|
2021-06-19 17:49:42 +08:00
|
|
|
|
import { useStore } from '/@/store/index';
|
2021-07-07 20:16:31 +08:00
|
|
|
|
import { useRoute } from 'vue-router';
|
2021-06-19 17:49:42 +08:00
|
|
|
|
import LayoutParentView from '/@/layout/routerView/parent.vue';
|
|
|
|
|
import Footer from '/@/layout/footer/index.vue';
|
2020-12-31 11:47:52 +08:00
|
|
|
|
export default defineComponent({
|
2021-03-15 12:44:58 +08:00
|
|
|
|
name: 'layoutMain',
|
2021-07-07 20:16:31 +08:00
|
|
|
|
components: { LayoutParentView, Footer },
|
2021-03-15 12:44:58 +08:00
|
|
|
|
setup() {
|
|
|
|
|
const { proxy } = getCurrentInstance() as any;
|
|
|
|
|
const route = useRoute();
|
2021-07-07 20:16:31 +08:00
|
|
|
|
const store = useStore();
|
2021-03-15 12:44:58 +08:00
|
|
|
|
const state = reactive({
|
|
|
|
|
headerHeight: '',
|
|
|
|
|
currentRouteMeta: {},
|
|
|
|
|
});
|
|
|
|
|
// 获取布局配置信息
|
|
|
|
|
const getThemeConfig = computed(() => {
|
|
|
|
|
return store.state.themeConfig.themeConfig;
|
|
|
|
|
});
|
|
|
|
|
// 设置 main 的高度
|
|
|
|
|
const initHeaderHeight = () => {
|
|
|
|
|
let { isTagsview } = store.state.themeConfig.themeConfig;
|
|
|
|
|
if (isTagsview) return (state.headerHeight = `84px`);
|
|
|
|
|
else return (state.headerHeight = `50px`);
|
|
|
|
|
};
|
2021-07-07 20:16:31 +08:00
|
|
|
|
// 初始化获取当前路由 meta,用于设置 iframes padding
|
|
|
|
|
const initGetMeta = () => {
|
|
|
|
|
state.currentRouteMeta = route.meta;
|
|
|
|
|
};
|
2021-03-15 12:44:58 +08:00
|
|
|
|
// 页面加载前
|
|
|
|
|
onBeforeMount(() => {
|
|
|
|
|
initHeaderHeight();
|
2021-07-07 20:16:31 +08:00
|
|
|
|
initGetMeta();
|
2021-03-15 12:44:58 +08:00
|
|
|
|
});
|
|
|
|
|
// 监听 themeConfig 配置文件的变化,更新菜单 el-scrollbar 的高度
|
|
|
|
|
watch(store.state.themeConfig.themeConfig, (val) => {
|
|
|
|
|
state.headerHeight = val.isTagsview ? '84px' : '50px';
|
|
|
|
|
if (val.isFixedHeaderChange !== val.isFixedHeader) {
|
|
|
|
|
if (!proxy.$refs.layoutScrollbarRef) return false;
|
|
|
|
|
proxy.$refs.layoutScrollbarRef.update();
|
|
|
|
|
}
|
|
|
|
|
});
|
2021-07-07 20:16:31 +08:00
|
|
|
|
// 监听路由变化
|
2021-03-15 12:44:58 +08:00
|
|
|
|
watch(
|
|
|
|
|
() => route.path,
|
|
|
|
|
() => {
|
2021-07-07 20:16:31 +08:00
|
|
|
|
state.currentRouteMeta = route.meta;
|
2021-03-15 12:44:58 +08:00
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
return {
|
|
|
|
|
getThemeConfig,
|
|
|
|
|
...toRefs(state),
|
|
|
|
|
};
|
|
|
|
|
},
|
2020-12-31 11:47:52 +08:00
|
|
|
|
});
|
|
|
|
|
</script>
|