feat(auth): 添加登录页与演示认证逻辑
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
import { createRouter, createWebHistory } from 'vue-router'
|
||||
|
||||
import { useAppStore } from '@/stores/app'
|
||||
import ClinicalLayout from '@/layouts/ClinicalLayout.vue'
|
||||
import ConsentTasksView from '@/views/consent-tasks/ConsentTasksView.vue'
|
||||
import DashboardView from '@/views/dashboard/DashboardView.vue'
|
||||
import DocumentPermissionsView from '@/views/document-permissions/DocumentPermissionsView.vue'
|
||||
import DocumentsView from '@/views/documents/DocumentsView.vue'
|
||||
import LoginView from '@/views/auth/LoginView.vue'
|
||||
import ReportsView from '@/views/reports/ReportsView.vue'
|
||||
import SettingsView from '@/views/settings/SettingsView.vue'
|
||||
import UserPermissionsView from '@/views/users/UserPermissionsView.vue'
|
||||
@@ -12,10 +14,18 @@ import UserPermissionsView from '@/views/users/UserPermissionsView.vue'
|
||||
const router = createRouter({
|
||||
history: createWebHistory(import.meta.env.BASE_URL),
|
||||
routes: [
|
||||
{
|
||||
path: '/login',
|
||||
name: 'login',
|
||||
component: LoginView,
|
||||
meta: { title: '登录' },
|
||||
},
|
||||
{
|
||||
path: '/',
|
||||
name: 'clinical',
|
||||
component: ClinicalLayout,
|
||||
redirect: '/workbench/home',
|
||||
meta: { requiresAuth: true },
|
||||
children: [
|
||||
{
|
||||
path: 'workbench',
|
||||
@@ -23,11 +33,13 @@ const router = createRouter({
|
||||
children: [
|
||||
{
|
||||
path: 'home',
|
||||
name: 'workbench-home',
|
||||
component: DashboardView,
|
||||
meta: { title: '首页', group: '工作台' },
|
||||
},
|
||||
{
|
||||
path: 'signing',
|
||||
name: 'workbench-signing',
|
||||
component: ConsentTasksView,
|
||||
meta: { title: '签署工作台', group: '工作台' },
|
||||
},
|
||||
@@ -39,26 +51,31 @@ const router = createRouter({
|
||||
children: [
|
||||
{
|
||||
path: 'documents',
|
||||
name: 'management-documents',
|
||||
component: DocumentsView,
|
||||
meta: { title: '文档库管理', group: '管理' },
|
||||
},
|
||||
{
|
||||
path: 'reports',
|
||||
name: 'management-reports',
|
||||
component: ReportsView,
|
||||
meta: { title: '报表分析', group: '管理' },
|
||||
},
|
||||
{
|
||||
path: 'users',
|
||||
name: 'management-users',
|
||||
component: UserPermissionsView,
|
||||
meta: { title: '用户与权限', group: '管理' },
|
||||
},
|
||||
{
|
||||
path: 'document-permissions',
|
||||
name: 'management-document-permissions',
|
||||
component: DocumentPermissionsView,
|
||||
meta: { title: '文档权限', group: '管理' },
|
||||
},
|
||||
{
|
||||
path: 'settings',
|
||||
name: 'management-settings',
|
||||
component: SettingsView,
|
||||
meta: { title: '系统设置', group: '管理' },
|
||||
},
|
||||
@@ -75,4 +92,21 @@ const router = createRouter({
|
||||
],
|
||||
})
|
||||
|
||||
router.beforeEach((to) => {
|
||||
const appStore = useAppStore()
|
||||
|
||||
if (to.name === 'login' && appStore.isLoggedIn) {
|
||||
return { name: 'workbench-home' }
|
||||
}
|
||||
|
||||
if (to.meta.requiresAuth && !appStore.isLoggedIn) {
|
||||
return {
|
||||
name: 'login',
|
||||
query: { redirect: to.fullPath },
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
})
|
||||
|
||||
export default router
|
||||
|
||||
Reference in New Issue
Block a user