mirror of
https://github.com/jxxghp/MoviePilot-Frontend.git
synced 2026-07-08 17:11:44 +08:00
add NProgress
This commit is contained in:
26
src/main.ts
26
src/main.ts
@@ -8,10 +8,14 @@ import store from '@/store'
|
||||
import '@core/scss/template/index.scss'
|
||||
import '@layouts/styles/index.scss'
|
||||
import '@styles/styles.scss'
|
||||
import NProgress from 'nprogress'
|
||||
import 'nprogress/nprogress.css'
|
||||
import { createApp } from 'vue'
|
||||
|
||||
loadFonts()
|
||||
|
||||
// Nprogress
|
||||
NProgress.configure({ showSpinner: false })
|
||||
|
||||
// Create vue app
|
||||
const app = createApp(App)
|
||||
|
||||
@@ -21,3 +25,23 @@ app
|
||||
.use(router)
|
||||
.use(store)
|
||||
.mount('#app')
|
||||
|
||||
|
||||
// 导航守卫
|
||||
router.beforeEach((to, from, next) => {
|
||||
// 通过 Vuex Store 检查用户是否已登录
|
||||
const isAuthenticated = store.state.auth.token !== null
|
||||
if (to.meta.requiresAuth && !isAuthenticated) {
|
||||
// 如果路由需要登录权限且用户未登录,则跳转到登录页面
|
||||
next('/login')
|
||||
}
|
||||
else {
|
||||
// 否则,允许继续进行路由导航
|
||||
NProgress.start()
|
||||
next()
|
||||
}
|
||||
})
|
||||
|
||||
router.afterEach(() => {
|
||||
NProgress.done()
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user