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 @@ 登 录 登 录 中... -
- 立即注册 -
@@ -250,7 +247,8 @@ export default { this.$store.dispatch("StudentLogin", loginData).then(() => { // 学员登录成功后,需要调用GetInfo获取用户信息 this.$store.dispatch("GetInfo").then(() => { - const targetPath = this.resolveRedirect("/") + // 学员登录后跳转到测试题页面,如果有redirect参数则跳转到指定页面 + const targetPath = this.resolveRedirect("/student/tests") this.$router.push(targetPath).catch(()=>{}) }).catch(() => { this.loading = false diff --git a/xinli-ui/src/views/psychology/assessment/taking.vue b/xinli-ui/src/views/psychology/assessment/taking.vue index c19c0e00..10240e96 100644 --- a/xinli-ui/src/views/psychology/assessment/taking.vue +++ b/xinli-ui/src/views/psychology/assessment/taking.vue @@ -145,7 +145,10 @@ export default { this.assessmentId = this.$route.query.assessmentId; if (!this.assessmentId) { this.$modal.msgError("测评ID不能为空"); - this.$router.push('/psychology/assessment'); + // 根据用户角色跳转到相应页面 + const roles = this.$store.getters.roles || []; + const isStudent = roles.some(role => role === 'student' || role.includes('学员')); + this.$router.push(isStudent ? '/student/tests' : '/psychology/assessment'); return; } this.loadAssessment(); @@ -162,7 +165,10 @@ export default { const assessment = assessmentRes.data; if (!assessment) { this.$modal.msgError("测评不存在"); - this.$router.push('/psychology/assessment'); + // 根据用户角色跳转到相应页面 + const roles = this.$store.getters.roles || []; + const isStudent = roles.some(role => role === 'student' || role.includes('学员')); + this.$router.push(isStudent ? '/student/tests' : '/psychology/assessment'); return; } @@ -172,7 +178,10 @@ export default { // 检查题目列表是否为空 if (this.itemList.length === 0) { this.$modal.msgWarning("该量表暂无题目,请联系管理员添加题目"); - this.$router.push('/psychology/assessment'); + // 根据用户角色跳转到相应页面 + const roles = this.$store.getters.roles || []; + const isStudent = roles.some(role => role === 'student' || role.includes('学员')); + this.$router.push(isStudent ? '/student/tests' : '/psychology/assessment'); return; } @@ -309,14 +318,20 @@ export default { this.$modal.confirm('确定要暂停测评吗?您可以稍后继续完成。').then(() => { pauseAssessment(this.assessmentId).then(() => { this.$modal.msgSuccess("测评已暂停"); - this.$router.push('/psychology/assessment'); + // 根据用户角色跳转到相应页面 + const roles = this.$store.getters.roles || []; + const isStudent = roles.some(role => role === 'student' || role.includes('学员')); + this.$router.push(isStudent ? '/student/tests' : '/psychology/assessment'); }); }); }, /** 退出 */ handleExit() { this.$modal.confirm('确定要退出测评吗?已答题目将会保存。').then(() => { - this.$router.push('/psychology/assessment'); + // 根据用户角色跳转到相应页面 + const roles = this.$store.getters.roles || []; + const isStudent = roles.some(role => role === 'student' || role.includes('学员')); + this.$router.push(isStudent ? '/student/tests' : '/psychology/assessment'); }); }, /** 提交测评 */ @@ -331,7 +346,10 @@ export default { this.$modal.confirm('确定要提交测评吗?提交后将不能修改。').then(() => { submitAssessment(this.assessmentId).then(response => { this.$modal.msgSuccess(response.msg || "测评已提交,报告已生成"); - this.$router.push('/psychology/assessment'); + // 根据用户角色跳转到相应页面 + const roles = this.$store.getters.roles || []; + const isStudent = roles.some(role => role === 'student' || role.includes('学员')); + this.$router.push(isStudent ? '/student/tests' : '/psychology/assessment'); }).catch(error => { this.$modal.msgError(error.msg || "提交失败,请重试"); }); @@ -461,7 +479,10 @@ export default { submitAssessment(this.assessmentId).then(response => { this.loading = false; this.$modal.msgSuccess(response.msg || "测评已提交,报告已生成"); - this.$router.push('/psychology/assessment'); + // 根据用户角色跳转到相应页面 + const roles = this.$store.getters.roles || []; + const isStudent = roles.some(role => role === 'student' || role.includes('学员')); + this.$router.push(isStudent ? '/student/tests' : '/psychology/assessment'); }).catch(error => { this.loading = false; this.$modal.msgError(error.msg || "提交失败,请重试"); diff --git a/xinli-ui/src/views/psychology/profile/index.vue b/xinli-ui/src/views/psychology/profile/index.vue index 82f8f860..d49eb46a 100644 --- a/xinli-ui/src/views/psychology/profile/index.vue +++ b/xinli-ui/src/views/psychology/profile/index.vue @@ -39,14 +39,6 @@ - - - 搜索 - 重置 @@ -72,16 +63,6 @@ v-hasPermi="['psychology:profile:add']" >新增档案 - - 创建用户 - -