添加重启应用功能,支持通过触摸事件触发重启
This commit is contained in:
27
src/App.tsx
27
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<string>(() => formatDate(new Date()));
|
||||
const restartTimerRef = useRef<number | null>(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 (
|
||||
<div className="app-container">
|
||||
{/* 全局背景层 */}
|
||||
<div className="global-background">
|
||||
{/* 顶部固定区域 - 始终显示 */}
|
||||
<div className="global-header">
|
||||
<img className="header-logo" alt="logo" src={icon} />
|
||||
<img
|
||||
className="header-logo"
|
||||
alt="logo"
|
||||
src={icon}
|
||||
onMouseDown={handleTouchStart}
|
||||
onMouseUp={handleTouchEnd}
|
||||
onMouseLeave={handleTouchEnd}
|
||||
onTouchStart={handleTouchStart}
|
||||
onTouchEnd={handleTouchEnd}
|
||||
/>
|
||||
<span className="header-title">医疗自助服务系统</span>
|
||||
</div>
|
||||
<span className="header-time">{time}</span>
|
||||
|
||||
1
src/electron.d.ts
vendored
1
src/electron.d.ts
vendored
@@ -27,6 +27,7 @@ interface ElectronAPI {
|
||||
onIdCardError: (callback: (error: any) => void) => void;
|
||||
log: (level: string, message: any) => void;
|
||||
removeIdCardListeners: () => void;
|
||||
restartApp: () => void;
|
||||
}
|
||||
|
||||
interface Window {
|
||||
|
||||
Reference in New Issue
Block a user