门诊医生站患者病历打不开 不显示数据问题
This commit is contained in:
@@ -219,6 +219,7 @@ const templateName = ref('');
|
||||
// 事件
|
||||
const emits = defineEmits(['save']);
|
||||
const { proxy } = getCurrentInstance();
|
||||
console.log('EMR组件初始化,proxy:', proxy);
|
||||
|
||||
// 监听表单变化
|
||||
watch(
|
||||
@@ -325,18 +326,109 @@ function cancel() {
|
||||
// 暴露方法给父组件
|
||||
defineExpose({
|
||||
getDetail(encounterId) {
|
||||
getEmrDetail(encounterId).then((res) => {
|
||||
if (res.data) {
|
||||
console.log('开始获取病历详情,encounterId:', encounterId);
|
||||
|
||||
// 立即初始化form.value为空对象,确保页面有内容显示
|
||||
form.value = {};
|
||||
|
||||
// 检查API函数是否存在
|
||||
if (typeof getEmrDetail !== 'function') {
|
||||
console.error('getEmrDetail函数未定义');
|
||||
if (proxy) {
|
||||
proxy.$modal.msgError('获取病历详情失败:API函数未定义');
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// 添加超时处理,防止请求一直挂起
|
||||
const timeoutPromise = new Promise((_, reject) => {
|
||||
setTimeout(() => {
|
||||
reject(new Error('获取病历详情请求超时'));
|
||||
}, 10000); // 10秒超时
|
||||
});
|
||||
|
||||
// 使用Promise.race处理正常请求和超时
|
||||
Promise.race([getEmrDetail(encounterId), timeoutPromise])
|
||||
.then((res) => {
|
||||
console.log('获取病历详情成功,返回完整数据:', JSON.stringify(res, null, 2));
|
||||
|
||||
// 检查响应是否有效
|
||||
if (!res) {
|
||||
console.error('API返回结果为空');
|
||||
if (proxy) {
|
||||
proxy.$modal.msgError('获取病历详情失败:API返回结果为空');
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('res存在,类型:', typeof res);
|
||||
console.log('res的属性:', Object.keys(res));
|
||||
|
||||
// 检查响应码
|
||||
if (res.code !== 200) {
|
||||
console.error('API返回错误代码:', res.code);
|
||||
if (proxy) {
|
||||
proxy.$modal.msgError('获取病历详情失败:' + (res.msg || '未知错误'));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// 检查数据是否存在
|
||||
if (!res.data) {
|
||||
console.log('res.data为空,使用默认值');
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('res.data存在,类型:', typeof res.data);
|
||||
console.log('res.data的属性:', Object.keys(res.data));
|
||||
|
||||
// 处理contextJson
|
||||
try {
|
||||
form.value = JSON.parse(res.data.contextJson) || {};
|
||||
if (res.data.contextJson) {
|
||||
console.log('contextJson存在,值:', res.data.contextJson);
|
||||
console.log('contextJson类型:', typeof res.data.contextJson);
|
||||
|
||||
// 检查contextJson类型
|
||||
if (typeof res.data.contextJson === 'string') {
|
||||
// 尝试解析JSON字符串
|
||||
const parsedData = JSON.parse(res.data.contextJson);
|
||||
// 确保解析结果是对象
|
||||
if (typeof parsedData === 'object' && parsedData !== null) {
|
||||
form.value = parsedData;
|
||||
console.log('解析后的病历数据:', JSON.stringify(form.value, null, 2));
|
||||
} else {
|
||||
form.value = {};
|
||||
console.error('contextJson解析结果不是有效对象:', parsedData);
|
||||
}
|
||||
} else if (typeof res.data.contextJson === 'object') {
|
||||
// 如果已经是对象,直接使用
|
||||
form.value = res.data.contextJson;
|
||||
console.log('直接使用contextJson作为对象:', JSON.stringify(form.value, null, 2));
|
||||
} else {
|
||||
form.value = {};
|
||||
console.error('contextJson类型无效:', typeof res.data.contextJson);
|
||||
}
|
||||
} else {
|
||||
console.log('contextJson为空,使用默认值');
|
||||
}
|
||||
} catch (e) {
|
||||
form.value = {};
|
||||
console.error('病历数据解析失败:', e);
|
||||
console.error('解析失败的contextJson值:', res.data.contextJson);
|
||||
if (proxy) {
|
||||
proxy.$modal.msgError('病历数据解析失败');
|
||||
}
|
||||
}
|
||||
|
||||
emits('save', true);
|
||||
} else {
|
||||
form.value = {};
|
||||
}
|
||||
});
|
||||
})
|
||||
.catch((error) => {
|
||||
// 处理API调用失败或超时的情况
|
||||
console.error('获取病历详情失败:', error);
|
||||
if (proxy) {
|
||||
proxy.$modal.msgError('获取病历详情失败:' + (error.message || '未知错误'));
|
||||
}
|
||||
});
|
||||
},
|
||||
addEmr
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user