refactor(deps): migrate to nuxt v4
This commit is contained in:
52
app/app.vue
Normal file
52
app/app.vue
Normal file
@@ -0,0 +1,52 @@
|
||||
<script setup lang="ts">
|
||||
import ModalAuthentication from '~/components/ModalAuthentication.vue'
|
||||
|
||||
const toast = useToast()
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
const modal = useModal()
|
||||
const loginState = useLoginState()
|
||||
|
||||
useHead({
|
||||
titleTemplate(title) {
|
||||
return title ? `${title} - AIGC 微课视频研创平台` : 'AIGC 微课视频研创平台'
|
||||
},
|
||||
})
|
||||
|
||||
useSeoMeta({
|
||||
viewport: 'width=device-width, initial-scale=1.0, user-scalable=no',
|
||||
})
|
||||
|
||||
onMounted(() => {
|
||||
loginState.checkSession().then(async (loggedIn) => {
|
||||
if (route.meta.preventLoginCheck) return
|
||||
if (!loggedIn && loginState.token) {
|
||||
toast.add({
|
||||
title: '登录失效',
|
||||
description: '登录已过期,请重新登录',
|
||||
color: 'red',
|
||||
icon: 'i-tabler-alert-triangle',
|
||||
})
|
||||
modal.open(ModalAuthentication)
|
||||
} else if (!loggedIn && !loginState.token) {
|
||||
// Prevents redirect from register page
|
||||
if (route.path === '/user/register') return
|
||||
router.replace('/user/authenticate')
|
||||
}
|
||||
})
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<NuxtLoadingIndicator />
|
||||
|
||||
<NuxtLayout>
|
||||
<NuxtPage />
|
||||
</NuxtLayout>
|
||||
|
||||
<UModals />
|
||||
<USlideovers />
|
||||
<UNotifications />
|
||||
</div>
|
||||
</template>
|
||||
Reference in New Issue
Block a user