From 3f61b5eb72a1d762c7c15f2ead2c7859c142277e Mon Sep 17 00:00:00 2001 From: chenqiang Date: Mon, 1 Sep 2025 15:44:33 +0800 Subject: [PATCH] =?UTF-8?q?=E8=80=83=E7=94=9F=E7=99=BB=E5=BD=95=E5=92=8CEx?= =?UTF-8?q?amineeHome=E9=A1=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/user/ExamineeLayout.vue | 41 +++ src/preload.js | 3 +- src/router/index.js | 98 ++++-- src/store/index.js | 16 +- src/views/WelcomeView.vue | 205 +++++++----- src/views/user/ExamineeHomeView.vue | 413 +++++++++++++++++++++++++ 6 files changed, 657 insertions(+), 119 deletions(-) create mode 100644 src/components/user/ExamineeLayout.vue create mode 100644 src/views/user/ExamineeHomeView.vue diff --git a/src/components/user/ExamineeLayout.vue b/src/components/user/ExamineeLayout.vue new file mode 100644 index 0000000..79092c0 --- /dev/null +++ b/src/components/user/ExamineeLayout.vue @@ -0,0 +1,41 @@ + + + + + \ No newline at end of file diff --git a/src/preload.js b/src/preload.js index b94ea36..fc69451 100644 --- a/src/preload.js +++ b/src/preload.js @@ -52,7 +52,8 @@ contextBridge.exposeInMainWorld('electronAPI', { questionRemove: (questionId) => ipcRenderer.invoke('question-remove', questionId), // 添加新的questionDelete方法,调用主进程中已注册的'question-delete'通道 questionDelete: (questionId) => ipcRenderer.invoke('question-delete', questionId), - questionGetStatistics: () => ipcRenderer.invoke('question-get-statistics'), + // 修改后 + questionGetStatistics: () => ipcRenderer.invoke('question-get-count-and-score'), questionGetQuestionById: (questionId) => ipcRenderer.invoke('question-get-question-by-id', questionId), // 考试服务相关接口 diff --git a/src/router/index.js b/src/router/index.js index ece2aea..321a347 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -2,11 +2,13 @@ import Vue from 'vue' import VueRouter from 'vue-router' import WelcomeView from '../views/WelcomeView.vue' import AdminLayout from '../components/admin/AdminLayout.vue' +import ExamineeLayout from '../components/user/ExamineeLayout.vue' import AdminHomeView from '../views/admin/AdminHomeView.vue' import QuestionManagementView from '../views/admin/QuestionManagementView.vue' import ExamineeManagementView from '../views/admin/ExamineeManagementView.vue' -// 添加考试管理组件导入 import ExamManagementView from '../views/admin/ExamManagementView.vue' +// 导入考生相关组件 +import ExamineeHomeView from '../views/user/ExamineeHomeView.vue' Vue.use(VueRouter) @@ -20,45 +22,81 @@ const routes = [ path: '/admin', name: 'AdminLayout', component: AdminLayout, - meta: { - requiresAuth: true - }, + meta: { requiresAuth: true }, children: [ - { - path: 'home', - name: 'AdminHome', - component: AdminHomeView - }, - { - path: 'question', - name: 'QuestionManagement', - component: QuestionManagementView - }, - { - path: 'examinee', - name: 'ExamineeManagement', - component: ExamineeManagementView - }, - { - path: 'exam', - name: 'ExamManagement', - component: ExamManagementView - } - // 可以在这里添加更多子路由 + { path: 'home', name: 'AdminHome', component: AdminHomeView }, + { path: 'question', name: 'QuestionManagement', component: QuestionManagementView }, + { path: 'examinee', name: 'ExamineeManagement', component: ExamineeManagementView }, + { path: 'exam', name: 'ExamManagement', component: ExamManagementView } + ] + }, + // 添加考生相关路由 + { + path: '/examinee', + name: 'Examinee', + component: ExamineeLayout, + meta: { requiresAuth: true }, + children: [ + { path: 'home', name: 'ExamineeHome', component: ExamineeHomeView }, + // 可以在这里添加更多考生相关的路由 ] } ] const router = new VueRouter({ - mode: 'hash', // 将history改为hash - base: process.env.BASE_URL, routes }) -// 添加路由守卫 +// 添加路由守卫,检查登录状态 router.beforeEach((to, from, next) => { - // 这里可以添加实际的认证逻辑 - next() + const store = require('../store/index.js').default + + // 检查路由是否需要认证 + if (to.matched.some(record => record.meta.requiresAuth)) { + // 检查是否已登录 + if (!store.state.isLoggedIn) { + // 如果未登录且不是去欢迎页,则重定向到欢迎页 + if (to.path !== '/') { + next({ + path: '/', + query: { redirect: to.fullPath } + }) + } else { + next() + } + } else { + next() + } + } else { + // 不需要认证的路由直接通过 + next() + } +}) + +// 添加路由守卫,检查登录状态 +router.beforeEach((to, from, next) => { + const store = require('../store/index.js').default + + // 检查路由是否需要认证 + if (to.matched.some(record => record.meta.requiresAuth)) { + // 检查是否已登录 + if (!store.state.isLoggedIn) { + // 如果未登录且不是去欢迎页,则重定向到欢迎页 + if (to.path !== '/') { + next({ + path: '/', + query: { redirect: to.fullPath } + }) + } else { + next() + } + } else { + next() + } + } else { + // 不需要认证的路由直接通过 + next() + } }) export default router diff --git a/src/store/index.js b/src/store/index.js index 793e671..ac5f09d 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -6,16 +6,28 @@ Vue.use(Vuex) export default new Vuex.Store({ state: { examinee: null, // 保存考生信息 - isLoggedIn: false // 登录状态 + admin: null, // 保存管理员信息 + isLoggedIn: false, // 通用登录状态 + userType: null // 用户类型: 'examinee' 或 'admin' }, mutations: { setExaminee(state, examineeInfo) { state.examinee = examineeInfo + state.admin = null state.isLoggedIn = true + state.userType = 'examinee' }, - clearExaminee(state) { + setAdmin(state, adminInfo) { + state.admin = adminInfo state.examinee = null + state.isLoggedIn = true + state.userType = 'admin' + }, + clearUser(state) { + state.examinee = null + state.admin = null state.isLoggedIn = false + state.userType = null } }, actions: { diff --git a/src/views/WelcomeView.vue b/src/views/WelcomeView.vue index 747745d..654deeb 100644 --- a/src/views/WelcomeView.vue +++ b/src/views/WelcomeView.vue @@ -7,14 +7,16 @@
-