mirror of
https://github.com/jxxghp/MoviePilot-Frontend.git
synced 2026-09-05 23:56:42 +08:00
add logout && fix theme
This commit is contained in:
+38
-1
@@ -10,31 +10,49 @@ const router = createRouter({
|
||||
children: [
|
||||
{
|
||||
path: 'dashboard',
|
||||
component: () => import('../pages/dashboard.vue'),
|
||||
component: () => import('../pages/dashboard.vue')
|
||||
},
|
||||
{
|
||||
path: 'account-settings',
|
||||
component: () => import('../pages/account-settings.vue'),
|
||||
meta: {
|
||||
requiresAuth: true
|
||||
}
|
||||
},
|
||||
{
|
||||
path: 'typography',
|
||||
component: () => import('../pages/typography.vue'),
|
||||
meta: {
|
||||
requiresAuth: true
|
||||
}
|
||||
},
|
||||
{
|
||||
path: 'icons',
|
||||
component: () => import('../pages/icons.vue'),
|
||||
meta: {
|
||||
requiresAuth: true
|
||||
}
|
||||
},
|
||||
{
|
||||
path: 'cards',
|
||||
component: () => import('../pages/cards.vue'),
|
||||
meta: {
|
||||
requiresAuth: true
|
||||
}
|
||||
},
|
||||
{
|
||||
path: 'tables',
|
||||
component: () => import('../pages/tables.vue'),
|
||||
meta: {
|
||||
requiresAuth: true
|
||||
}
|
||||
},
|
||||
{
|
||||
path: 'form-layouts',
|
||||
component: () => import('../pages/form-layouts.vue'),
|
||||
meta: {
|
||||
requiresAuth: true
|
||||
}
|
||||
},
|
||||
],
|
||||
},
|
||||
@@ -59,4 +77,23 @@ const router = createRouter({
|
||||
],
|
||||
})
|
||||
|
||||
// 导航守卫
|
||||
router.beforeEach((to, from, next) => {
|
||||
const isAuthenticated = checkLoginStatus() // 检查用户是否已登录
|
||||
if (to.meta.requiresAuth && !isAuthenticated) {
|
||||
// 如果路由需要登录权限且用户未登录,则跳转到登录页面
|
||||
next('/login')
|
||||
} else {
|
||||
// 否则,允许继续进行路由导航
|
||||
next()
|
||||
}
|
||||
})
|
||||
|
||||
// 检查用户登录状态的函数
|
||||
function checkLoginStatus() {
|
||||
// 在此处检查用户的登录状态,例如从本地存储中读取令牌或其他登录相关的信息
|
||||
const token = localStorage.getItem('token')
|
||||
return !!token // 返回一个布尔值,表示用户是否已登录
|
||||
}
|
||||
|
||||
export default router
|
||||
|
||||
Reference in New Issue
Block a user