变更日期: 2025-01-14 15:30:00
处理人员: cursor
变更类型: 前端功能修复 + UI优化
问题描述:
根本原因分析:
status是字符串类型("0", "1"),但切换逻辑使用数字比较(=== 1)schedule_status字典未正确配置,导致显示异常修复方案:
文件: web/src/views/xljk/consultation/schedule/index.vue
修改前:
const handleUpdate = async (row?: XljkConsultationScheduleVO) => {
if (row && row.id) {
try {
await updateXljkSchedule({
id: row.id,
status: row.status === 1 ? 0 : 1 // 错误:字符串与数字比较
} as XljkConsultationScheduleForm);
ElMessage.success('状态更新成功');
getList();
} catch (error) {
console.error('更新时段状态失败', error);
ElMessage.error('状态更新失败');
}
}
};
修改后:
const handleUpdate = async (row?: XljkConsultationScheduleVO) => {
if (row && row.id) {
try {
// 修复:将字符串状态正确转换为数字进行比较
const currentStatus = parseInt(row.status as string);
const newStatus = currentStatus === 1 ? 0 : 1;
console.log(`状态切换调试 - 当前状态: ${row.status} (${typeof row.status}), 转换后: ${currentStatus}, 新状态: ${newStatus}`);
await updateXljkSchedule({
id: row.id,
status: newStatus.toString()
} as XljkConsultationScheduleForm);
ElMessage.success(`状态已${newStatus === 0 ? '启用' : '停用'}`);
getList();
} catch (error) {
console.error('更新时段状态失败', error);
ElMessage.error('状态更新失败');
}
}
};
修复要点:
parseInt() 将字符串状态转换为数字进行比较文件: backend/script/sql/xljk-dict-data.sql
新增内容:
-- 预约时段状态字典
INSERT INTO sys_dict_type VALUES (102, '000000', '预约时段状态', 'schedule_status', 103, 1, sysdate(), NULL, NULL, '预约时段状态列表');
-- 预约时段状态字典数据
INSERT INTO sys_dict_data VALUES (300, '000000', 1, '正常', '0', 'schedule_status', '', 'success', 'Y', 103, 1, sysdate(), NULL, NULL, '正常状态');
INSERT INTO sys_dict_data VALUES (301, '000000', 2, '停用', '1', 'schedule_status', '', 'danger', 'N', 103, 1, sysdate(), NULL, NULL, '停用状态');
配置要点:
schedule_status 字典类型0-正常(success样式)、1-停用(danger样式)调整目标: 缩小上午时段、下午时段、创建时间3个列的列宽,优化页面布局
列宽调整对比:
| 字段名称 | 调整前 | 调整后 | 变化 |
|---|---|---|---|
| 上午时段 | min-width="150" |
min-width="120" |
-30px |
| 下午时段 | min-width="150" |
min-width="120" |
-30px |
| 创建时间 | width="150" |
width="120" |
-30px |
修改位置: web/src/views/xljk/consultation/schedule/index.vue (第84-102行)
修改内容:
<!-- 上午时段列 -->
<el-table-column label="上午时段" align="center" min-width="120">
<!-- 下午时段列 -->
<el-table-column label="下午时段" align="center" min-width="120">
<!-- 创建时间列 -->
<el-table-column label="创建时间" align="center" prop="createTime" width="120">
优化效果:
min-width)表格布局更新:
调整目标: 移除预约限制管理(未到访记录)列表界面的创建时间字段显示
页面位置: web/src/views/xljk/consultation/noshow/index.vue
移除字段:
<!-- 已移除的创建时间列 -->
<el-table-column label="创建时间" align="center" prop="createTime" width="150">
<template #default="scope">
<span>{{ parseTime(scope.row.createTime) }}</span>
</template>
</el-table-column>
修改位置: 第92-96行
优化效果:
当前保留字段:
表格布局优化:
// 修复代码
parseInt("1") === 1 // true (转换后比较)
2. **数据流类型不一致**:
后端返回 → status: "0" (字符串) 前端比较 → status === 1 (数字) 结果 → 永远返回false,总是执行 : 1 分支
3. **字典配置缺失**:
```vue
<dict-tag :options="schedule_status" :value="scope.row.status" />
当 schedule_status 字典为空时,dict-tag 组件无法正确渲染,可能显示原始值或双重标签。
验证步骤:
预期结果:
直接影响:
间接影响:
| 文件路径 | 变更类型 | 说明 |
|---|---|---|
web/src/views/xljk/consultation/schedule/index.vue |
修改 | 修复状态切换逻辑 + 优化列宽布局 |
web/src/views/xljk/consultation/noshow/index.vue |
修改 | 移除创建时间字段显示 |
backend/script/sql/xljk-dict-data.sql |
新增 | 创建心理健康模块字典数据配置 |
docs/变更管理/code-adjust-record-2025-01-14-cursor.md |
新增 | 本变更记录文档 |
验证完成: ✅ 功能测试通过
文档更新: ✅ 已同步更新
代码审查: ✅ 自检完成