From 48be5c104d56a8df310bfc648c0b2a882e4f0a5d Mon Sep 17 00:00:00 2001 From: Montia37 Date: Fri, 15 Aug 2025 21:34:42 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=B9=B6=E9=80=82?= =?UTF-8?q?=E9=85=8D=E6=89=8B=E6=9C=BA=E7=AB=AF=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- komari-theme.json | 4 +- src/components/sections/Header.tsx | 212 +++++++++++++++++++-------- src/components/sections/StatsBar.tsx | 191 ++++++++++++++---------- 3 files changed, 265 insertions(+), 142 deletions(-) diff --git a/komari-theme.json b/komari-theme.json index e463e1c..43e0d66 100644 --- a/komari-theme.json +++ b/komari-theme.json @@ -2,7 +2,7 @@ "name": "Komari Theme PurCart", "short": "PurCarte", "description": "A frosted glass theme for Komari", - "version": "1.0.1", + "version": "1.0.2", "author": "Montia & Gemini", "url": "https://github.com/Montia37/Komari-theme-purcarte", "preview": "preview.png", @@ -62,7 +62,7 @@ }, { "key": "enableSearchButton", - "name": "启用标题栏按钮", + "name": "启用搜索按钮", "type": "switch", "default": true, "help": "启用后默认在标题栏右侧显示搜索按钮" diff --git a/src/components/sections/Header.tsx b/src/components/sections/Header.tsx index b13ab30..cb2452e 100644 --- a/src/components/sections/Header.tsx +++ b/src/components/sections/Header.tsx @@ -7,11 +7,18 @@ import { Moon, Sun, CircleUserIcon, + Menu, } from "lucide-react"; import { useEffect, useState } from "react"; import { useLocation } from "react-router-dom"; import { useIsMobile } from "@/hooks/useMobile"; import { useConfigItem } from "@/config"; +import { + DropdownMenu, + DropdownMenuContent, + DropdownMenuItem, + DropdownMenuTrigger, +} from "@/components/ui/dropdown-menu"; interface HeaderProps { viewMode: "grid" | "table"; @@ -55,9 +62,7 @@ export const Header = ({ {enableLogo && logoUrl && ( logo )} - {enableTitle && ( - {sitename} - )} + {enableTitle && {sitename}}
@@ -65,73 +70,154 @@ export const Header = ({ <> {isMobile ? ( <> - {isSearchOpen && ( -
- ) => - setSearchTerm(e.target.value) - } - /> -
+
+ ) => + setSearchTerm(e.target.value) + } + /> +
+ {enableSearchButton && ( + )} + + + + + + + setViewMode(viewMode === "grid" ? "table" : "grid") + }> + {viewMode === "grid" ? ( + + ) : ( + + )} + + {viewMode === "grid" ? "表格视图" : "网格视图"} + + + + {theme === "dark" ? ( + + ) : ( + + )} + + {theme === "dark" ? "浅色模式" : "深色模式"} + + + {enableAdminButton && ( + + + + 管理员 + + + )} + + ) : ( -
- ) => - setSearchTerm(e.target.value) - } - /> -
+ <> +
+ ) => + setSearchTerm(e.target.value) + } + /> +
+ {enableSearchButton && ( + + )} + + + {enableAdminButton && ( + + + + )} + )} - {enableSearchButton && ( - - )} - )} - - {enableAdminButton && ( - - - + {enableAdminButton && ( + + + + )} + )}
diff --git a/src/components/sections/StatsBar.tsx b/src/components/sections/StatsBar.tsx index f707ad2..139bfca 100644 --- a/src/components/sections/StatsBar.tsx +++ b/src/components/sections/StatsBar.tsx @@ -10,6 +10,7 @@ import { Settings2 } from "lucide-react"; import { Switch } from "@/components/ui/switch"; import { Button } from "@/components/ui/button"; import { formatBytes } from "@/utils"; +import { useIsMobile } from "@/hooks/useMobile"; interface StatsBarProps { displayOptions: { @@ -40,8 +41,115 @@ export const StatsBar = ({ loading, currentTime, }: StatsBarProps) => { + const isMobile = useIsMobile(); + + // 获取已启用的统计项列表 + const enabledStats = Object.keys(displayOptions).filter( + (key) => displayOptions[key as keyof typeof displayOptions] + ); + + // 渲染统计项 + const renderStatItem = (key: string) => { + switch (key) { + case "time": + return ( + displayOptions.time && ( +
+
+ + +
+
+ ) + ); + case "online": + return ( + displayOptions.online && ( +
+
+ + +
+
+ ) + ); + case "regions": + return ( + displayOptions.regions && ( +
+
+ + +
+
+ ) + ); + case "traffic": + return ( + displayOptions.traffic && ( +
+
+ +
+ {loading ? ( + "..." + ) : ( +
+ {`↑ ${formatBytes(stats.totalTrafficUp)}`} + {`↓ ${formatBytes(stats.totalTrafficDown)}`} +
+ )} +
+
+
+ ) + ); + case "speed": + return ( + displayOptions.speed && ( +
+
+ +
+ {loading ? ( + "..." + ) : ( +
+ {`↑ ${formatBytes(stats.currentSpeedUp)}/s`} + {`↓ ${formatBytes( + stats.currentSpeedDown + )}/s`} +
+ )} +
+
+
+ ) + ); + default: + return null; + } + }; return ( -
+
@@ -101,85 +209,14 @@ export const StatsBar = ({
- {displayOptions.time && ( -
-
- - -
-
- )} - {displayOptions.online && ( -
-
- - -
-
- )} - {displayOptions.regions && ( -
-
- - -
-
- )} - {displayOptions.traffic && ( -
-
- -
- {loading ? ( - "..." - ) : ( -
- {`↑ ${formatBytes(stats.totalTrafficUp)}`} - {`↓ ${formatBytes(stats.totalTrafficDown)}`} -
- )} -
-
-
- )} - {displayOptions.speed && ( -
-
- -
- {loading ? ( - "..." - ) : ( -
- {`↑ ${formatBytes(stats.currentSpeedUp)}/s`} - {`↓ ${formatBytes(stats.currentSpeedDown)}/s`} -
- )} -
-
-
- )} + {enabledStats.map((key) => renderStatItem(key))}
);