From 34e9c583927d7b452fbf9cd4dec16b97179df1ca Mon Sep 17 00:00:00 2001 From: yuchenglong Date: Thu, 4 Dec 2025 13:50:20 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=87=8D=E5=90=AF=E5=BA=94?= =?UTF-8?q?=E7=94=A8=E5=8A=9F=E8=83=BD=EF=BC=8C=E6=94=AF=E6=8C=81=E9=80=9A?= =?UTF-8?q?=E8=BF=87=E8=A7=A6=E6=91=B8=E4=BA=8B=E4=BB=B6=E8=A7=A6=E5=8F=91?= =?UTF-8?q?=E9=87=8D=E5=90=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- electron/main.js | 5 +++++ electron/preload.js | 4 +++- src/App.tsx | 27 +++++++++++++++++++++++++-- src/electron.d.ts | 1 + 4 files changed, 34 insertions(+), 3 deletions(-) diff --git a/electron/main.js b/electron/main.js index 59f050d..8cc49f2 100644 --- a/electron/main.js +++ b/electron/main.js @@ -368,6 +368,11 @@ app.whenReady().then(() => { return "stopped"; }); + ipcMain.on("restart-app", () => { + app.relaunch(); + app.exit(0); + }); + app.on("activate", () => { if (BrowserWindow.getAllWindows().length === 0) { createWindow(); diff --git a/electron/preload.js b/electron/preload.js index 1965a88..ee1b5ab 100644 --- a/electron/preload.js +++ b/electron/preload.js @@ -4,7 +4,8 @@ contextBridge.exposeInMainWorld("electronAPI", { // 获取PDF(绕过CORS) fetchPdf: (pdfUrl) => ipcRenderer.invoke("fetch-pdf", pdfUrl), // 打印PDF - printPdf: (pdfUrl, options) => ipcRenderer.invoke("print-pdf", pdfUrl, options), + printPdf: (pdfUrl, options) => + ipcRenderer.invoke("print-pdf", pdfUrl, options), // 获取打印机列表 getPrinters: () => ipcRenderer.invoke("get-printers"), startIdCardListen: () => ipcRenderer.invoke("start_idcard_listen"), @@ -18,4 +19,5 @@ contextBridge.exposeInMainWorld("electronAPI", { ipcRenderer.removeAllListeners("idcard-data"); ipcRenderer.removeAllListeners("idcard-error"); }, + restartApp: () => ipcRenderer.send("restart-app"), }); diff --git a/src/App.tsx b/src/App.tsx index d4b605d..2be3291 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,5 +1,5 @@ import { Routes, Route } from "react-router-dom"; -import { useEffect, useState } from "react"; +import { useEffect, useState, useRef } from "react"; // import { listen } from "@tauri-apps/api/event"; import "./App.css"; import icon from "./assets/icon.png"; @@ -16,6 +16,7 @@ import UI81 from "./pages/UI81/UI81"; function App() { const [time, setTime] = useState(() => formatDate(new Date())); + const restartTimerRef = useRef(null); useEffect(() => { const id = setInterval(() => setTime(formatDate(new Date())), 1000); @@ -36,13 +37,35 @@ function App() { }; }, []); + const handleTouchStart = () => { + restartTimerRef.current = window.setTimeout(() => { + window.electronAPI.restartApp(); + }, 5000); + }; + + const handleTouchEnd = () => { + if (restartTimerRef.current) { + clearTimeout(restartTimerRef.current); + restartTimerRef.current = null; + } + }; + return (
{/* 全局背景层 */}
{/* 顶部固定区域 - 始终显示 */}
- logo + logo 医疗自助服务系统
{time} diff --git a/src/electron.d.ts b/src/electron.d.ts index 5661719..27ae0d3 100644 --- a/src/electron.d.ts +++ b/src/electron.d.ts @@ -27,6 +27,7 @@ interface ElectronAPI { onIdCardError: (callback: (error: any) => void) => void; log: (level: string, message: any) => void; removeIdCardListeners: () => void; + restartApp: () => void; } interface Window {