提交代码修改
This commit is contained in:
1 parent
760fd8d07a
commit
5231d97cc1
4 files changed
+122
-5
No files matched your search
@@ -0,0 +1,107 @@
|
||||
# 学历层次显示问题修复记录
|
||||
|
||||
## 变更信息
|
||||
- **日期**: 2025-01-14
|
||||
- **操作者**: Cursor AI
|
||||
- **变更类型**: Bug修复
|
||||
- **影响模块**: 学工管理 - 学生信息管理
|
||||
- **变更文件**:
|
||||
- `web/src/views/studentMsg/studentMsg/index.vue`
|
||||
- `web/src/api/studentMsg/types.ts`
|
||||
- `web/src/api/studentMsg/studentMsg/types.ts`
|
||||
|
||||
## 问题描述
|
||||
|
||||
### 问题现象
|
||||
- 学生信息修改界面中,学历层次字段显示为数字 `2`,而不是对应的文本标签 `高级工`
|
||||
- 用户期望看到的是 `高级工` 而不是 `2`
|
||||
|
||||
### 问题根本原因
|
||||
**数据类型不匹配导致显示异常**
|
||||
|
||||
1. **后端返回数据类型**: 后端返回的 `academicLevel` 是数字类型(如 `2`)
|
||||
2. **前端类型定义**: 前端类型定义中 `academicLevel` 被定义为 `string` 类型
|
||||
3. **表单初始化**: 表单初始化时 `academicLevel` 被设置为空字符串 `''`
|
||||
4. **数据类型冲突**: 数字类型的后端数据与字符串类型的前端期望不匹配
|
||||
|
||||
### 影响范围
|
||||
- 学生信息修改页面
|
||||
- 学历层次字段显示异常
|
||||
- 可能影响其他使用 `academicLevel` 字段的页面
|
||||
|
||||
## 解决方案
|
||||
|
||||
### 修复内容
|
||||
|
||||
#### 1. 修改前端类型定义
|
||||
**文件**: `web/src/api/studentMsg/types.ts`
|
||||
```typescript
|
||||
// 修改前
|
||||
academic_level?: string;
|
||||
|
||||
// 修改后
|
||||
academic_level?: string | number;
|
||||
```
|
||||
|
||||
**文件**: `web/src/api/studentMsg/studentMsg/types.ts`
|
||||
```typescript
|
||||
// 修改前
|
||||
academicLevel: string;
|
||||
academicLevel?: string;
|
||||
|
||||
// 修改后
|
||||
academicLevel: string | number;
|
||||
academicLevel?: string | number;
|
||||
```
|
||||
|
||||
#### 2. 修改表单初始化
|
||||
**文件**: `web/src/views/studentMsg/studentMsg/index.vue`
|
||||
```typescript
|
||||
// 修改前
|
||||
academicLevel: '',
|
||||
|
||||
// 修改后
|
||||
academicLevel: undefined,
|
||||
```
|
||||
|
||||
### 修复原理
|
||||
1. **类型兼容性**: 将 `academicLevel` 字段类型从 `string` 改为 `string | number`,支持数字类型
|
||||
2. **初始化优化**: 将初始值从空字符串改为 `undefined`,避免类型冲突
|
||||
3. **显示逻辑**: 保持现有的 `getAcademicLevelLabel` 函数不变,它能正确处理数字类型
|
||||
|
||||
### 现有显示逻辑
|
||||
```typescript
|
||||
/** 学历层级码表映射 */
|
||||
const getAcademicLevelLabel = (value: string | number) => {
|
||||
const academicLevelMap: Record<string, string> = {
|
||||
'1': '中级工',
|
||||
'2': '高级工',
|
||||
'3': '预备技师',
|
||||
'4': '技师',
|
||||
'5': '中高职一体'
|
||||
};
|
||||
return academicLevelMap[String(value)] || value || '未知';
|
||||
};
|
||||
```
|
||||
|
||||
## 验证方法
|
||||
|
||||
### 测试步骤
|
||||
1. 进入学生信息管理页面
|
||||
2. 点击修改按钮,打开学生信息修改对话框
|
||||
3. 检查学历层次字段是否正确显示文本标签(如 `高级工`)而不是数字(如 `2`)
|
||||
|
||||
### 预期结果
|
||||
- 学历层次字段显示正确的文本标签
|
||||
- 修改和保存功能正常工作
|
||||
- 其他相关页面不受影响
|
||||
|
||||
## 相关文档
|
||||
- 学生信息管理API文档
|
||||
- 前端开发规范
|
||||
- 数据类型定义规范
|
||||
|
||||
## 备注
|
||||
- 此修复确保了前后端数据类型的一致性
|
||||
- 保持了现有业务逻辑的完整性
|
||||
- 为后续类似字段的处理提供了参考模板
|
||||
@@ -417,7 +417,7 @@ export interface StudentMsgVO {
|
||||
/**
|
||||
* 学历层次 - 预留,数据从班级表关联
|
||||
*/
|
||||
academicLevel: string;
|
||||
academicLevel: string | number;
|
||||
|
||||
/**
|
||||
* 培养方式:全日制、在职、函授、夜大等 - 预留,数据从班级表关联
|
||||
@@ -1459,7 +1459,7 @@ export interface StudentMsgQuery extends PageQuery {
|
||||
/**
|
||||
* 学历层次 - 预留,数据从班级表关联
|
||||
*/
|
||||
academicLevel?: string;
|
||||
academicLevel?: string | number;
|
||||
|
||||
/**
|
||||
* 培养方式:全日制、在职、函授、夜大等 - 预留,数据从班级表关联
|
||||
|
||||
@@ -146,7 +146,7 @@ export interface StudentForm {
|
||||
enrollment_year?: string;
|
||||
enrollment_date?: string;
|
||||
school_system?: string;
|
||||
academic_level?: string;
|
||||
academic_level?: string | number;
|
||||
training_type?: string;
|
||||
major_name?: string;
|
||||
class_name?: string;
|
||||
|
||||
@@ -1732,7 +1732,7 @@ const initFormData: StudentMsgForm = {
|
||||
enrollmentYear: undefined,
|
||||
enrollmentDate: '',
|
||||
schoolSystem: undefined,
|
||||
academicLevel: '',
|
||||
academicLevel: undefined as number | undefined,
|
||||
trainingType: '全日制',
|
||||
majorId: '',
|
||||
majorName: '',
|
||||
@@ -2094,6 +2094,10 @@ const handleDetail = async (row: StudentVO) => {
|
||||
const res = await service.get(`/studentMsg/studentMsg/${studentId}`);
|
||||
if (res && res.code === 200) {
|
||||
Object.assign(detailForm, res.data);
|
||||
// 确保学历层次为数字类型,避免类型不匹配导致的显示问题
|
||||
if (detailForm.academicLevel !== undefined && detailForm.academicLevel !== null) {
|
||||
detailForm.academicLevel = Number(detailForm.academicLevel);
|
||||
}
|
||||
detailDialog.visible = true;
|
||||
activeDetailTab.value = 'basic'; // 重置到第一个tab页
|
||||
} else {
|
||||
@@ -2263,7 +2267,9 @@ const handleAdd = async () => {
|
||||
form.collegeName = classData.college_name || classData.collegeName;
|
||||
form.majorId = classData.major_id || classData.majorId;
|
||||
form.majorName = classData.major_name || classData.majorName;
|
||||
form.academicLevel = Number(classData.class_type || classData.classType);
|
||||
// 确保学历层次为数字类型,避免类型不匹配导致的显示问题
|
||||
const classType = classData.class_type || classData.classType;
|
||||
form.academicLevel = classType ? Number(classType) : undefined;
|
||||
form.grade = classData.grade;
|
||||
form.enrollmentYear = classData.enrollment_year || classData.enrollmentYear;
|
||||
form.classTeacherId = classData.class_teacher_id || classData.classTeacherId;
|
||||
@@ -2292,6 +2298,10 @@ const handleUpdate = async (row?: StudentForm) => {
|
||||
dialog.visible = true;
|
||||
dialog.title = '修改学生';
|
||||
Object.assign(form, res.data);
|
||||
// 确保学历层次为数字类型,避免类型不匹配导致的显示问题
|
||||
if (form.academicLevel !== undefined && form.academicLevel !== null) {
|
||||
form.academicLevel = Number(form.academicLevel);
|
||||
}
|
||||
// 注意:如果需要专业和班级选项,可能需要额外的接口调用
|
||||
// majorOptions.value = data.data.majors;
|
||||
// classOptions.value = data.data.classes;
|
||||
|
||||
Reference in new issue
Block a user