2020-12-31 11:47:52 +08:00
|
|
|
<template>
|
2021-01-06 18:41:05 +08:00
|
|
|
<el-main>
|
2021-01-10 23:59:43 +08:00
|
|
|
<el-scrollbar class="layout-scrollbar" ref="layoutScrollbarRef"
|
2021-01-25 15:39:59 +08:00
|
|
|
v-show="!currentRouteMeta.isLink && !currentRouteMeta.isIframe"
|
2021-01-10 23:59:43 +08:00
|
|
|
:style="{minHeight: `calc(100vh - ${headerHeight}`}">
|
2021-01-20 18:52:41 +08:00
|
|
|
<LayoutParentView />
|
2021-01-06 18:41:05 +08:00
|
|
|
<Footer v-if="getThemeConfig.isFooter" />
|
2020-12-31 11:47:52 +08:00
|
|
|
</el-scrollbar>
|
2021-01-25 15:39:59 +08:00
|
|
|
<Link :style="{height: `calc(100vh - ${headerHeight}`}" :meta="currentRouteMeta"
|
|
|
|
v-if="currentRouteMeta.isLink && !currentRouteMeta.isIframe" />
|
|
|
|
<Iframes :style="{height: `calc(100vh - ${headerHeight}`}" :meta="currentRouteMeta"
|
|
|
|
v-if="currentRouteMeta.isLink && currentRouteMeta.isIframe" />
|
2020-12-31 11:47:52 +08:00
|
|
|
</el-main>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2021-01-05 18:11:13 +08:00
|
|
|
import {
|
|
|
|
computed,
|
|
|
|
defineComponent,
|
|
|
|
toRefs,
|
|
|
|
reactive,
|
|
|
|
getCurrentInstance,
|
|
|
|
watch,
|
2021-01-25 15:39:59 +08:00
|
|
|
onBeforeMount,
|
2021-01-05 18:11:13 +08:00
|
|
|
} from "vue";
|
2021-01-25 15:39:59 +08:00
|
|
|
import { useRoute } from "vue-router";
|
2021-01-05 18:11:13 +08:00
|
|
|
import { useStore } from "/@/store/index.ts";
|
2021-01-20 18:52:41 +08:00
|
|
|
import LayoutParentView from "/@/views/layout/routerView/parent.vue";
|
2021-01-06 18:41:05 +08:00
|
|
|
import Footer from "/@/views/layout/footer/index.vue";
|
2021-01-25 15:39:59 +08:00
|
|
|
import Link from "/@/views/layout/routerView/link.vue";
|
|
|
|
import Iframes from "/@/views/layout/routerView/iframes.vue";
|
2020-12-31 11:47:52 +08:00
|
|
|
export default defineComponent({
|
|
|
|
name: "layoutMain",
|
2021-01-25 15:39:59 +08:00
|
|
|
components: { LayoutParentView, Footer, Link, Iframes },
|
2020-12-31 11:47:52 +08:00
|
|
|
setup() {
|
2021-01-05 18:11:13 +08:00
|
|
|
const { proxy } = getCurrentInstance();
|
|
|
|
const store = useStore();
|
2021-01-25 15:39:59 +08:00
|
|
|
const route = useRoute();
|
2020-12-31 11:47:52 +08:00
|
|
|
const state = reactive({
|
2021-01-25 15:39:59 +08:00
|
|
|
headerHeight: "",
|
|
|
|
currentRouteMeta: {},
|
2020-12-31 11:47:52 +08:00
|
|
|
});
|
2021-01-10 23:59:43 +08:00
|
|
|
// 获取布局配置信息
|
2021-01-05 18:11:13 +08:00
|
|
|
const getThemeConfig = computed(() => {
|
|
|
|
return store.state.themeConfig;
|
|
|
|
});
|
2021-01-25 15:39:59 +08:00
|
|
|
// 初始化当前路由 meta 信息
|
|
|
|
const initCurrentRouteMeta = (meta: object) => {
|
|
|
|
state.currentRouteMeta = meta;
|
|
|
|
};
|
|
|
|
// 设置 main 的高度
|
|
|
|
const initHeaderHeight = () => {
|
|
|
|
let { isTagsview } = store.state.themeConfig;
|
|
|
|
if (isTagsview) return (state.headerHeight = `84px`);
|
|
|
|
else return (state.headerHeight = `50px`);
|
|
|
|
};
|
|
|
|
// 页面加载前
|
|
|
|
onBeforeMount(() => {
|
|
|
|
initCurrentRouteMeta(route.meta);
|
|
|
|
initHeaderHeight();
|
|
|
|
});
|
2021-01-10 23:59:43 +08:00
|
|
|
// 监听 themeConfig 配置文件的变化,更新菜单 el-scrollbar 的高度
|
2021-01-05 18:11:13 +08:00
|
|
|
watch(store.state.themeConfig, (val) => {
|
2021-01-06 18:41:05 +08:00
|
|
|
state.headerHeight = val.isTagsview ? "84px" : "50px";
|
2021-01-06 13:30:53 +08:00
|
|
|
if (val.isFixedHeaderChange !== val.isFixedHeader) {
|
2021-01-10 23:59:43 +08:00
|
|
|
if (!proxy.$refs.layoutScrollbarRef) return false;
|
2021-01-06 13:30:53 +08:00
|
|
|
proxy.$refs.layoutScrollbarRef.update();
|
|
|
|
}
|
2021-01-05 18:11:13 +08:00
|
|
|
});
|
2021-01-25 15:39:59 +08:00
|
|
|
// 监听路由的变化
|
|
|
|
watch(
|
|
|
|
() => route.path,
|
|
|
|
() => {
|
|
|
|
initCurrentRouteMeta(route.meta);
|
2021-02-20 22:21:24 +08:00
|
|
|
proxy.$refs.layoutScrollbarRef.wrap.scrollTop = 0;
|
2021-01-25 15:39:59 +08:00
|
|
|
}
|
|
|
|
);
|
2021-01-05 18:11:13 +08:00
|
|
|
return {
|
|
|
|
getThemeConfig,
|
2021-01-25 15:39:59 +08:00
|
|
|
initCurrentRouteMeta,
|
2021-01-05 18:11:13 +08:00
|
|
|
...toRefs(state),
|
|
|
|
};
|
2020-12-31 11:47:52 +08:00
|
|
|
},
|
|
|
|
});
|
|
|
|
</script>
|