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

@@ -109,25 +109,16 @@ const getList = () => {
});
};
// 标记是否已经手动选择过患者,防止后续自动选择
const hasManuallySelectedPatient = ref(false);
// 添加一个变量来跟踪当前期望的患者ID
let expectedPatientId = null;
watch(
() => filteredCardData.value,
(newData) => {
// 如果有数据且当前没有选中患者,且是首次加载,默认选择第一条
// 只有在从未手动选择过患者的情况下才自动选择
// 并且确保当前没有正在处理的患者切换操作
if (
newData &&
newData.length > 0 &&
!cardId.value &&
isFirstLoad.value &&
!patientInfo.value?.encounterId &&
!hasManuallySelectedPatient.value
!patientInfo.value?.encounterId
) {
const firstPatient = newData[0];
if (firstPatient?.encounterId) {
@@ -139,81 +130,34 @@ watch(
debounceTimer = setTimeout(() => {
handleItemClick(firstPatient);
isFirstLoad.value = false;
hasManuallySelectedPatient.value = true; // 标记已手动选择过
}, 100);
}
} else if (expectedPatientId && cardId.value && cardId.value !== expectedPatientId) {
// 如果当前cardId与期望的不一致且不是初始状态这可能意味着发生了意外的重置
// 这种情况下,我们不希望自动选择第一个患者
console.debug(`期望的患者ID: ${expectedPatientId}, 当前cardId: ${cardId.value}`);
}
},
{ immediate: true }
);
// 更新handleItemClick函数设置期望的患者ID
// 防抖函数,防止快速点击导致状态冲突
let debounceTimer = null;
const handleItemClick = (node) => {
// 设置期望的患者ID
expectedPatientId = node.encounterId;
// 清除之前的计时器
if (debounceTimer) {
clearTimeout(debounceTimer);
}
// 取消之前未完成的患者加载操作
if (currentPatientPromise) {
// 注意这里无法真正取消Promise但我们可以标记当前操作已过期
currentPatientPromise.cancelled = true;
}
// 设置新的计时器
debounceTimer = setTimeout(async () => {
// 检查是否已被取消
if (currentPatientPromise?.cancelled) {
return;
}
debounceTimer = setTimeout(() => {
cardId.value = node.encounterId;
// 同时更新本地和全局状态,确保模块内组件和跨模块组件都能正确响应
updatePatientInfo(node);
updateLocalPatientInfo(node);
// 标记已手动选择患者,防止自动选择第一条
hasManuallySelectedPatient.value = true;
// 创建一个新的Promise来追踪这次加载操作
currentPatientPromise = Promise.all([
// 并行调用医嘱相关的API避免重复请求
adviceRef.value?.getListInfo().catch(error => {
console.error('获取医嘱信息失败:', error);
return null;
}),
adviceRef.value?.getDiagnosisInfo().catch(error => {
console.error('获取诊断信息失败:', error);
return null;
}),
// 获取诊断信息
diagnosisRef.value?.getList?.().catch(error => {
console.error('获取诊断信息失败:', error);
return null;
})
]);
try {
await currentPatientPromise;
// 检查在此期间是否选择了其他患者
if (currentPatientPromise?.cancelled) {
return;
}
} catch (error) {
console.error('加载患者信息时出错:', error);
}
diagnosisRef.value?.getList();
adviceRef.value?.getListInfo();
adviceRef.value?.getDiagnosisInfo();
}, 100); // 100ms 防抖延迟
};
// 防抖函数,防止快速点击导致状态冲突
const handleSearch = (keyword) => {
searchData.keyword = keyword;
getList();