|
1 | 1 | import { useState } from "react"; |
2 | | -import { Settings, Database, Key, Info } from "lucide-react"; |
| 2 | +import { useTranslation } from "react-i18next"; |
| 3 | +import { Settings, Database, Key, Info, ChevronDown } from "lucide-react"; |
3 | 4 | import { cn } from "@/lib/utils"; |
4 | 5 |
|
5 | 6 | type SettingsSection = "general" | "storage" | "api" | "about"; |
6 | 7 |
|
7 | | -const settingsSections = [ |
8 | | - { id: "general" as SettingsSection, icon: Settings, label: "通用设置" }, |
9 | | - { id: "storage" as SettingsSection, icon: Database, label: "数据存储" }, |
10 | | - { id: "api" as SettingsSection, icon: Key, label: "API 密钥" }, |
11 | | - { id: "about" as SettingsSection, icon: Info, label: "关于" }, |
| 8 | +const languages = [ |
| 9 | + { code: "zh-CN", label: "简体中文" }, |
| 10 | + { code: "en", label: "English" }, |
12 | 11 | ]; |
13 | 12 |
|
14 | 13 | function SettingsPage() { |
| 14 | + const { t, i18n } = useTranslation(); |
15 | 15 | const [activeSection, setActiveSection] = useState<SettingsSection>("general"); |
| 16 | + const [languageOpen, setLanguageOpen] = useState(false); |
| 17 | + |
| 18 | + const settingsSections = [ |
| 19 | + { id: "general" as SettingsSection, icon: Settings, label: t("settings.general") }, |
| 20 | + { id: "storage" as SettingsSection, icon: Database, label: t("settings.storage", "数据存储") }, |
| 21 | + { id: "api" as SettingsSection, icon: Key, label: t("settings.apiKeys", "API 密钥") }, |
| 22 | + { id: "about" as SettingsSection, icon: Info, label: t("settings.about") }, |
| 23 | + ]; |
| 24 | + |
| 25 | + const currentLanguage = languages.find((l) => l.code === i18n.language) || languages[0]; |
| 26 | + |
| 27 | + const handleLanguageChange = (code: string) => { |
| 28 | + i18n.changeLanguage(code); |
| 29 | + setLanguageOpen(false); |
| 30 | + }; |
| 31 | + |
| 32 | + const renderGeneralSettings = () => ( |
| 33 | + <div className="space-y-6"> |
| 34 | + {/* Language Setting */} |
| 35 | + <div className="flex items-center justify-between"> |
| 36 | + <div> |
| 37 | + <div className="text-sm font-medium text-[var(--text-primary)]"> |
| 38 | + {t("settings.language")} |
| 39 | + </div> |
| 40 | + <div className="text-xs text-[var(--text-muted)] mt-0.5"> |
| 41 | + {t("settings.languageDesc", "选择界面显示语言")} |
| 42 | + </div> |
| 43 | + </div> |
| 44 | + <div className="relative"> |
| 45 | + <button |
| 46 | + onClick={() => setLanguageOpen(!languageOpen)} |
| 47 | + className="flex items-center gap-2 px-3 py-1.5 bg-[var(--bg-tertiary)] rounded-lg text-sm text-[var(--text-primary)] hover:bg-[var(--border-light)] transition-colors" |
| 48 | + > |
| 49 | + {currentLanguage.label} |
| 50 | + <ChevronDown className={cn("w-4 h-4 transition-transform", languageOpen && "rotate-180")} /> |
| 51 | + </button> |
| 52 | + {languageOpen && ( |
| 53 | + <div className="absolute right-0 mt-1 w-32 bg-[var(--bg-card)] border border-[var(--border-light)] rounded-lg shadow-lg overflow-hidden z-10"> |
| 54 | + {languages.map((lang) => ( |
| 55 | + <button |
| 56 | + key={lang.code} |
| 57 | + onClick={() => handleLanguageChange(lang.code)} |
| 58 | + className={cn( |
| 59 | + "w-full px-3 py-2 text-sm text-left hover:bg-[var(--bg-tertiary)] transition-colors", |
| 60 | + lang.code === i18n.language |
| 61 | + ? "text-[var(--accent-primary)] bg-[var(--bg-tertiary)]" |
| 62 | + : "text-[var(--text-primary)]" |
| 63 | + )} |
| 64 | + > |
| 65 | + {lang.label} |
| 66 | + </button> |
| 67 | + ))} |
| 68 | + </div> |
| 69 | + )} |
| 70 | + </div> |
| 71 | + </div> |
| 72 | + </div> |
| 73 | + ); |
| 74 | + |
| 75 | + const renderAboutSettings = () => ( |
| 76 | + <div className="space-y-4"> |
| 77 | + <div className="flex items-center justify-between"> |
| 78 | + <span className="text-sm text-[var(--text-secondary)]">{t("settings.version")}</span> |
| 79 | + <span className="text-sm text-[var(--text-primary)]">0.1.0</span> |
| 80 | + </div> |
| 81 | + <div className="flex items-center justify-between"> |
| 82 | + <span className="text-sm text-[var(--text-secondary)]">Electron</span> |
| 83 | + <span className="text-sm text-[var(--text-primary)]">35.x</span> |
| 84 | + </div> |
| 85 | + </div> |
| 86 | + ); |
| 87 | + |
| 88 | + const renderContent = () => { |
| 89 | + switch (activeSection) { |
| 90 | + case "general": |
| 91 | + return renderGeneralSettings(); |
| 92 | + case "about": |
| 93 | + return renderAboutSettings(); |
| 94 | + default: |
| 95 | + return ( |
| 96 | + <p className="text-[var(--text-muted)]"> |
| 97 | + {t("common.developingFeature", "功能开发中...")} |
| 98 | + </p> |
| 99 | + ); |
| 100 | + } |
| 101 | + }; |
16 | 102 |
|
17 | 103 | return ( |
18 | 104 | <div className="h-full flex"> |
19 | 105 | {/* Sidebar - Settings Nav */} |
20 | 106 | <div className="w-[260px] bg-[var(--bg-secondary)] border-r border-[var(--border-light)] flex flex-col"> |
21 | 107 | <div className="p-3 border-b border-[var(--border-light)]"> |
22 | | - <h2 className="text-sm font-medium text-[var(--text-primary)]">设置</h2> |
| 108 | + <h2 className="text-sm font-medium text-[var(--text-primary)]">{t("settings.title")}</h2> |
23 | 109 | </div> |
24 | 110 |
|
25 | 111 | <div className="flex-1 overflow-y-auto p-2"> |
@@ -53,7 +139,7 @@ function SettingsPage() { |
53 | 139 | </h1> |
54 | 140 |
|
55 | 141 | <div className="bg-[var(--bg-card)] rounded-lg border border-[var(--border-light)] p-4"> |
56 | | - <p className="text-[var(--text-muted)]">设置内容开发中...</p> |
| 142 | + {renderContent()} |
57 | 143 | </div> |
58 | 144 | </div> |
59 | 145 | </div> |
|
0 commit comments