修复用户界面问题

This commit is contained in:
xiao12feng 2025-11-20 15:22:40 +08:00
parent d2e29d9537
commit d729451133
10 changed files with 137 additions and 83 deletions

View File

@ -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()

View File

@ -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

View File

@ -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()

View File

@ -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)
}
}

View File

@ -74,9 +74,6 @@
<span v-if="!loading"> </span>
<span v-else> 中...</span>
</el-button>
<div style="float: right;" v-if="register">
<router-link class="link-type" :to="'/register'">立即注册</router-link>
</div>
</el-form-item>
<el-form-item style="width:100%; text-align: center; margin-top: 10px;">
<a class="student-login-link" @click="switchToStudent">
@ -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

View File

@ -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 || "提交失败,请重试");

View File

@ -39,14 +39,6 @@
<el-option label="老年" value="senior" />
</el-select>
</el-form-item>
<el-form-item label="身份证号" prop="idCard">
<el-input
v-model="queryParams.idCard"
placeholder="请输入身份证号"
clearable
@keyup.enter.native="handleQuery"
/>
</el-form-item>
<el-form-item label="信息编号" prop="infoNumber">
<el-input
v-model="queryParams.infoNumber"
@ -57,7 +49,6 @@
</el-form-item>
<el-form-item>
<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
</el-form-item>
</el-form>
@ -72,16 +63,6 @@
v-hasPermi="['psychology:profile:add']"
>新增档案</el-button>
</el-col>
<el-col :span="1.8">
<el-button
type="primary"
plain
icon="el-icon-user"
size="mini"
@click="handleAddUser"
v-hasPermi="['psychology:profile:add']"
>创建用户</el-button>
</el-col>
<el-col :span="1.5">
<el-button
type="success"
@ -123,7 +104,6 @@
</el-table-column>
<el-table-column label="姓名" align="center" prop="userName" width="100" />
<el-table-column label="电话" align="center" prop="phone" width="120" />
<el-table-column label="身份证号" align="center" prop="idCard" width="180" />
<el-table-column label="生日" align="center" prop="birthday" width="120">
<template slot-scope="scope">
<span>{{ parseTime(scope.row.birthday, '{y}-{m}-{d}') }}</span>
@ -147,13 +127,6 @@
@click="handleUpdate(scope.row)"
v-hasPermi="['psychology:profile:edit']"
>档案</el-button>
<el-button
size="mini"
type="text"
icon="el-icon-user"
@click="handleEditUser(scope.row)"
v-hasPermi="['psychology:profile:edit']"
>用户</el-button>
<el-button
size="mini"
type="text"
@ -177,21 +150,6 @@
<el-dialog :title="title" :visible.sync="open" width="900px" append-to-body>
<el-form ref="form" :model="form" :rules="rules" label-width="120px">
<el-row>
<el-col :span="12">
<el-form-item prop="userId">
<template slot="label">
用户ID
<span style="color:#909399;font-size:12px;">留空自动创建</span>
</template>
<el-input-number
v-model="form.userId"
:min="1"
:disabled="form.profileId != undefined"
:controls="false"
placeholder="不填将自动创建用户"
/>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="档案类型" prop="profileType">
<el-select v-model="form.profileType" placeholder="请选择档案类型">
@ -202,6 +160,9 @@
</el-select>
</el-form-item>
</el-col>
<el-col :span="12">
<!-- 用户ID已隐藏会通过信息编号自动填充 -->
</el-col>
</el-row>
<el-row>
<el-col :span="12">
@ -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
}
},
// userIdinfoNumber
syncUserIdWithInfoNumber() {
if (this.form.infoNumber) {
// userId
this.form.userId = parseInt(this.form.infoNumber)
} else if (this.form.userId) {
// userIduserId
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 {

View File

@ -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');
}
}
};

View File

@ -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 || "提交失败,请重试");

View File

@ -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()
},