1
0
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:
2023-05-05 20:59:09 +08:00
parent a8dce8f8e0
commit 60b8460e03
32 changed files with 1022 additions and 151 deletions

View File

@@ -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