diff --git a/src/api/hisApi.ts b/src/api/hisApi.ts index f26323b..862ec79 100644 --- a/src/api/hisApi.ts +++ b/src/api/hisApi.ts @@ -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); /** diff --git a/src/pages/U2/u2.tsx b/src/pages/U2/u2.tsx index 43adced..01e4338 100644 --- a/src/pages/U2/u2.tsx +++ b/src/pages/U2/u2.tsx @@ -175,52 +175,50 @@ const U2: React.FC = () => { const countyCode = regionFromId.county || ""; const tryUploadWithPhoto = async () => { - try { - const photoPath = idCardData.photo_path; - if ( - photoPath && - window.electronAPI && - window.electronAPI.readLocalFile - ) { - const res = await window.electronAPI.readLocalFile(photoPath); - if (res && res.success && res.data) { - const base64 = res.data as string; - // 仅支持 BMP:优先使用主进程返回的 mime,否则默认为 image/bmp - const mime = res.mime || "image/bmp"; - - // base64 -> Blob - const byteCharacters = atob(base64); - const byteNumbers = new Array(byteCharacters.length); - for (let i = 0; i < byteCharacters.length; i++) { - byteNumbers[i] = byteCharacters.charCodeAt(i); - } - const byteArray = new Uint8Array(byteNumbers); - const blob = new Blob([byteArray], { type: mime }); - - // 调用带图片的更新接口(传入推断的省市县编码) - const apiRes = await updatePatientInfo( - idCardNo, - selectedMarital, - provinceCode, - cityCode, - countyCode, - address, - blob - ); - return apiRes; - } - } - } catch (err) { - console.warn("upload photo failed", err); + const photoPath = idCardData.photo_path; + 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) { + 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"; + + // base64 -> Blob + const byteCharacters = atob(base64); + const byteNumbers = new Array(byteCharacters.length); + for (let i = 0; i < byteCharacters.length; i++) { + byteNumbers[i] = byteCharacters.charCodeAt(i); + } + const byteArray = new Uint8Array(byteNumbers); + const blob = new Blob([byteArray], { type: mime }); + + // 调用带图片的更新接口(传入推断的省市县编码) return updatePatientInfo( idCardNo, selectedMarital, provinceCode, cityCode, countyCode, - address + address, + blob ); };