添加patient-info接口
This commit is contained in:
@@ -16,6 +16,8 @@ const U1: React.FC = () => {
|
||||
const timerRef = useRef<number | null>(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");
|
||||
});
|
||||
|
||||
// 监听错误 (可选)
|
||||
|
||||
@@ -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<PatientInfo | null>(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 = () => {
|
||||
<div className="u2-info-card">
|
||||
<img className="u2-avatar" src={avatar} alt="avatar" />
|
||||
<div className="u2-details-list">
|
||||
<div className="u2-detail-row">
|
||||
<div className="u2-detail-bar" />
|
||||
<div className="u2-detail-text">姓名:xxx</div>
|
||||
</div>
|
||||
|
||||
<div className="u2-detail-row">
|
||||
<div className="u2-detail-bar" />
|
||||
<div className="u2-detail-text">性别:x</div>
|
||||
</div>
|
||||
|
||||
<div className="u2-detail-row">
|
||||
<div className="u2-detail-bar" />
|
||||
<div className="u2-detail-text">年龄:56岁</div>
|
||||
</div>
|
||||
|
||||
<div className="u2-detail-row">
|
||||
<div className="u2-detail-bar" />
|
||||
<div className="u2-detail-text">
|
||||
证件号:{idCardNo ?? "xxxxxxxxxxxxxx"}
|
||||
姓名:{loading ? "" : patientInfo?.name || "---"}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="u2-detail-row">
|
||||
<div className="u2-detail-bar" />
|
||||
<div className="u2-detail-text">手机号:166xxxxxxxx</div>
|
||||
<div className="u2-detail-text">
|
||||
性别:{loading ? "" : patientInfo?.gender_name || "---"}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="u2-detail-row">
|
||||
<div className="u2-detail-bar" />
|
||||
<div className="u2-detail-text">婚姻状况:未婚</div>
|
||||
<div className="u2-detail-text">
|
||||
年龄:{loading ? "" : patientInfo?.age || "---"}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="u2-detail-row">
|
||||
<div className="u2-detail-bar" />
|
||||
<div className="u2-detail-text">
|
||||
证件号:{idCardNo || patientInfo?.IdCard || "---"}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="u2-detail-row">
|
||||
<div className="u2-detail-bar" />
|
||||
<div className="u2-detail-text">
|
||||
手机号:{loading ? "" : patientInfo?.phone || "---"}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="u2-detail-row">
|
||||
<div className="u2-detail-bar" />
|
||||
<div className="u2-detail-text">
|
||||
婚姻状况:{loading ? "" : patientInfo?.marital_name || "---"}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user