This commit is contained in:
xianyi
2025-11-20 17:15:17 +08:00
89 changed files with 475 additions and 121814 deletions

2
.gitignore vendored
View File

@@ -1 +1,3 @@
node_modules
release
dist

File diff suppressed because one or more lines are too long

2
dist/index.html vendored
View File

@@ -4,7 +4,7 @@
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Electron + React App</title>
<script type="module" crossorigin src="./assets/index-d39aadb6.js"></script>
<script type="module" crossorigin src="./assets/index-cc0bc14e.js"></script>
<link rel="stylesheet" href="./assets/index-0c3a5195.css">
</head>
<body>

233
electron/idcard-worker.js Normal file
View File

@@ -0,0 +1,233 @@
const { parentPort } = require("worker_threads");
const koffi = require("koffi");
const path = require("path");
const iconv = require("iconv-lite");
// 定义结构体
const IDCardData = koffi.struct("IDCardData", {
Name: koffi.array("char", 32),
Sex: koffi.array("char", 6),
Nation: koffi.array("char", 20),
Born: koffi.array("char", 18),
Address: koffi.array("char", 72),
IDCardNo: koffi.array("char", 38),
GrantDept: koffi.array("char", 32),
UserLifeBegin: koffi.array("char", 18),
UserLifeEnd: koffi.array("char", 18),
reserved: koffi.array("char", 38),
PhotoFileName: koffi.array("char", 255),
});
let lib = null;
let running = false;
// 解码 GBK 字符串
function decodeGBK(buffer) {
// 找到第一个 null 字节 (0x00) 的位置
let nullIndex = -1;
for (let i = 0; i < buffer.length; i++) {
if (buffer[i] === 0) {
nullIndex = i;
break;
}
}
// 如果找到了 null截取前面的部分否则使用整个 buffer
const validBuffer = nullIndex !== -1 ? buffer.slice(0, nullIndex) : buffer;
return iconv.decode(validBuffer, "gbk").trim();
}
// 加载 DLL
function loadDll() {
if (lib) return true;
try {
const fs = require("fs");
const dllNames = ["Syn_IDCardRead.dll", "SynIDCardRead.dll"];
// 确定 DLL 目录:优先检查生产环境 resources/xzx否则使用开发环境 resources/xzx
let dllDir = path.join(process.cwd(), "resources", "xzx");
if (process.resourcesPath) {
const prodDir = path.join(process.resourcesPath, "xzx");
if (fs.existsSync(prodDir)) {
dllDir = prodDir;
}
}
let dllPath = null;
for (const name of dllNames) {
const p = path.join(dllDir, name);
if (fs.existsSync(p)) {
dllPath = p;
break;
}
}
if (!dllPath) {
throw new Error(`DLL not found in ${dllDir}`);
}
parentPort.postMessage({
type: "log",
payload: `Loading DLL from: ${dllPath}`,
});
lib = koffi.load(dllPath);
// 尝试使用 stdcall 约定,这对于 Windows 32位 DLL 很常见
// koffi 2.x 版本中stdcall 约定需要在函数名前加 __stdcall
// 如果字符串解析失败,可以尝试使用 lib.stdcall() 方法
// 辅助函数:尝试加载函数,支持原名和修饰名
const loadFunc = (name, alias, ret, args) => {
try {
return lib.stdcall(name, ret, args);
} catch (e) {
try {
return lib.stdcall(alias, ret, args);
} catch (e2) {
throw new Error(
`Cannot find function '${name}' or '${alias}' in DLL`
);
}
}
};
try {
return {
Syn_OpenPort: loadFunc("Syn_OpenPort", "_Syn_OpenPort@4", "int", [
"int",
]),
Syn_ClosePort: loadFunc("Syn_ClosePort", "_Syn_ClosePort@4", "int", [
"int",
]),
Syn_StartFindIDCard: loadFunc(
"Syn_StartFindIDCard",
"_Syn_StartFindIDCard@12",
"int",
["int", "uint8*", "int"]
),
Syn_SelectIDCard: loadFunc(
"Syn_SelectIDCard",
"_Syn_SelectIDCard@12",
"int",
["int", "uint8*", "int"]
),
Syn_ReadMsg: loadFunc("Syn_ReadMsg", "_Syn_ReadMsg@12", "int", [
"int",
"int",
koffi.out(koffi.pointer(IDCardData)),
]),
};
} catch (e) {
// 如果 lib.stdcall 也不行,尝试回退到 func 但不带 __stdcall (可能不是 stdcall 或者 koffi 版本差异)
// 但根据之前的错误,不带 __stdcall 找不到函数,带了又报类型错误,说明很可能是 stdcall 但字符串解析有问题
// 这里我们坚持用 lib.stdcall 这种显式 API 调用,它比字符串解析更稳定
throw e;
}
} catch (err) {
parentPort.postMessage({
type: "error",
payload: `Failed to load DLL: ${err.message}`,
});
return null;
}
}
async function startListen() {
if (running) return;
running = true;
const api = loadDll();
if (!api) {
running = false;
return;
}
try {
// 尝试打开端口,优先尝试 1001 (USB)
let port = 1001;
let openRes = api.Syn_OpenPort(port);
if (openRes !== 0) {
// 如果 1001 失败,尝试 1001-1016
for (let p = 1002; p <= 1016; p++) {
if (api.Syn_OpenPort(p) === 0) {
port = p;
openRes = 0;
break;
}
}
}
if (openRes !== 0) {
parentPort.postMessage({
type: "error",
payload: `Open port failed (tried 1001-1016)`,
});
running = false;
return;
}
parentPort.postMessage({
type: "log",
payload: `Port ${port} opened successfully`,
});
const iin = Buffer.alloc(4);
const sn = Buffer.alloc(8);
// IDCardData 结构体大小计算: 32+6+20+18+72+38+32+18+18+38+255 = 547 字节
// koffi 会自动处理结构体内存分配
while (running) {
// 寻卡
api.Syn_StartFindIDCard(port, iin, 0);
// 选卡
api.Syn_SelectIDCard(port, sn, 0);
// 读卡
const data = {}; // koffi 输出对象
const ret = api.Syn_ReadMsg(port, 0, data);
if (ret === 0 && data) {
const payload = {
name: decodeGBK(Buffer.from(data.Name)),
sex: decodeGBK(Buffer.from(data.Sex)),
nation: decodeGBK(Buffer.from(data.Nation)),
born: decodeGBK(Buffer.from(data.Born)),
address: decodeGBK(Buffer.from(data.Address)),
id_card_no: decodeGBK(Buffer.from(data.IDCardNo)),
grant_dept: decodeGBK(Buffer.from(data.GrantDept)),
life_begin: decodeGBK(Buffer.from(data.UserLifeBegin)),
life_end: decodeGBK(Buffer.from(data.UserLifeEnd)),
photo_path: decodeGBK(Buffer.from(data.PhotoFileName)),
};
parentPort.postMessage({
type: "log",
payload: `Read IDCard success: ${payload.name} ${payload.id_card_no}`,
});
parentPort.postMessage({ type: "data", payload });
// 读到卡后暂停一下,避免重复读取太快
await new Promise((r) => setTimeout(r, 500));
} else {
// 没读到卡,稍微等待
await new Promise((r) => setTimeout(r, 150));
}
}
api.Syn_ClosePort(port);
} catch (err) {
parentPort.postMessage({
type: "error",
payload: `Worker error: ${err.message}`,
});
running = false;
}
}
parentPort.on("message", (msg) => {
if (msg === "start") {
startListen();
} else if (msg === "stop") {
running = false;
}
});

