Files
mayfly-go/frontend/src/layout/component/main.vue

54 lines
1.6 KiB
Vue
Raw Normal View History

<template>
2025-08-19 19:44:14 +08:00
<el-main class="layout-main h-full">
<el-scrollbar ref="layoutScrollbarRef" view-class="h-full">
<LayoutParentView />
</el-scrollbar>
2025-08-04 21:02:27 +08:00
<el-backtop target=".layout-backtop .el-main .el-scrollbar__wrap"></el-backtop>
</el-main>
2023-12-15 17:33:22 +08:00
<el-footer v-if="themeConfig.isFooter">
<Footer />
</el-footer>
</template>
2023-03-15 11:41:03 +08:00
<script setup lang="ts" name="layoutMain">
2025-08-19 19:44:14 +08:00
import { watch, defineAsyncComponent, useTemplateRef, nextTick, onMounted } from 'vue';
import { useRoute } from 'vue-router';
2023-03-15 11:41:03 +08:00
import { storeToRefs } from 'pinia';
import { useThemeConfig } from '@/store/themeConfig';
const LayoutParentView = defineAsyncComponent(() => import('@/layout/routerView/parent.vue'));
const Footer = defineAsyncComponent(() => import('@/layout/footer/index.vue'));
2023-03-15 11:41:03 +08:00
2025-08-19 19:44:14 +08:00
const layoutScrollbarRef = useTemplateRef('layoutScrollbarRef');
2023-03-15 11:41:03 +08:00
const { themeConfig } = storeToRefs(useThemeConfig());
const route = useRoute();
// 监听 themeConfig 配置文件的变化,更新菜单 el-scrollbar 的高度
watch(themeConfig.value, (val) => {
if (val.isFixedHeaderChange !== val.isFixedHeader) {
2025-08-19 19:44:14 +08:00
if (!layoutScrollbarRef.value) {
return;
}
layoutScrollbarRef.value.update();
2023-03-15 11:41:03 +08:00
}
});
2025-08-19 19:44:14 +08:00
2023-03-15 11:41:03 +08:00
// 监听路由的变化
watch(
() => route.path,
() => {
2025-08-19 19:44:14 +08:00
nextTick(() => {
if (!layoutScrollbarRef.value) {
return;
}
setTimeout(() => {
layoutScrollbarRef.value.update();
}, 500);
layoutScrollbarRef.value.setScrollTop();
});
2023-03-15 11:41:03 +08:00
}
);
</script>