Backup local changes before resolving remote repository issue

This commit is contained in:
2026-01-27 10:05:25 +08:00
parent 11c2758289
commit 86bca03b04
29 changed files with 2626 additions and 126 deletions

View File

@@ -525,19 +525,33 @@ function getList() {
function refresh() {
getListInfo(false);
}
// 防止重复请求的标志
let listInfoRequestPromise = null;
// 获取列表信息
function getListInfo(addNewRow) {
// 如果已经有正在进行的请求则返回该请求的Promise
if (listInfoRequestPromise) {
return listInfoRequestPromise;
}
loadingInstance = ElLoading.service({ fullscreen: true });
setTimeout(() => {
loadingInstance.close();
if (loadingInstance) {
loadingInstance.close();
}
}, 180);
isAdding.value = false;
expandOrder.value = [];
getPrescriptionList(patientInfo.value.encounterId).then((res) => {
console.log('getListInfo==========>', JSON.stringify(res.data));
loadingInstance.close();
prescriptionList.value = res.data
// 并行请求两个API并将结果合并处理
listInfoRequestPromise = Promise.all([
getPrescriptionList(patientInfo.value.encounterId),
getContract({ encounterId: patientInfo.value.encounterId })
])
.then(([prescriptionRes, contractRes]) => {
// 处理处方列表
prescriptionList.value = prescriptionRes.data
.map((item) => {
return {
...JSON.parse(item.contentJson),
@@ -549,15 +563,35 @@ function getListInfo(addNewRow) {
.sort((a, b) => {
return new Date(b.requestTime) - new Date(a.requestTime);
});
getGroupMarkers(); // 更新标记
// 处理合同列表
contractList.value = contractRes.data;
// 更新账户ID
accountId.value = patientInfo.value.accountId;
// 更新标记
getGroupMarkers();
if (props.activeTab == 'prescription' && addNewRow) {
handleAddPrescription();
}
console.log('getListInfo==========>', JSON.stringify(prescriptionRes.data));
})
.catch(error => {
console.error('获取列表信息失败:', error);
ElMessage.error('获取列表信息失败');
})
.finally(() => {
if (loadingInstance) {
loadingInstance.close();
}
// 请求完成后清除Promise引用
listInfoRequestPromise = null;
});
getContract({ encounterId: patientInfo.value.encounterId }).then((res) => {
contractList.value = res.data;
});
accountId.value = patientInfo.value.accountId;
return listInfoRequestPromise;
}
// 数据过滤
const filterPrescriptionList = computed(() => {
@@ -571,18 +605,37 @@ const filterPrescriptionList = computed(() => {
return pList;
});
// 防止诊断信息重复请求的标志
let diagnosisInfoRequestPromise = null;
function getDiagnosisInfo() {
getEncounterDiagnosis(patientInfo.value.encounterId).then((res) => {
diagnosisList.value = res.data;
let diagnosisInfo = diagnosisList.value.filter((item) => {
return item.maindiseFlag == 1;
// 如果已经有正在进行的请求则返回该请求的Promise
if (diagnosisInfoRequestPromise) {
return diagnosisInfoRequestPromise;
}
diagnosisInfoRequestPromise = getEncounterDiagnosis(patientInfo.value.encounterId)
.then((res) => {
diagnosisList.value = res.data;
let diagnosisInfo = diagnosisList.value.filter((item) => {
return item.maindiseFlag == 1;
});
diagnosisInfo.value = diagnosisInfo[0];
conditionDefinitionId.value = diagnosisInfo[0].definitionId;
conditionId.value = diagnosisInfo[0].conditionId;
encounterDiagnosisId.value = diagnosisInfo[0].encounterDiagnosisId;
diagnosisName.value = diagnosisInfo[0].name;
})
.catch(error => {
console.error('获取诊断信息失败:', error);
ElMessage.error('获取诊断信息失败');
})
.finally(() => {
// 请求完成后清除Promise引用
diagnosisInfoRequestPromise = null;
});
diagnosisInfo.value = diagnosisInfo[0];
conditionDefinitionId.value = diagnosisInfo[0].definitionId;
conditionId.value = diagnosisInfo[0].conditionId;
encounterDiagnosisId.value = diagnosisInfo[0].encounterDiagnosisId;
diagnosisName.value = diagnosisInfo[0].name;
});
return diagnosisInfoRequestPromise;
}
function getRowDisabled(row) {

View File

@@ -65,22 +65,40 @@ const queryParams = ref({
isPage: 0,
});
const historyData = ref([]);
// 防止重复请求的标志
let queryListPromise = null;
const queryList = async () => {
// 如果已经有正在进行的请求则返回该请求的Promise
if (queryListPromise) {
return queryListPromise;
}
try {
if (patientInfo.value.encounterId && unref(definitionId) && unref(definitionId) !== '') {
const res = await getRecordByEncounterIdList({
queryListPromise = getRecordByEncounterIdList({
...queryParams.value,
encounterId: patientInfo.value.encounterId,
patientId: patientInfo.value.patientId,
definitionId: unref(definitionId),
})
.then(res => {
historyData.value = res.data || [];
})
.finally(() => {
// 请求完成后清除Promise引用
queryListPromise = null;
});
historyData.value = res.data || [];
return queryListPromise;
} else {
historyData.value = [];
}
} catch (error) {
// 不显示错误消息,避免干扰用户体验
historyData.value = [];
// 请求完成后清除Promise引用
queryListPromise = null;
}
};

View File

@@ -305,9 +305,10 @@ const handleSubmitOk = async (data) => {
// templateRef.value?.queryList();
// 等待历史记录列表更新后,重新加载最新病历并更新选中状态
// 增加延迟时间以确保数据库更新完成
setTimeout(() => {
loadLatestMedicalRecord();
}, 100);
}, 300);
ElMessage.success('保存成功');
} catch (error) {
ElMessage.error('提交失败');
@@ -553,54 +554,94 @@ const selectOutpatientMedicalRecordTemplate = async () => {
selectDefaultTemplate();
};
// 防止重复请求的标志
let loadLatestMedicalRecordPromise = null;
// 加载最新的病历数据并回显
const loadLatestMedicalRecord = async () => {
// 如果已经有正在进行的请求则返回该请求的Promise
if (loadLatestMedicalRecordPromise) {
return loadLatestMedicalRecordPromise;
}
if (!patientInfo.value?.encounterId || !currentSelectTemplate.value.id) return;
editForm.value.id = '';
loading.value = true;
try {
// 获取患者的历史病历记录
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) {
// 按时间排序,获取最新的病历记录
historyRecords.sort((a, b) => new Date(b.recordTime) - new Date(a.recordTime));
const latestRecord = historyRecords[0];
// 创建一个新的Promise来处理请求
loadLatestMedicalRecordPromise = new Promise(async (resolve, reject) => {
try {
// 获取患者的历史病历记录
const res = await getRecordByEncounterIdList({
isPage: 0,
encounterId: patientInfo.value.encounterId,
patientId: patientInfo.value.patientId,
definitionId: currentSelectTemplate.value.id,
});
// 保存最新病历ID用于在History组件中高亮显示
selectedHistoryRecordId.value = latestRecord.id;
// 自动回显最新病历数据到模板
editForm.value = latestRecord;
nextTick(() => {
if (emrComponentRef.value && latestRecord.contentJson) {
try {
const parsedData = JSON.parse(latestRecord.contentJson);
emrComponentRef.value.setFormData(parsedData);
} catch (parseError) {
console.error('解析病历数据失败:', parseError);
// 解析失败时仍然尝试设置空数据以清空之前的残留数据
const historyRecords = res.data || [];
if (historyRecords.length > 0) {
// 按时间排序,获取最新病历记录
historyRecords.sort((a, b) => new Date(b.recordTime) - new Date(a.recordTime));
const latestRecord = historyRecords[0];
// 保存最新病历ID用于在History组件中高亮显示
selectedHistoryRecordId.value = latestRecord.id;
// 自动回显最新病历数据到模板
editForm.value = latestRecord;
nextTick(() => {
if (emrComponentRef.value && latestRecord.contentJson) {
try {
const parsedData = JSON.parse(latestRecord.contentJson);
emrComponentRef.value.setFormData(parsedData);
} catch (parseError) {
console.error('解析病历数据失败:', parseError);
// 解析失败时仍然尝试设置空数据以清空之前的残留数据
emrComponentRef.value.setFormData({});
}
} else {
// 如果没有内容数据,也要清空组件中的数据
emrComponentRef.value.setFormData({});
}
} else {
// 如果没有内容数据,也要清空组件中的数据
emrComponentRef.value.setFormData({});
}
// 通知History组件更新选中状态
if (historyRef.value && typeof historyRef.value.updateSelectedRecord === 'function') {
historyRef.value.updateSelectedRecord(latestRecord.id);
}
});
} else {
// 清空选中状态
// 通知History组件更新选中状态
if (historyRef.value && typeof historyRef.value.updateSelectedRecord === 'function') {
historyRef.value.updateSelectedRecord(latestRecord.id);
}
resolve(); // 成功完成
});
} else {
// 清空选中状态
selectedHistoryRecordId.value = '';
// 当没有历史记录时,也要清空当前表单数据,避免显示之前患者的数据
editForm.value = {
id: '',
definitionId: '',
definitionBusNo: '',
contentJson: '',
statusEnum: 1,
organizationId: 0,
encounterId: '',
patientId: '',
recordTime: dayjs().format('YYYY-MM-DD HH:mm:ss'),
createBy: '',
source: '',
};
nextTick(() => {
if (emrComponentRef.value) {
emrComponentRef.value.setFormData({});
}
resolve(); // 成功完成
});
loading.value = false;
}
} catch (error) {
ElMessage.error('加载最新病历数据失败=====>', error);
// 出错时也清空选中状态
selectedHistoryRecordId.value = '';
// 当没有历史记录时,也要清空当前表单数据,避免显示之前患者的数据
// 出错时也要清空表单数据,避免显示之前患者的数据
editForm.value = {
id: '',
definitionId: '',
@@ -619,37 +660,17 @@ const loadLatestMedicalRecord = async () => {
if (emrComponentRef.value) {
emrComponentRef.value.setFormData({});
}
reject(error); // 错误完成
});
loading.value = false;
} finally {
loading.value = false;
// 请求完成后清除Promise引用
loadLatestMedicalRecordPromise = null;
}
} catch (error) {
ElMessage.error('加载最新病历数据失败=====>', error);
// 出错时也清空选中状态
selectedHistoryRecordId.value = '';
// 出错时也要清空表单数据,避免显示之前患者的数据
editForm.value = {
id: '',
definitionId: '',
definitionBusNo: '',
contentJson: '',
statusEnum: 1,
organizationId: 0,
encounterId: '',
patientId: '',
recordTime: dayjs().format('YYYY-MM-DD HH:mm:ss'),
createBy: '',
source: '',
};
});
nextTick(() => {
if (emrComponentRef.value) {
emrComponentRef.value.setFormData({});
}
});
loading.value = false;
} finally {
loading.value = false;
}
return loadLatestMedicalRecordPromise;
};
// 选择默认模板 - 获取住院病历分类下的第一个模板
@@ -835,6 +856,41 @@ watch(
{ deep: true, immediate: true }
);
// 合并两个监听器,避免重复触发
let patientChangeProcessing = false; // 防止重复处理
watch(
() => [patientInfo.value?.encounterId, currentSelectTemplate.value?.id],
([newEncounterId, newTemplateId]) => {
// 当患者就诊ID或模板ID变化时加载最新病历数据
if (newEncounterId && newTemplateId && !patientChangeProcessing) {
patientChangeProcessing = true;
// 添加延迟以确保模板数据已更新
nextTick(() => {
loadLatestMedicalRecord().finally(() => {
// 重置处理标志
patientChangeProcessing = false;
});
});
}
},
{ immediate: true }
);
// 监听模板选择变化,当模板选择变化时加载最新病历数据
watch(
() => currentSelectTemplate.value.id,
(newTemplateId) => {
// 当模板选择变化时,加载该模板的最新病历数据
if (newTemplateId) {
// 只要有模板ID就尝试加载数据不管之前是否有患者信息
// 因为可能是在切换患者后才选择模板
loadLatestMedicalRecord();
}
}
);
onMounted(async () => {
// 移除日志
await queryTemplateTree();

View File

@@ -109,16 +109,25 @@ 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
!patientInfo.value?.encounterId &&
!hasManuallySelectedPatient.value
) {
const firstPatient = newData[0];
if (firstPatient?.encounterId) {
@@ -130,34 +139,81 @@ 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 }
);
// 防抖函数,防止快速点击导致状态冲突
let debounceTimer = null;
// 更新handleItemClick函数设置期望的患者ID
const handleItemClick = (node) => {
// 设置期望的患者ID
expectedPatientId = node.encounterId;
// 清除之前的计时器
if (debounceTimer) {
clearTimeout(debounceTimer);
}
// 取消之前未完成的患者加载操作
if (currentPatientPromise) {
// 注意这里无法真正取消Promise但我们可以标记当前操作已过期
currentPatientPromise.cancelled = true;
}
// 设置新的计时器
debounceTimer = setTimeout(() => {
debounceTimer = setTimeout(async () => {
// 检查是否已被取消
if (currentPatientPromise?.cancelled) {
return;
}
cardId.value = node.encounterId;
// 同时更新本地和全局状态,确保模块内组件和跨模块组件都能正确响应
updatePatientInfo(node);
updateLocalPatientInfo(node);
diagnosisRef.value?.getList();
adviceRef.value?.getListInfo();
adviceRef.value?.getDiagnosisInfo();
// 标记已手动选择患者,防止自动选择第一条
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);
}
}, 100); // 100ms 防抖延迟
};
// 防抖函数,防止快速点击导致状态冲突
const handleSearch = (keyword) => {
searchData.keyword = keyword;
getList();