Files
mayfly-go/mayfly_go_web/src/views/layout/component/main.vue

76 lines
2.7 KiB
Vue
Raw Normal View History

<template>
<el-main class="layout-main">
2023-03-15 11:41:03 +08:00
<el-scrollbar class="layout-scrollbar" ref="layoutScrollbarRef"
v-show="!state.currentRouteMeta.link && state.currentRouteMeta.linkType != 1"
2023-03-15 11:41:03 +08:00
:style="{ minHeight: `calc(100vh - ${state.headerHeight}` }">
<LayoutParentView />
2023-03-15 11:41:03 +08:00
<Footer v-if="themeConfig.isFooter" />
</el-scrollbar>
2023-03-15 11:41:03 +08:00
<Link :style="{ height: `calc(100vh - ${state.headerHeight}` }" :meta="state.currentRouteMeta"
v-if="state.currentRouteMeta.link && state.currentRouteMeta.linkType == 2" />
2023-03-15 11:41:03 +08:00
<Iframes :style="{ height: `calc(100vh - ${state.headerHeight}` }" :meta="state.currentRouteMeta"
v-if="state.currentRouteMeta.link && state.currentRouteMeta.linkType == 1 && state.isShowLink"
2023-03-15 11:41:03 +08:00
@getCurrentRouteMeta="onGetCurrentRouteMeta" />
</el-main>
</template>
2023-03-15 11:41:03 +08:00
<script setup lang="ts" name="layoutMain">
import { reactive, getCurrentInstance, watch, onBeforeMount } from 'vue';
import { useRoute } from 'vue-router';
2023-03-15 11:41:03 +08:00
import { storeToRefs } from 'pinia';
import { useThemeConfig } from '@/store/themeConfig';
import LayoutParentView from '@/views/layout/routerView/parent.vue';
import Footer from '@/views/layout/footer/index.vue';
import Link from '@/views/layout/routerView/link.vue';
import Iframes from '@/views/layout/routerView/iframes.vue';
2023-03-15 11:41:03 +08:00
const { proxy } = getCurrentInstance() as any;
const { themeConfig } = storeToRefs(useThemeConfig());
const route = useRoute();
const state = reactive({
headerHeight: '',
currentRouteMeta: {} as any,
isShowLink: false,
});
// 子组件触发更新
const onGetCurrentRouteMeta = () => {
initCurrentRouteMeta(route.meta);
};
// 初始化当前路由 meta 信息
const initCurrentRouteMeta = (meta: object) => {
state.isShowLink = false;
state.currentRouteMeta = meta;
setTimeout(() => {
state.isShowLink = true;
}, 100);
};
// 设置 main 的高度
const initHeaderHeight = () => {
let { isTagsview } = themeConfig.value;
if (isTagsview) return (state.headerHeight = `84px`);
else return (state.headerHeight = `50px`);
};
// 页面加载前
onBeforeMount(() => {
initCurrentRouteMeta(route.meta);
initHeaderHeight();
});
// 监听 themeConfig 配置文件的变化,更新菜单 el-scrollbar 的高度
watch(themeConfig.value, (val) => {
state.headerHeight = val.isTagsview ? '84px' : '50px';
if (val.isFixedHeaderChange !== val.isFixedHeader) {
if (!proxy.$refs.layoutScrollbarRef) return false;
proxy.$refs.layoutScrollbarRef.update();
}
});
2023-03-15 11:41:03 +08:00
// 监听路由的变化
watch(
() => route.path,
() => {
initCurrentRouteMeta(route.meta);
proxy.$refs.layoutScrollbarRef.wrapRef.scrollTop = 0;
}
);
</script>