feat: add session valid chack

This commit is contained in:
maicss
2024-03-01 23:33:50 +08:00
parent 81062d4580
commit 46e1cae0bb
+13 -2
View File
@@ -1,14 +1,25 @@
<script lang="ts" setup> <script lang="ts" setup>
import api from '@/api';
import DefaultLayoutWithVerticalNav from './components/DefaultLayoutWithVerticalNav.vue' import DefaultLayoutWithVerticalNav from './components/DefaultLayoutWithVerticalNav.vue'
const router = useRouter()
const route = useRoute()
document.addEventListener('visibilitychange', () => {
if (document.visibilityState === 'visible') {
api.get('user/current')
.catch(() => {
router.replace('/login')
})
}
})
</script> </script>
<template> <template>
<DefaultLayoutWithVerticalNav> <DefaultLayoutWithVerticalNav>
<router-view v-slot="{ Component }"> <router-view v-slot="{ Component }">
<keep-alive> <keep-alive>
<component :is="Component" v-if="$route.meta.keepAlive" :key="$route.fullPath" /> <component :is="Component" v-if="route.meta.keepAlive" :key="route.fullPath" />
</keep-alive> </keep-alive>
<component :is="Component" v-if="!$route.meta.keepAlive" :key="$route.fullPath" /> <component :is="Component" v-if="!route.meta.keepAlive" :key="route.fullPath" />
</router-view> </router-view>
</DefaultLayoutWithVerticalNav> </DefaultLayoutWithVerticalNav>
</template> </template>