refactor(ui): 优化按钮样式和数据加载逻辑

- 将多个按钮组件从 type="text" 改为 link 属性,提升界面美观性
- 修复 PatientList 组件中姓名显示的文本截断功能
- 在住院记录模板中添加对 patientInfo 变化的监听,自动更新表单数据
- 优化打印机列表获取逻辑,添加连接状态检查和警告信息
- 移除不必要的防抖和重复请求防护逻辑,简化代码实现
- 修复多处组件中对 patientInfo 属性访问的安全性问题
- 优化病历数据加载时机,移除防抖包装直接调用加载函数
- 改进数据设置逻辑,避免覆盖未传入字段的原有值
- 调整组件属性定义,使 patientInfo 参数变为可选并设置默认值
- 优化患者切换时的组件重置和数据加载流程
This commit is contained in:
2026-01-27 17:32:03 +08:00
parent 0f0dc70c7e
commit 4f0cc1a0c4
21 changed files with 232 additions and 387 deletions

View File

@@ -103,7 +103,6 @@ import dayjs from 'dayjs';
// 打印工具
import {PRINT_TEMPLATE, simplePrint} from '@/utils/printUtils.js';
import {getEncounterDiagnosis} from '../api';
import apiRequestManager from '@/utils/apiRequestManager.js';
import History from './components/history';
import Template from './components/template';
import TemplateEdit from './components/templateEdit.vue';
@@ -206,7 +205,7 @@ const handleNodeClick = (data, node) => {
// 选择任何病历模板后,都加载该病历类型的最新历史记录
if (node.isLeaf && props.patientInfo && props.patientInfo.patientId) {
debouncedLoadLatestMedicalRecord();
loadLatestMedicalRecord();
}
}, 100);
});
@@ -280,7 +279,7 @@ const handleSubmitOk = async (data) => {
// 等待历史记录列表更新后,重新加载最新病历并更新选中状态
setTimeout(() => {
debouncedLoadLatestMedicalRecord();
loadLatestMedicalRecord();
}, 100);
} catch (error) {
ElMessage.error('提交失败');
@@ -411,7 +410,7 @@ const selectOutpatientMedicalRecordTemplate = async () => {
// 等待模板加载完成,然后获取并回显最新病历数据
setTimeout(() => {
historyRef.value?.queryList();
debouncedLoadLatestMedicalRecord();
loadLatestMedicalRecord();
}, 500);
});
} else {
@@ -422,36 +421,19 @@ const selectOutpatientMedicalRecordTemplate = async () => {
// 当前选中的历史病历ID用于在History组件中高亮显示
const selectedHistoryRecordId = ref('');
import { debounce } from 'lodash-es';
// 防止重复加载的标志
let isLoadingLatestRecord = false;
// 加载最新的病历数据并回显
const loadLatestMedicalRecord = async () => {
if (!patientInfo.value.encounterId || !currentSelectTemplate.value.id) return;
// 防止重复加载
if (isLoadingLatestRecord) {
console.log('Latest medical record is already loading, skipping duplicate call');
return;
}
isLoadingLatestRecord = true;
loading.value = true;
try {
// 获取患者的历史病历记录
const res = await apiRequestManager.execute(
getRecordByEncounterIdList,
'/document/record/getRecordByEncounterIdList',
{
isPage: 0,
encounterId: patientInfo.value.encounterId,
patientId: patientInfo.value.patientId,
definitionId: currentSelectTemplate.value.id,
}
);
const res = await getRecordByEncounterIdList({
isPage: 0,
encounterId: patientInfo.value.encounterId,
patientId: patientInfo.value.patientId,
definitionId: currentSelectTemplate.value.id,
});
const historyRecords = res.data || [];
if (historyRecords.length > 0) {
@@ -537,12 +519,8 @@ const loadLatestMedicalRecord = async () => {
});
} finally {
loading.value = false;
isLoadingLatestRecord = false; // 重置加载标志
}
};
// 防抖版本的加载最新病历数据函数
const debouncedLoadLatestMedicalRecord = debounce(loadLatestMedicalRecord, 300);
const templateRef = ref(null);
const handleTemplateClick = (data) => {
@@ -772,7 +750,7 @@ const selectDefaultTemplate = () => {
// 直接加载最新病历数据不再使用额外的setTimeout延迟
// 因为handleNodeClick中已经有nextTick和setTimeout处理组件渲染
debouncedLoadLatestMedicalRecord();
loadLatestMedicalRecord();
});
} else {
console.log('未找到门诊病历模板');