优化身份证照片上传逻辑,增加错误处理和日志记录;调整默认API基础URL为内部地址

This commit is contained in:
yuchenglong
2025-12-09 14:22:05 +08:00
parent 0daeb03e62
commit 78f2a106a0
2 changed files with 39 additions and 41 deletions

View File

@@ -153,8 +153,8 @@ function createAxiosInstance(baseURL: string): AxiosInstance {
}
// 默认使用外网URL
let currentBaseURL = API_CONFIG.EXTERNAL_URL;
// let currentBaseURL = API_CONFIG.INTERNAL_URL;
// let currentBaseURL = API_CONFIG.EXTERNAL_URL;
let currentBaseURL = API_CONFIG.INTERNAL_URL;
let axiosInstance = createAxiosInstance(currentBaseURL);
/**

View File

@@ -175,15 +175,28 @@ const U2: React.FC = () => {
const countyCode = regionFromId.county || "";
const tryUploadWithPhoto = async () => {
try {
const photoPath = idCardData.photo_path;
if (
photoPath &&
window.electronAPI &&
window.electronAPI.readLocalFile
) {
if (!photoPath) {
window.electronAPI.log("error", "身份证照片路径不存在,无法上传照片");
throw new Error("身份证照片路径不存在");
}
if (!window.electronAPI || !window.electronAPI.readLocalFile) {
window.electronAPI.log(
"error",
"系统不支持读取本地文件,无法上传身份证照片"
);
throw new Error("系统不支持读取本地文件");
}
const res = await window.electronAPI.readLocalFile(photoPath);
if (res && res.success && res.data) {
if (!res || !res.success || !res.data) {
window.electronAPI.log(
"error",
`读取身份证照片失败: ${res?.error || "未知错误"}`
);
throw new Error(res?.error || "读取身份证照片失败");
}
const base64 = res.data as string;
// 仅支持 BMP优先使用主进程返回的 mime否则默认为 image/bmp
const mime = res.mime || "image/bmp";
@@ -198,7 +211,7 @@ const U2: React.FC = () => {
const blob = new Blob([byteArray], { type: mime });
// 调用带图片的更新接口(传入推断的省市县编码)
const apiRes = await updatePatientInfo(
return updatePatientInfo(
idCardNo,
selectedMarital,
provinceCode,
@@ -207,21 +220,6 @@ const U2: React.FC = () => {
address,
blob
);
return apiRes;
}
}
} catch (err) {
console.warn("upload photo failed", err);
}
// 回退:无图片或上传失败时,走普通接口(包含推断的省市县编码)
return updatePatientInfo(
idCardNo,
selectedMarital,
provinceCode,
cityCode,
countyCode,
address
);
};
tryUploadWithPhoto()