mirror of
https://github.com/FatttSnake/Pinnacle-OA.git
synced 2026-04-05 23:11:24 +08:00
Added login, logout and getUserinfo (Include ui and server)
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
import { createRouter, createWebHistory } from 'vue-router'
|
||||
import { PRODUCTION_NAME } from '@/constants/Common.constants'
|
||||
import { getLoginStatus } from '@/utils/auth'
|
||||
|
||||
const router = createRouter({
|
||||
history: createWebHistory(import.meta.env.BASE_URL),
|
||||
@@ -23,8 +25,41 @@ const router = createRouter({
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
path: '/login',
|
||||
component: async () => await import('@/pages/Login.vue'),
|
||||
name: 'Login',
|
||||
meta: {
|
||||
title: '登录'
|
||||
}
|
||||
}
|
||||
]
|
||||
})
|
||||
|
||||
router.beforeEach((to, from, next) => {
|
||||
if (to.matched.length === 0) {
|
||||
from.path !== '' ? next({ path: from.path }) : next('/')
|
||||
} else {
|
||||
if (to.meta.title !== '') {
|
||||
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
||||
document.title = `${PRODUCTION_NAME} - ${to.meta.title}`
|
||||
}
|
||||
|
||||
if (getLoginStatus()) {
|
||||
if (to.name === 'Login') {
|
||||
next('/')
|
||||
} else {
|
||||
next()
|
||||
}
|
||||
} else {
|
||||
if (to.name === 'Login') {
|
||||
next()
|
||||
} else {
|
||||
next('/login')
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
export default router
|
||||
|
||||
Reference in New Issue
Block a user