From c30bb416de3e7ab06c17e5f73fa99bbb88890531 Mon Sep 17 00:00:00 2001 From: yuchenglong Date: Mon, 24 Nov 2025 17:18:51 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0patient-info=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/U1/u1.tsx | 14 ++++++-- src/pages/U2/u2.tsx | 80 ++++++++++++++++++++++++++++++++------------- 2 files changed, 69 insertions(+), 25 deletions(-) diff --git a/src/pages/U1/u1.tsx b/src/pages/U1/u1.tsx index 4b6edc5..c84382c 100644 --- a/src/pages/U1/u1.tsx +++ b/src/pages/U1/u1.tsx @@ -16,6 +16,8 @@ const U1: React.FC = () => { const timerRef = useRef(null); const handleStart = () => { + localStorage.setItem("lastIdCardNo", "31010919571209004X"); + navigate("/u2"); if (reading) return; // 避免重复点击 setReading(true); // 启动后端监听;如果启动失败立即恢复 UI 状态 @@ -48,6 +50,14 @@ const U1: React.FC = () => { // 监听数据 window.electronAPI.onIdCardData((e: any) => { const payload = e.payload; + // 保存到 localStorage,下一次刷卡时覆盖 + try { + if (payload?.id_card_no) { + localStorage.setItem("lastIdCardNo", payload.id_card_no); + } + } catch (err) { + console.warn("localStorage.setItem failed", err); + } console.log("[idcard-data]", payload); window.electronAPI.log("info", `[idcard-data] received`); window.electronAPI.log( @@ -61,9 +71,7 @@ const U1: React.FC = () => { } window.electronAPI.stopIdCardListen().catch(() => {}); setReading(false); - navigate("/u2", { - state: { idCardNo: payload?.id_card_no, cardData: payload }, - }); + navigate("/u2"); }); // 监听错误 (可选) diff --git a/src/pages/U2/u2.tsx b/src/pages/U2/u2.tsx index 6257a23..36354a5 100644 --- a/src/pages/U2/u2.tsx +++ b/src/pages/U2/u2.tsx @@ -1,15 +1,41 @@ -import React from "react"; +import React, { useEffect, useState } from "react"; import "./u2.css"; -import { useNavigate, useLocation } from "react-router-dom"; +import { useNavigate } from "react-router-dom"; import DecorLine from "../../components/DecorLine"; import avatar from "../../assets/avatar.png"; import semicircle from "../../assets/semicircle.png"; import BackButton from "../../components/BackButton"; import ConfirmButton from "../../components/ConfirmButton"; +import { getPatientInfo, PatientInfo } from "../../api/hisApi"; + const U2: React.FC = () => { const navigate = useNavigate(); - const location = useLocation(); - const idCardNo = (location.state as any)?.idCardNo; + // 不再通过路由传参,直接从 localStorage 读取上次保存的身份证号 + const idCardNo = localStorage.getItem("lastIdCardNo"); + const [patientInfo, setPatientInfo] = useState(null); + const [loading, setLoading] = useState(false); + + useEffect(() => { + if (idCardNo) { + setLoading(true); + getPatientInfo(idCardNo) + .then((res) => { + if (res.Status === 200) { + setPatientInfo(res.Data); + } else { + alert(`获取用户信息失败: ${res.Message}`); + } + }) + .catch((err) => { + console.error(err); + alert("获取用户信息出错,请重试"); + }) + .finally(() => { + setLoading(false); + }); + } + }, [idCardNo]); + const handleBack = () => { navigate(-1); }; @@ -38,36 +64,46 @@ const U2: React.FC = () => {
avatar
-
-
-
姓名:xxx
-
- -
-
-
性别:x
-
- -
-
-
年龄:56岁
-
-
- 证件号:{idCardNo ?? "xxxxxxxxxxxxxx"} + 姓名:{loading ? "" : patientInfo?.name || "---"}
-
手机号:166xxxxxxxx
+
+ 性别:{loading ? "" : patientInfo?.gender_name || "---"} +
-
婚姻状况:未婚
+
+ 年龄:{loading ? "" : patientInfo?.age || "---"} +
+
+ +
+
+
+ 证件号:{idCardNo || patientInfo?.IdCard || "---"} +
+
+ +
+
+
+ 手机号:{loading ? "" : patientInfo?.phone || "---"} +
+
+ +
+
+
+ 婚姻状况:{loading ? "" : patientInfo?.marital_name || "---"} +