View File

@@ -3,7 +3,57 @@ const path = require("path");
const https = require("https");
const http = require("http");
let mainWindow;
let mainWindow = null;
const { Worker } = require("worker_threads");
const log = require("electron-log");
// 配置日志输出
log.transports.file.level = "info";
log.transports.file.resolvePath = () =>
path.join(path.dirname(app.getPath("exe")), "logs", "main.log");
log.info("App starting...");
// 监听渲染进程日志
ipcMain.on("log-message", (event, { level, message }) => {
if (log[level]) {
log[level](`[Renderer] ${message}`);
} else {
log.info(`[Renderer] ${message}`);
}
});
let idCardWorker = null;
function createIdCardWorker() {
if (idCardWorker) return;
log.info("Creating IDCard Worker...");
idCardWorker = new Worker(path.join(__dirname, "idcard-worker.js"));
idCardWorker.on("message", (msg) => {
if (!mainWindow) return;
if (msg.type === "data") {
log.info("IDCard data received");
mainWindow.webContents.send("idcard-data", { payload: msg.payload });
} else if (msg.type === "error") {
log.error("IDCard worker error message:", msg.payload);
mainWindow.webContents.send("idcard-error", { payload: msg.payload });
} else if (msg.type === "log") {
log.info("[Worker]", msg.payload);
}
});
idCardWorker.on("error", (err) => {
log.error("Worker thread error:", err);
});
idCardWorker.on("exit", (code) => {
if (code !== 0) log.error(`Worker stopped with exit code ${code}`);
else log.info("Worker stopped gracefully");
idCardWorker = null;
});
}
function createWindow() {
mainWindow = new BrowserWindow({
@@ -16,11 +66,16 @@ function createWindow() {
},
});
// 开发环境下加载 Vite 开发服务器地址
// 生产环境下加载打包后的 index.html
mainWindow = win;
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><C2BC><EFBFBD> Vite <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><C2BC>ش<EFBFBD><D8B4><EFBFBD><EFBFBD><EFBFBD> index.html
const isDev = !app.isPackaged;
if (isDev) {
win.loadURL("http://localhost:5173");
// <20>򿪿<EFBFBD><F2BFAABF><EFBFBD><EFBFBD>߹<EFBFBD><DFB9><EFBFBD>
win.webContents.openDevTools();
mainWindow.loadURL("http://localhost:5173");
// 打开开发者工具
mainWindow.webContents.openDevTools();
@@ -126,6 +181,25 @@ ipcMain.handle("print-pdf", async (event, pdfUrl) => {
app.whenReady().then(() => {
createWindow();
createIdCardWorker();
// IPC <20><><EFBFBD><EFBFBD>
ipcMain.handle("start_idcard_listen", () => {
if (idCardWorker) {
idCardWorker.postMessage("start");
} else {
createIdCardWorker();
idCardWorker.postMessage("start");
}
return "started";
});
ipcMain.handle("stop_idcard_listen", () => {
if (idCardWorker) {
idCardWorker.postMessage("stop");
}
return "stopped";
});
app.on("activate", () => {
if (BrowserWindow.getAllWindows().length === 0) {
@@ -135,6 +209,9 @@ app.whenReady().then(() => {
});
app.on("window-all-closed", () => {
if (idCardWorker) {
idCardWorker.terminate();
}
if (process.platform !== "darwin") {
app.quit();
}

View File

@@ -5,4 +5,15 @@ contextBridge.exposeInMainWorld("electronAPI", {
fetchPdf: (pdfUrl) => ipcRenderer.invoke("fetch-pdf", pdfUrl),
// 打印PDF
printPdf: (pdfUrl) => ipcRenderer.invoke("print-pdf", pdfUrl),
startIdCardListen: () => ipcRenderer.invoke("start_idcard_listen"),
stopIdCardListen: () => ipcRenderer.invoke("stop_idcard_listen"),
onIdCardData: (callback) =>
ipcRenderer.on("idcard-data", (event, value) => callback(value)),
onIdCardError: (callback) =>
ipcRenderer.on("idcard-error", (event, value) => callback(value)),
log: (level, message) => ipcRenderer.send("log-message", { level, message }),
removeIdCardListeners: () => {
ipcRenderer.removeAllListeners("idcard-data");
ipcRenderer.removeAllListeners("idcard-error");
},
});

75
package-lock.json generated
View File

@@ -10,6 +10,9 @@
"license": "ISC",
"dependencies": {
"pdfjs-dist": "2.16.105",
"electron-log": "^5.4.3",
"iconv-lite": "^0.7.0",
"koffi": "^2.14.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-pdf": "5.7.2",
@@ -2813,6 +2816,18 @@
"node": ">=12"
}
},
"node_modules/dmg-builder/node_modules/iconv-lite": {
"version": "0.6.3",
"resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.6.3.tgz",
"integrity": "sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw==",
"dev": true,
"dependencies": {
"safer-buffer": ">= 2.1.2 < 3.0.0"
},
"engines": {
"node": ">=0.10.0"
}
},
"node_modules/dmg-builder/node_modules/jsonfile": {
"version": "6.2.0",
"resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.2.0.tgz",
@@ -3046,6 +3061,14 @@
"node": ">= 10.0.0"
}
},
"node_modules/electron-log": {
"version": "5.4.3",
"resolved": "https://registry.npmjs.org/electron-log/-/electron-log-5.4.3.tgz",
"integrity": "sha512-sOUsM3LjZdugatazSQ/XTyNcw8dfvH1SYhXWiJyfYodAAKOZdHs0txPiLDXFzOZbhXgAgshQkshH2ccq0feyLQ==",
"engines": {
"node": ">= 14"
}
},
"node_modules/electron-publish": {
"version": "24.13.1",
"resolved": "https://registry.npmjs.org/electron-publish/-/electron-publish-24.13.1.tgz",
@@ -3914,15 +3937,18 @@
}
},
"node_modules/iconv-lite": {
"version": "0.6.3",
"resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.6.3.tgz",
"integrity": "sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw==",
"dev": true,
"version": "0.7.0",
"resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.7.0.tgz",
"integrity": "sha512-cf6L2Ds3h57VVmkZe+Pn+5APsT7FpqJtEhhieDCvrE2MK5Qk9MyffgQyuxQTm6BChfeZNtcOLHp9IcWRVcIcBQ==",
"dependencies": {
"safer-buffer": ">= 2.1.2 < 3.0.0"
},
"engines": {
"node": ">=0.10.0"
},
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/express"
}
},
"node_modules/ieee754": {
@@ -4149,6 +4175,15 @@
"json-buffer": "3.0.1"
}
},
"node_modules/koffi": {
"version": "2.14.1",
"resolved": "https://registry.npmjs.org/koffi/-/koffi-2.14.1.tgz",
"integrity": "sha512-IMFL3IbRDXacSIjs7pPbPxgNlJ2hUtawQXU2QPdr6iw38jmv5AesAUG8HPX00xl0PPA2BbEa3noTw1YdHY+gHg==",
"hasInstallScript": true,
"funding": {
"url": "https://buymeacoffee.com/koromix"
}
},
"node_modules/lazy-val": {
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/lazy-val/-/lazy-val-1.0.5.tgz",
@@ -5035,8 +5070,7 @@
"node_modules/safer-buffer": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz",
"integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==",
"dev": true
"integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg=="
},
"node_modules/sanitize-filename": {
"version": "1.6.3",
@@ -8134,6 +8168,15 @@
"universalify": "^2.0.0"
}
},
"iconv-lite": {
"version": "0.6.3",
"resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.6.3.tgz",
"integrity": "sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw==",
"dev": true,
"requires": {
"safer-buffer": ">= 2.1.2 < 3.0.0"
}
},
"jsonfile": {
"version": "6.2.0",
"resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.2.0.tgz",
@@ -8324,6 +8367,11 @@
}
}
},
"electron-log": {
"version": "5.4.3",
"resolved": "https://registry.npmjs.org/electron-log/-/electron-log-5.4.3.tgz",
"integrity": "sha512-sOUsM3LjZdugatazSQ/XTyNcw8dfvH1SYhXWiJyfYodAAKOZdHs0txPiLDXFzOZbhXgAgshQkshH2ccq0feyLQ=="
},
"electron-publish": {
"version": "24.13.1",
"resolved": "https://registry.npmjs.org/electron-publish/-/electron-publish-24.13.1.tgz",
@@ -8965,10 +9013,9 @@
}
},
"iconv-lite": {
"version": "0.6.3",
"resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.6.3.tgz",
"integrity": "sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw==",
"dev": true,
"version": "0.7.0",
"resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.7.0.tgz",
"integrity": "sha512-cf6L2Ds3h57VVmkZe+Pn+5APsT7FpqJtEhhieDCvrE2MK5Qk9MyffgQyuxQTm6BChfeZNtcOLHp9IcWRVcIcBQ==",
"requires": {
"safer-buffer": ">= 2.1.2 < 3.0.0"
}
@@ -9141,6 +9188,11 @@
"json-buffer": "3.0.1"
}
},
"koffi": {
"version": "2.14.1",
"resolved": "https://registry.npmjs.org/koffi/-/koffi-2.14.1.tgz",
"integrity": "sha512-IMFL3IbRDXacSIjs7pPbPxgNlJ2hUtawQXU2QPdr6iw38jmv5AesAUG8HPX00xl0PPA2BbEa3noTw1YdHY+gHg=="
},
"lazy-val": {
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/lazy-val/-/lazy-val-1.0.5.tgz",
@@ -9792,8 +9844,7 @@
"safer-buffer": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz",
"integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==",
"dev": true
"integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg=="
},
"sanitize-filename": {
"version": "1.6.3",

View File

@@ -7,13 +7,18 @@
"dev": "concurrently \"vite\" \"wait-on tcp:5173 && electron .\"",
"build": "vite build",
"pack": "npm run build && electron-builder --dir",
"pack:ia32": "npm run build && electron-builder --dir --ia32",
"dist": "npm run build && electron-builder",
"dist:ia32": "npm run build && electron-builder --ia32",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"electron-log": "^5.4.3",
"iconv-lite": "^0.7.0",
"koffi": "^2.14.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-pdf": "5.7.2",
@@ -41,6 +46,12 @@
"dist/**/*",
"electron/**/*"
],
"extraResources": [
{
"from": "resources/xzx",
"to": "xzx"
}
],
"win": {
"target": [
"nsis",

File diff suppressed because one or more lines are too long

View File

@@ -7,6 +7,9 @@ files:
- filter:
- dist/**/*
- electron/**/*
extraResources:
- from: resources/xzx
to: xzx
win:
target:
- nsis

View File

@@ -1,21 +0,0 @@
Copyright (c) Electron contributors
Copyright (c) 2013-2020 GitHub Inc.
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

File diff suppressed because it is too large Load Diff

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -1 +0,0 @@
{"file_format_version": "1.0.0", "ICD": {"library_path": ".\\vk_swiftshader.dll", "api_version": "1.0.5"}}

Binary file not shown.

7
resources/xzx/Config.ini Normal file
View File

@@ -0,0 +1,7 @@
[ReadCardConfig]
PortType=USB
Port=1001
BaudRate=115200
AutoPrint=false
MakePhotoById=false
BandRate=115200

View File

@@ -0,0 +1 @@
d8838bccad0c19e847b9e73f4432b951b6f035fd8c19f5474e30db5a0e4fa4c99b57c01af79161850b95d3f99a6b0b6074f18224ec7c44f28bc243be06f8f2b96e370f5ca724c01f1bd0e289afdd9eeef7e33d42a5113ddd4818a47b33449487baec2099a50d5e3dde32bdf66d979982a68d0d60a1200990ebf8a4827b7db3d1e83f9ad9d9946267fe830c48bbe025a5ebb99b85c7f1cf93de2beb22c8e9766e5ef526242b01f5251d8a768780026add2d2d8fb9ffccb86f8779221b01d206e586d96b83839b30006910a4bca6438fb5d5b2900431f8ecab50a9f18d0e7e8abec7b212fdc9ab667f08dd3eef14ecbdb24910466f45be92d0a085ff81d7362b828847c29be579942b63b9eb26b2441b5ef20f5a012431d263ded3f5fe434111b833612464bf4df18ae06c536b6895d240387774c3b438d5f0745c7a0d3ce963e82fc8df603f6fa526e8bd1fc51e2509e0840f3bbbde7bc3fec9e837b5aa744a9ae4449c974e26d787e475f73dbc3ee9c73cc258f38b79c413453fd4fe732bed57ba9d0312d2bcaf333a5c82d92a269a7ccaf27273a178feb95028f8f0805675a6199abbd8b47756b4543269a35025438794cd32410ac19c77526c4b94b93d091069056df1dda0f49298d753a317850c7104f94067ac9cc4d5b3d377f10627d21c12a4c066347eb05370fbe9e0658c1ec1803d43ed71509f5cdb25d60f505ef7527c405d3ea05bb381436dd3622484a1ff7263e4d93f275493332af3f77d28a13a0fa0eb810b7d25a378f6b8313ab3bcb44131ca3500670b0321aa95b077cef85d348e13315c2d2d42795e41569162986755709d099b59ee320e6caf422497234251d07d697bb3f3e5ad6d15d80fd85da016e7075bf84522aa6339e8b66ecd4b71d02fd01f4f57a0147ceaddbf9e5f32e7ec60ae35ff73d2f386d9d0133cb697731773b55fc2615c584e9f4013253d3fc53fa13a9e982a2493e1145861759c30cf9064d333bb184e378b52e7dd8bbbd0c17774549fabb44014dab2e0a903c53d0da1c9d3a223c69f3b9bcc7925ba21a464fc9fa43e20574ffedb7a27f2cd7ae7b6b46c5cb4e0b176ece7d59ff199b74b3436ead185df5c79d74b35d644bb02315130131772db21fcd1d535014b10c4cbbb8e1f847cd00be52992ab94a7b5a7b1c27d87abe3fc605972ceb3463a07924c816a04642adcabbc7b18a40a24a3af217d0390c1102cb5b4573b1816c76667f50d33631a97e986255644e8e0c26d63cd1f29f501ff51673509822c1bf8158ceee752024dcbe0e24941803ebd8afc0bded3598012ba5431060f0db7fad7fd4960972da9a6cfaa0850c43470498236ef7b22fbf79d491e054cf142815e6c04e573a52e22ccaa2d406167c6442db40456cd93752349b2968132388b51edbe13aa349abc34696453d1a4b39f8311284f8afbae

Binary file not shown.

BIN
resources/xzx/WltRS.dll Normal file

Binary file not shown.

BIN
resources/xzx/sdtapi.dll Normal file

Binary file not shown.

View File

@@ -18,46 +18,62 @@ const U1: React.FC = () => {
const handleStart = () => {
if (reading) return; // 避免重复点击
setReading(true);
// 启动后端监听
// invoke("start_idcard_listen").catch((e) => {
// console.error("start_idcard_listen failed", e);
// });
// 启动后端监听;如果启动失败立即恢复 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);
// invoke("stop_idcard_listen").catch(() => {});
}
console.warn("未在 6 秒内读取到身份证信息,恢复初始状态");
window.electronAPI.log(
"warn",
"未在 6 秒内读取到身份证信息,恢复初始状态"
);
setReading(false);
window.electronAPI.stopIdCardListen().catch(() => {});
timerRef.current = null;
}, 6000);
};
useEffect(() => {
if (!reading) return;
// let unlisten: (() => void) | null = null;
// (async () => {
// try {
// const off = await listen("idcard-data", (e) => {
// const payload: any = e.payload;
// console.log("[idcard-data]", payload);
// // 成功:清理定时器,停止监听,跳转并传递身份证号
// if (timerRef.current) {
// clearTimeout(timerRef.current);
// timerRef.current = null;
// }
// invoke("stop_idcard_listen").catch(() => {});
// setReading(false);
// navigate("/u2", {
// state: { idCardNo: payload?.id_card_no, cardData: payload },
// });
// });
// unlisten = off;
// } catch (err) {
// console.error("listen idcard-data failed", err);
// }
// })();
// 监听数据
window.electronAPI.onIdCardData((e: any) => {
const payload = e.payload;
console.log("[idcard-data]", payload);
window.electronAPI.log("info", `[idcard-data] received`);
window.electronAPI.log(
"info",
`Read IDCard success: ${payload.name} ${payload.id_card_no}`
);
// 成功:清理定时器,停止监听,跳转并传递身份证号
if (timerRef.current) {
clearTimeout(timerRef.current);
timerRef.current = null;
}
window.electronAPI.stopIdCardListen().catch(() => {});
setReading(false);
navigate("/u2", {
state: { idCardNo: payload?.id_card_no, cardData: payload },
});
});
// 监听错误 (可选)
window.electronAPI.onIdCardError((e: any) => {
console.error("[idcard-error]", e.payload);
window.electronAPI.log("error", `[idcard-error] ${e.payload}`);
});
return () => {
// if (unlisten) unlisten();
window.electronAPI.removeIdCardListeners();
};
}, [reading, navigate]);
@@ -66,7 +82,7 @@ const U1: React.FC = () => {
// 页面卸载时清理
if (timerRef.current) clearTimeout(timerRef.current);
timerRef.current = null;
// if (reading) invoke("stop_idcard_listen").catch(() => {});
if (reading) window.electronAPI.stopIdCardListen().catch(() => {});
};
}, [reading]);

11
src/vite-env.d.ts vendored
View File

@@ -1 +1,12 @@
/// <reference types="vite/client" />
interface Window {
electronAPI: {
startIdCardListen: () => Promise<any>;
stopIdCardListen: () => Promise<any>;
onIdCardData: (callback: (data: any) => void) => void;
onIdCardError: (callback: (error: any) => void) => void;
log: (level: string, message: any) => void;
removeIdCardListeners: () => void;
};
}