添加32位打包和日志
This commit is contained in:
@@ -18,17 +18,27 @@ const U1: React.FC = () => {
|
||||
const handleStart = () => {
|
||||
if (reading) return; // 避免重复点击
|
||||
setReading(true);
|
||||
// 启动后端监听
|
||||
// 启动后端监听;如果启动失败立即恢复 UI 状态
|
||||
window.electronAPI.startIdCardListen().catch((e: any) => {
|
||||
console.error("start_idcard_listen failed", e);
|
||||
window.electronAPI.log("error", `start_idcard_listen failed: ${e}`);
|
||||
setReading(false);
|
||||
});
|
||||
|
||||
// 6 秒超时恢复
|
||||
if (timerRef.current) {
|
||||
clearTimeout(timerRef.current);
|
||||
timerRef.current = null;
|
||||
}
|
||||
timerRef.current = window.setTimeout(() => {
|
||||
if (reading) {
|
||||
console.warn("未在 6 秒内读取到身份证信息,恢复初始状态");
|
||||
setReading(false);
|
||||
window.electronAPI.stopIdCardListen().catch(() => {});
|
||||
}
|
||||
console.warn("未在 6 秒内读取到身份证信息,恢复初始状态");
|
||||
window.electronAPI.log(
|
||||
"warn",
|
||||
"未在 6 秒内读取到身份证信息,恢复初始状态"
|
||||
);
|
||||
setReading(false);
|
||||
window.electronAPI.stopIdCardListen().catch(() => {});
|
||||
timerRef.current = null;
|
||||
}, 6000);
|
||||
};
|
||||
|
||||
@@ -39,6 +49,7 @@ const U1: React.FC = () => {
|
||||
window.electronAPI.onIdCardData((e: any) => {
|
||||
const payload = e.payload;
|
||||
console.log("[idcard-data]", payload);
|
||||
window.electronAPI.log("info", `[idcard-data] received`);
|
||||
// 成功:清理定时器,停止监听,跳转并传递身份证号
|
||||
if (timerRef.current) {
|
||||
clearTimeout(timerRef.current);
|
||||
@@ -54,6 +65,7 @@ const U1: React.FC = () => {
|
||||
// 监听错误 (可选)
|
||||
window.electronAPI.onIdCardError((e: any) => {
|
||||
console.error("[idcard-error]", e.payload);
|
||||
window.electronAPI.log("error", `[idcard-error] ${e.payload}`);
|
||||
});
|
||||
|
||||
return () => {
|
||||
|
||||
1
src/vite-env.d.ts
vendored
1
src/vite-env.d.ts
vendored
@@ -6,6 +6,7 @@ interface Window {
|
||||
stopIdCardListen: () => Promise<any>;
|
||||
onIdCardData: (callback: (data: any) => void) => void;
|
||||
onIdCardError: (callback: (error: any) => void) => void;
|
||||
log: (level: string, message: any) => void;
|
||||
removeIdCardListeners: () => void;
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user