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']"
>新增档案
-
- 创建用户
-
-
{{ parseTime(scope.row.birthday, '{y}-{m}-{d}') }}
@@ -147,13 +127,6 @@
@click="handleUpdate(scope.row)"
v-hasPermi="['psychology:profile:edit']"
>档案
- 用户
-
-
-
- 用户ID
- (留空自动创建)
-
-
-
-
@@ -202,6 +160,9 @@
+
+
+
@@ -542,10 +503,27 @@ export default {
}
this.resetForm("form")
},
- // 处理信息编号输入,只允许数字
+ // 处理信息编号输入,只允许数字,并同时更新userId
handleInfoNumberInput(value) {
// 移除所有非数字字符
- this.form.infoNumber = value.replace(/\D/g, '')
+ const numericValue = value.replace(/\D/g, '')
+ this.form.infoNumber = numericValue
+ // 将信息编号同时赋值给userId,确保两者保持一致
+ if (numericValue) {
+ this.form.userId = parseInt(numericValue)
+ } else {
+ this.form.userId = undefined
+ }
+ },
+ // 同步userId和infoNumber,确保两者保持一致
+ syncUserIdWithInfoNumber() {
+ if (this.form.infoNumber) {
+ // 如果有信息编号,将其同步到userId
+ this.form.userId = parseInt(this.form.infoNumber)
+ } else if (this.form.userId) {
+ // 如果没有信息编号但有userId,将userId同步到信息编号
+ this.form.infoNumber = this.form.userId.toString()
+ }
},
// 处理姓名输入,只允许汉字
handleUserNameInput(value) {
@@ -712,6 +690,8 @@ export default {
getProfile(row.profileId).then(response => {
if (response.data) {
this.form = response.data
+ // 确保 userId 和 infoNumber 保持一致
+ this.syncUserIdWithInfoNumber()
this.open = true
this.title = "修改用户档案"
} else {
@@ -734,6 +714,8 @@ export default {
if (response.data && response.data.profileId) {
// 找到了档案,修改档案
this.form = response.data
+ // 确保 userId 和 infoNumber 保持一致
+ this.syncUserIdWithInfoNumber()
this.open = true
this.title = "修改用户档案"
} else {
diff --git a/xinli-ui/src/views/psychology/questionnaire/start.vue b/xinli-ui/src/views/psychology/questionnaire/start.vue
index afe94c23..968315ae 100644
--- a/xinli-ui/src/views/psychology/questionnaire/start.vue
+++ b/xinli-ui/src/views/psychology/questionnaire/start.vue
@@ -106,7 +106,10 @@ export default {
startAnswerDirectly() {
if (!this.form.questionnaireId) {
this.$modal.msgError("问卷ID不能为空");
- this.$router.push('/psychology/scale');
+ // 根据用户角色跳转到相应页面
+ const roles = this.$store.getters.roles || [];
+ const isStudent = roles.some(role => role === 'student' || role.includes('学员'));
+ this.$router.push(isStudent ? '/student/tests' : '/psychology/scale');
return;
}
@@ -131,7 +134,10 @@ export default {
},
/** 返回 */
handleBack() {
- this.$router.push('/psychology/scale');
+ // 根据用户角色跳转到相应页面
+ const roles = this.$store.getters.roles || [];
+ const isStudent = roles.some(role => role === 'student' || role.includes('学员'));
+ this.$router.push(isStudent ? '/student/tests' : '/psychology/scale');
}
}
};
diff --git a/xinli-ui/src/views/psychology/questionnaire/taking.vue b/xinli-ui/src/views/psychology/questionnaire/taking.vue
index 363648bb..94f4d717 100644
--- a/xinli-ui/src/views/psychology/questionnaire/taking.vue
+++ b/xinli-ui/src/views/psychology/questionnaire/taking.vue
@@ -216,7 +216,10 @@ export default {
this.answerId = this.$route.query.answerId;
if (!this.answerId) {
this.$modal.msgError("答题ID不能为空");
- this.$router.push('/psychology/scale');
+ // 根据用户角色跳转到相应页面
+ const roles = this.$store.getters.roles || [];
+ const isStudent = roles.some(role => role === 'student' || role.includes('学员'));
+ this.$router.push(isStudent ? '/student/tests' : '/psychology/scale');
return;
}
this.loadAnswer();
@@ -232,7 +235,10 @@ export default {
const answer = answerRes.data;
if (!answer) {
this.$modal.msgError("答题记录不存在");
- this.$router.push('/psychology/scale');
+ // 根据用户角色跳转到相应页面
+ const roles = this.$store.getters.roles || [];
+ const isStudent = roles.some(role => role === 'student' || role.includes('学员'));
+ this.$router.push(isStudent ? '/student/tests' : '/psychology/scale');
return;
}
@@ -256,7 +262,10 @@ export default {
if (this.itemList.length === 0) {
this.$modal.msgWarning("该问卷暂无题目,请联系管理员添加题目");
- this.$router.push('/psychology/scale');
+ // 根据用户角色跳转到相应页面
+ const roles = this.$store.getters.roles || [];
+ const isStudent = roles.some(role => role === 'student' || role.includes('学员'));
+ this.$router.push(isStudent ? '/student/tests' : '/psychology/scale');
return;
}
@@ -449,7 +458,10 @@ export default {
/** 退出 */
handleExit() {
this.$modal.confirm('确定要退出答题吗?已答题目将会保存。').then(() => {
- this.$router.push('/psychology/scale');
+ // 根据用户角色跳转到相应页面
+ const roles = this.$store.getters.roles || [];
+ const isStudent = roles.some(role => role === 'student' || role.includes('学员'));
+ this.$router.push(isStudent ? '/student/tests' : '/psychology/scale');
});
},
/** 提交问卷 */
@@ -480,7 +492,10 @@ export default {
submitQuestionnaireAnswer(this.answerId).then(response => {
this.loading = false;
this.$modal.msgSuccess(response.msg || "问卷已提交");
- this.$router.push('/psychology/scale');
+ // 根据用户角色跳转到相应页面
+ const roles = this.$store.getters.roles || [];
+ const isStudent = roles.some(role => role === 'student' || role.includes('学员'));
+ this.$router.push(isStudent ? '/student/tests' : '/psychology/scale');
}).catch(error => {
this.loading = false;
this.$modal.msgError(error.msg || "提交失败,请重试");
diff --git a/xinli-ui/src/views/student/tests.vue b/xinli-ui/src/views/student/tests.vue
index 36960d75..aaa7c45e 100644
--- a/xinli-ui/src/views/student/tests.vue
+++ b/xinli-ui/src/views/student/tests.vue
@@ -72,11 +72,14 @@ export default {
return {
loading: false,
testList: [],
- searchText: "",
- studentNo: ""
+ searchText: ""
}
},
computed: {
+ // 学员编号 - 从 store 实时获取,优先使用 infoNumber
+ studentNo() {
+ return this.$store.getters.infoNumber || this.$store.getters.name || "未知"
+ },
// 过滤后的测试题列表
filteredTestList() {
if (!this.searchText) {
@@ -89,8 +92,6 @@ export default {
}
},
created() {
- // 获取学员编号
- this.studentNo = this.$store.getters.name || "未知"
// 加载测试题列表
this.loadTestList()
},