Files
pqs-9100_client/frontend/src/layouts/components/Main/index.vue

84 lines
2.6 KiB
Vue
Raw Normal View History

2024-08-22 11:27:06 +08:00
<template>
<Maximize v-show="maximize" />
2024-08-23 13:19:20 +08:00
<Tabs v-if="tabs && showMenuFlag" />
2024-08-22 11:27:06 +08:00
<el-main>
2024-08-27 15:40:58 +08:00
<router-view v-slot="{ Component, route }" >
2024-08-22 11:27:06 +08:00
<transition appear name="fade-transform" mode="out-in">
<keep-alive :include="keepAliveName">
2024-08-23 13:19:20 +08:00
<component
:is="Component"
v-if="isRouterShow"
:key="route.fullPath"
/>
2024-08-22 11:27:06 +08:00
</keep-alive>
</transition>
</router-view>
</el-main>
<el-footer v-show="footer">
<Footer />
</el-footer>
</template>
<script setup lang="ts">
2024-08-23 13:19:20 +08:00
import { ref, onBeforeUnmount, provide, watch, computed } from "vue";
2024-08-22 11:27:06 +08:00
import { storeToRefs } from "pinia";
import { useDebounceFn } from "@vueuse/core";
import { useGlobalStore } from "@/stores/modules/global";
import { useKeepAliveStore } from "@/stores/modules/keepAlive";
import Maximize from "./components/Maximize.vue";
import Tabs from "@/layouts/components/Tabs/index.vue";
import Footer from "@/layouts/components/Footer/index.vue";
2024-08-23 13:19:20 +08:00
import { useAuthStore } from "@/stores/modules/auth";
2024-08-22 11:27:06 +08:00
const globalStore = useGlobalStore();
2024-08-23 13:19:20 +08:00
const authStore = useAuthStore();
2024-08-22 11:27:06 +08:00
const { maximize, isCollapse, layout, tabs, footer } = storeToRefs(globalStore);
const keepAliveStore = useKeepAliveStore();
const { keepAliveName } = storeToRefs(keepAliveStore);
2024-08-23 13:19:20 +08:00
//是否显示导航栏
const showMenuFlag = computed(() => authStore.showMenuFlagGet);
2024-08-22 11:27:06 +08:00
// 注入刷新页面方法
const isRouterShow = ref(true);
const refreshCurrentPage = (val: boolean) => (isRouterShow.value = val);
provide("refresh", refreshCurrentPage);
// 监听当前页面是否最大化,动态添加 class
watch(
() => maximize.value,
() => {
const app = document.getElementById("app") as HTMLElement;
if (maximize.value) app.classList.add("main-maximize");
else app.classList.remove("main-maximize");
},
{ immediate: true }
);
// 监听布局变化,在 body 上添加相对应的 layout class
watch(
() => layout.value,
() => {
const body = document.body as HTMLElement;
body.setAttribute("class", layout.value);
},
{ immediate: true }
);
// 监听窗口大小变化,折叠侧边栏
const screenWidth = ref(0);
const listeningWindow = useDebounceFn(() => {
screenWidth.value = document.body.clientWidth;
2024-08-23 13:19:20 +08:00
if (!isCollapse.value && screenWidth.value < 1200)
globalStore.setGlobalState("isCollapse", true);
if (isCollapse.value && screenWidth.value > 1200)
globalStore.setGlobalState("isCollapse", false);
2024-08-22 11:27:06 +08:00
}, 100);
window.addEventListener("resize", listeningWindow, false);
onBeforeUnmount(() => {
window.removeEventListener("resize", listeningWindow);
});
</script>
<style scoped lang="scss">
@import "./index.scss";
</style>