From d729451133821896fa192da55839f4c48b972893 Mon Sep 17 00:00:00 2001 From: xiao12feng Date: Thu, 20 Nov 2025 15:22:40 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=94=A8=E6=88=B7=E7=95=8C?= =?UTF-8?q?=E9=9D=A2=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- xinli-ui/src/permission.js | 32 +++++---- xinli-ui/src/store/getters.js | 3 +- xinli-ui/src/store/modules/user.js | 14 +++- xinli-ui/src/utils/auth.js | 16 +++++ xinli-ui/src/views/login.vue | 6 +- .../views/psychology/assessment/taking.vue | 35 ++++++++-- .../src/views/psychology/profile/index.vue | 70 +++++++------------ .../views/psychology/questionnaire/start.vue | 10 ++- .../views/psychology/questionnaire/taking.vue | 25 +++++-- xinli-ui/src/views/student/tests.vue | 9 +-- 10 files changed, 137 insertions(+), 83 deletions(-) diff --git a/xinli-ui/src/permission.js b/xinli-ui/src/permission.js index 769231b7..40e10bf3 100644 --- a/xinli-ui/src/permission.js +++ b/xinli-ui/src/permission.js @@ -21,8 +21,10 @@ router.beforeEach((to, from, next) => { to.meta.title && store.dispatch('settings/setTitle', to.meta.title) /* has token*/ if (to.path === '/login' || to.path === '/admin-login') { - // 已登录,统一跳回首页 - next({ path: '/' }) + // 已登录,根据角色跳转到相应页面 + const userRoles = store.getters.roles || [] + const isStudentRole = userRoles.some(role => role === 'student' || role.includes('学员')) + next({ path: isStudentRole ? '/student/tests' : '/' }) NProgress.done() } else if (isWhiteList(to.path)) { next() @@ -39,21 +41,22 @@ router.beforeEach((to, from, next) => { const isStudentRole = userRoles.some(role => role === 'student' || role.includes('学员')) if (isStudentRole) { - const allowPaths = [ - '/', - '/index' - ] + // 学员访问首页时重定向到测试题列表 + if (to.path === '/' || to.path === '/index') { + next({ path: '/student/tests', replace: true }) + return + } const allowPrefixes = [ '/student', '/psychology/assessment/taking', '/psychology/questionnaire', '/psychology/assessment/report' ] - const isAllowed = allowPaths.includes(to.path) || allowPrefixes.some(prefix => to.path.startsWith(prefix)) + const isAllowed = allowPrefixes.some(prefix => to.path.startsWith(prefix)) if (isAllowed) { next() } else { - next({ path: '/' }) + next({ path: '/student/tests' }) } } else { // 管理员角色,生成路由 @@ -77,21 +80,22 @@ router.beforeEach((to, from, next) => { const isStudentRole = userRoles.some(role => role === 'student' || role.includes('学员')) if (isStudentRole) { - const allowPaths = [ - '/', - '/index' - ] + // 学员访问首页时重定向到测试题列表 + if (to.path === '/' || to.path === '/index') { + next({ path: '/student/tests', replace: true }) + return + } const allowPrefixes = [ '/student', '/psychology/assessment/taking', '/psychology/questionnaire', '/psychology/assessment/report' ] - const isAllowed = allowPaths.includes(to.path) || allowPrefixes.some(prefix => to.path.startsWith(prefix)) + const isAllowed = allowPrefixes.some(prefix => to.path.startsWith(prefix)) if (isAllowed) { next() } else { - next({ path: '/' }) + next({ path: '/student/tests' }) } } else { next() diff --git a/xinli-ui/src/store/getters.js b/xinli-ui/src/store/getters.js index 3680f956..640534fe 100644 --- a/xinli-ui/src/store/getters.js +++ b/xinli-ui/src/store/getters.js @@ -16,6 +16,7 @@ const getters = { permission_routes: state => state.permission.routes, topbarRouters: state => state.permission.topbarRouters, defaultRoutes: state => state.permission.defaultRoutes, - sidebarRouters: state => state.permission.sidebarRouters + sidebarRouters: state => state.permission.sidebarRouters, + infoNumber: state => state.user.infoNumber } export default getters diff --git a/xinli-ui/src/store/modules/user.js b/xinli-ui/src/store/modules/user.js index 292e39c8..b97322b0 100644 --- a/xinli-ui/src/store/modules/user.js +++ b/xinli-ui/src/store/modules/user.js @@ -1,7 +1,7 @@ import router from '@/router' import { MessageBox, } from 'element-ui' import { login, logout, getInfo, studentLogin } from '@/api/login' -import { getToken, setToken, removeToken, getRole, setRole } from '@/utils/auth' +import { getToken, setToken, removeToken, getRole, setRole, getInfoNumber, setInfoNumber } from '@/utils/auth' import { isHttp, isEmpty } from "@/utils/validate" import defAva from '@/assets/images/profile.jpg' @@ -22,7 +22,8 @@ const user = { nickName: '', avatar: '', roles: initRoles(), - permissions: [] + permissions: [], + infoNumber: getInfoNumber() || '' // 学员信息编号,从 Cookie 中恢复 }, mutations: { @@ -58,6 +59,11 @@ const user = { }, SET_PERMISSIONS: (state, permissions) => { state.permissions = permissions + }, + SET_INFO_NUMBER: (state, infoNumber) => { + state.infoNumber = infoNumber + // 持久化到 Cookie + setInfoNumber(infoNumber) } }, @@ -132,6 +138,7 @@ const user = { commit('SET_TOKEN', '') commit('SET_ROLES', []) commit('SET_PERMISSIONS', []) + commit('SET_INFO_NUMBER', '') removeToken() resolve() }).catch(error => { @@ -145,6 +152,7 @@ const user = { return new Promise(resolve => { commit('SET_TOKEN', '') commit('SET_ROLES', []) + commit('SET_INFO_NUMBER', '') removeToken() resolve() }) @@ -165,6 +173,8 @@ const user = { // 设置学员token setToken(res.token) commit('SET_TOKEN', res.token) + // 保存信息编号到 store + commit('SET_INFO_NUMBER', infoNumber) // 学员登录成功后,需要调用GetInfo获取用户信息(因为学员也是系统用户,只是角色不同) // 这里不设置角色,等GetInfo获取后再设置 resolve() diff --git a/xinli-ui/src/utils/auth.js b/xinli-ui/src/utils/auth.js index 0d959d86..774f4498 100644 --- a/xinli-ui/src/utils/auth.js +++ b/xinli-ui/src/utils/auth.js @@ -2,6 +2,7 @@ import Cookies from 'js-cookie' const TokenKey = 'Admin-Token' const RoleKey = 'User-Role' +const InfoNumberKey = 'Info-Number' export function getToken() { return Cookies.get(TokenKey) @@ -14,6 +15,7 @@ export function setToken(token) { export function removeToken() { Cookies.remove(TokenKey) Cookies.remove(RoleKey) + Cookies.remove(InfoNumberKey) } // 获取用户角色 @@ -29,3 +31,17 @@ export function setRole(role) { return Cookies.remove(RoleKey) } } + +// 获取信息编号 +export function getInfoNumber() { + return Cookies.get(InfoNumberKey) +} + +// 设置信息编号 +export function setInfoNumber(infoNumber) { + if (infoNumber) { + return Cookies.set(InfoNumberKey, infoNumber) + } else { + return Cookies.remove(InfoNumberKey) + } +} diff --git a/xinli-ui/src/views/login.vue b/xinli-ui/src/views/login.vue index 9a890890..d9b0a832 100644 --- a/xinli-ui/src/views/login.vue +++ b/xinli-ui/src/views/login.vue @@ -74,9 +74,6 @@ 登 录 登 录 中... -
- 立即注册 -
- - - 搜索 - 重置 @@ -72,16 +63,6 @@ v-hasPermi="['psychology:profile:add']" >新增档案 - - 创建用户 - -