From 25fdb36dc637dedbcef6eaec193a93c111c247dc Mon Sep 17 00:00:00 2001 From: yuchenglong Date: Fri, 28 Nov 2025 18:01:26 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=BA=AB=E4=BB=BD=E8=AF=81?= =?UTF-8?q?=E8=AF=BB=E5=8F=96=E9=80=BB=E8=BE=91=EF=BC=8C=E7=AE=80=E5=8C=96?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E5=B9=B6=E6=B8=85=E7=90=86=E4=B8=8D=E5=BF=85?= =?UTF-8?q?=E8=A6=81=E7=9A=84=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/U1/u1.tsx | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/src/pages/U1/u1.tsx b/src/pages/U1/u1.tsx index f57c084..f4babbf 100644 --- a/src/pages/U1/u1.tsx +++ b/src/pages/U1/u1.tsx @@ -19,16 +19,13 @@ const U1: React.FC = () => { // 实时监听身份证读取 useEffect(() => { - // 启动后端监听 window.electronAPI.startIdCardListen().catch((e: any) => { console.error("start_idcard_listen failed", e); window.electronAPI.log("error", `start_idcard_listen failed: ${e}`); }); - // 监听数据 window.electronAPI.onIdCardData((e: any) => { const payload = e.payload; - // 保存到 localStorage,下一次刷卡时覆盖 try { if (payload?.id_card_no) { localStorage.setItem("lastIdCardNo", payload.id_card_no); @@ -43,8 +40,7 @@ const U1: React.FC = () => { `Read IDCard success: ${payload.name} ${payload.id_card_no}` ); - // 无论是否点击了开始签到,只要读到卡就跳转 - // 清理定时器 + // 读到卡即跳转;清理倒计时 if (timerRef.current) { clearTimeout(timerRef.current); timerRef.current = null; @@ -53,22 +49,14 @@ const U1: React.FC = () => { clearInterval(intervalRef.current); intervalRef.current = null; } - // 停止监听(跳转后不再需要监听) window.electronAPI.stopIdCardListen().catch(() => {}); setReading(false); navigate("/u2"); }); - // 监听错误 (可选) window.electronAPI.onIdCardError((e: any) => { console.error("[idcard-error]", e.payload); window.electronAPI.log("error", `[idcard-error] ${e.payload}`); - // 错误不停止监听,继续等待下一次读取,除非是严重错误? - // 这里仅记录日志,或者在 reading 状态下提示用户 - if (reading) { - // 如果正在倒计时中出错,可以选择停止倒计时或者忽略 - // 目前保持监听 - } }); return () => { @@ -77,7 +65,7 @@ const U1: React.FC = () => { if (timerRef.current) clearTimeout(timerRef.current); if (intervalRef.current) clearInterval(intervalRef.current); }; - }, [navigate, reading]); + }, [navigate]); const handleStart = () => { if (reading) return; // 避免重复点击