From 79e5035aa80e5a5772f72b1a1a065abef1a03eb3 Mon Sep 17 00:00:00 2001 From: Montia37 Date: Sun, 31 Aug 2025 11:17:45 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E7=B3=BB=E7=BB=9F?= =?UTF-8?q?=E5=9B=BE=E6=A0=87=E5=9C=86=E8=A7=92=E9=81=AE=E6=8C=A1=E9=97=AE?= =?UTF-8?q?=E9=A2=98=E5=92=8C=20StatsBar=20=E7=BB=84=E4=BB=B6=E6=97=B6?= =?UTF-8?q?=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/sections/NodeCard.tsx | 2 +- src/components/sections/StatsBar.tsx | 13 ++++++++++--- src/pages/Home.tsx | 2 -- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/components/sections/NodeCard.tsx b/src/components/sections/NodeCard.tsx index c06ceaa..8b97c2b 100644 --- a/src/components/sections/NodeCard.tsx +++ b/src/components/sections/NodeCard.tsx @@ -53,7 +53,7 @@ export const NodeCard = ({ node, enableSwap }: NodeCardProps) => { {node.os} {node.name} diff --git a/src/components/sections/StatsBar.tsx b/src/components/sections/StatsBar.tsx index 4b858d4..c166bdc 100644 --- a/src/components/sections/StatsBar.tsx +++ b/src/components/sections/StatsBar.tsx @@ -7,6 +7,7 @@ import { DropdownMenuTrigger, } from "@/components/ui/dropdown-menu"; import { Settings2 } from "lucide-react"; +import { useEffect, useState } from "react"; import { Switch } from "@/components/ui/switch"; import { Button } from "@/components/ui/button"; import { formatBytes } from "@/utils"; @@ -31,7 +32,6 @@ interface StatsBarProps { currentSpeedDown: number; }; loading: boolean; - currentTime: Date; } export const StatsBar = ({ @@ -39,9 +39,16 @@ export const StatsBar = ({ setDisplayOptions, stats, loading, - currentTime, }: StatsBarProps) => { const isMobile = useIsMobile(); + const [time, setTime] = useState(new Date()); + + useEffect(() => { + const timer = setInterval(() => { + setTime(new Date()); + }, 1000); + return () => clearInterval(timer); + }, []); // 获取已启用的统计项列表 const enabledStats = Object.keys(displayOptions).filter( @@ -60,7 +67,7 @@ export const StatsBar = ({ 当前时间 diff --git a/src/pages/Home.tsx b/src/pages/Home.tsx index 5f8b809..73f9690 100644 --- a/src/pages/Home.tsx +++ b/src/pages/Home.tsx @@ -27,7 +27,6 @@ const HomePage: React.FC = ({ viewMode, searchTerm }) => { traffic: true, speed: true, }); - const [currentTime] = useState(new Date()); const combinedNodes = useMemo(() => { if (!staticNodes) return []; @@ -88,7 +87,6 @@ const HomePage: React.FC = ({ viewMode, searchTerm }) => { setDisplayOptions={setDisplayOptions} stats={stats} loading={loading} - currentTime={currentTime} /> )}