2026-03-31 18:52:37 +08:00
|
|
|
/* ============================================================
|
|
|
|
|
SYSTEM PAGE — Settings
|
|
|
|
|
Design: Reference luxsin_x8_设置.png
|
|
|
|
|
Sections:
|
|
|
|
|
- 显示: 屏幕亮度, 自动锁屏, 旋钮亮度, 旋钮熄屏呼吸灯
|
|
|
|
|
- 通用: 语言, 自动返回首页, 休眠
|
|
|
|
|
- 声音: 开机提示音
|
|
|
|
|
- 关于: 设备名, 固件版本, MAC
|
|
|
|
|
All list rows with options → navigate to /select page
|
|
|
|
|
============================================================ */
|
|
|
|
|
import { useDevice } from "@/contexts/DeviceContext";
|
|
|
|
|
import { ChevronLeft, ChevronRight } from "lucide-react";
|
|
|
|
|
import { useLocation } from "wouter";
|
|
|
|
|
import { useEffect } from "react";
|
|
|
|
|
import BottomNav from "@/components/BottomNav";
|
|
|
|
|
import { navigateToSelect } from "./SelectPage";
|
2026-05-27 15:10:04 +08:00
|
|
|
import { formatFirmwareVersionDisplay } from "@/lib/luxsinApi";
|
2026-04-14 16:33:52 +08:00
|
|
|
import localeZh from "@/locales/data-zh.json";
|
|
|
|
|
import localeZhHK from "@/locales/data-zh-HK.json";
|
|
|
|
|
import localeEn from "@/locales/data-en.json";
|
2026-03-31 18:52:37 +08:00
|
|
|
|
|
|
|
|
function IOSToggle({ checked, onChange }: { checked: boolean; onChange: (v: boolean) => void }) {
|
|
|
|
|
return (
|
|
|
|
|
<label className="ios-toggle" onClick={(e) => e.stopPropagation()}>
|
|
|
|
|
<input type="checkbox" checked={checked} onChange={(e) => onChange(e.target.checked)} />
|
|
|
|
|
<span className="ios-toggle-track"><span className="ios-toggle-thumb" /></span>
|
|
|
|
|
</label>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function SectionHeader({ title }: { title: string }) {
|
|
|
|
|
return (
|
|
|
|
|
<div className="px-1 pt-5 pb-2">
|
|
|
|
|
<span className="text-[14px] font-semibold" style={{ color: "#00FFF6" }}>{title}</span>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function ListRow({ label, description, value, onClick, toggle, checked, onToggle }: {
|
|
|
|
|
label: string; description?: string; value?: string;
|
|
|
|
|
onClick?: () => void; toggle?: boolean; checked?: boolean; onToggle?: (v: boolean) => void;
|
|
|
|
|
}) {
|
|
|
|
|
if (toggle) {
|
|
|
|
|
return (
|
|
|
|
|
<div className="ios-list-row">
|
|
|
|
|
<div className="flex-1 min-w-0">
|
|
|
|
|
<div className="text-[16px] text-white">{label}</div>
|
|
|
|
|
{description && <div className="text-[12px] text-white/35 mt-0.5">{description}</div>}
|
|
|
|
|
</div>
|
|
|
|
|
<IOSToggle checked={!!checked} onChange={onToggle ?? (() => {})} />
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
return (
|
|
|
|
|
<button className="ios-list-row w-full text-left active:bg-white/5 transition-colors" onClick={onClick}>
|
|
|
|
|
<div className="flex-1 min-w-0">
|
|
|
|
|
<div className="text-[16px] text-white">{label}</div>
|
|
|
|
|
{description && <div className="text-[12px] text-white/35 mt-0.5">{description}</div>}
|
|
|
|
|
</div>
|
|
|
|
|
<div className="flex items-center gap-1">
|
|
|
|
|
{value && <span className="ios-row-value">{value}</span>}
|
|
|
|
|
<ChevronRight size={16} className="ios-chevron ml-1" />
|
|
|
|
|
</div>
|
|
|
|
|
</button>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-14 16:33:52 +08:00
|
|
|
type LocaleSettings = {
|
|
|
|
|
settings: {
|
|
|
|
|
vu: string;
|
2026-05-13 17:42:26 +08:00
|
|
|
vuMeter?: string;
|
2026-04-14 16:33:52 +08:00
|
|
|
screenBrightness: { label: string; options: Array<{ index: number; label: string }> };
|
|
|
|
|
turnOffScreen: { label: string; options: Array<{ index: number; label: string }> };
|
|
|
|
|
knobBrightness: { label: string; options: Array<{ index: number; label: string }> };
|
|
|
|
|
buttonLight: { label: string; options: Array<{ index: number; label: string }> };
|
|
|
|
|
language: { label: string; options: Array<{ index: number; label: string }> };
|
|
|
|
|
Automatic: { label: string; options: Array<{ index: number; label: string }> };
|
|
|
|
|
sleepTime?: { label: string; options: Array<{ index: number; label: string }> };
|
|
|
|
|
sleep?: { label: string; options: Array<{ index: number; label: string }> };
|
2026-05-13 17:42:26 +08:00
|
|
|
systemPage: {
|
|
|
|
|
sectionDisplay: string;
|
|
|
|
|
sectionGeneral: string;
|
|
|
|
|
sectionAbout: string;
|
|
|
|
|
screenBrightnessDesc: string;
|
|
|
|
|
turnOffScreenDesc: string;
|
|
|
|
|
knobBrightnessDesc: string;
|
|
|
|
|
buttonLightDesc: string;
|
|
|
|
|
languageDesc: string;
|
|
|
|
|
automaticDesc: string;
|
|
|
|
|
sleepDesc: string;
|
|
|
|
|
deviceName: string;
|
|
|
|
|
firmwareVersion: string;
|
|
|
|
|
macAddress: string;
|
2026-05-22 15:54:11 +08:00
|
|
|
deviceIp: string;
|
2026-05-13 17:42:26 +08:00
|
|
|
};
|
2026-04-14 16:33:52 +08:00
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const LOCALE_BY_LANG: Record<number, LocaleSettings> = {
|
|
|
|
|
0: localeEn as LocaleSettings,
|
|
|
|
|
1: localeZhHK as LocaleSettings,
|
|
|
|
|
2: localeZh as LocaleSettings,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
function optionLabels(items: Array<{ index: number; label: string }> | undefined, fallback: string[]) {
|
|
|
|
|
if (!items || items.length === 0) return fallback;
|
|
|
|
|
const sorted = [...items].sort((a, b) => a.index - b.index);
|
|
|
|
|
return sorted.map((item) => item.label);
|
|
|
|
|
}
|
2026-03-31 18:52:37 +08:00
|
|
|
|
2026-05-25 16:30:40 +08:00
|
|
|
/** Device language index: 0=en, 1=zh-HK, 2=zh-CN */
|
|
|
|
|
const SUPPORTED_LANGUAGE_INDICES = new Set([0, 1, 2]);
|
|
|
|
|
|
|
|
|
|
function languageLabels(
|
|
|
|
|
items: Array<{ index: number; label: string }> | undefined,
|
|
|
|
|
fallback: string[],
|
|
|
|
|
) {
|
|
|
|
|
const filtered = (items ?? []).filter((o) => SUPPORTED_LANGUAGE_INDICES.has(o.index));
|
|
|
|
|
if (filtered.length === 0) return fallback;
|
|
|
|
|
return [...filtered].sort((a, b) => a.index - b.index).map((o) => o.label);
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-31 18:52:37 +08:00
|
|
|
export default function SystemPage() {
|
|
|
|
|
const [, setLocation] = useLocation();
|
2026-05-22 15:54:11 +08:00
|
|
|
const { deviceState, updateSetting, refresh, isConnected, api, ip } = useDevice();
|
2026-03-31 18:52:37 +08:00
|
|
|
const ds = deviceState;
|
|
|
|
|
|
|
|
|
|
// 页面加载且已连接时刷新数据
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
if (isConnected || api) {
|
|
|
|
|
refresh();
|
|
|
|
|
}
|
|
|
|
|
}, [isConnected, api]);
|
|
|
|
|
|
|
|
|
|
const screenLightIdx = ds?.screenLight ?? 1;
|
|
|
|
|
const buttonLightIdx = ds?.buttonLight ?? 1;
|
|
|
|
|
const screenOffIdx = ds?.screenOff ?? 2;
|
|
|
|
|
const sleepIdx = ds?.sleep ?? 0;
|
|
|
|
|
const autoHomeIdx = ds?.autoHome ?? 1;
|
2026-05-25 16:30:40 +08:00
|
|
|
const rawLangIdx = ds?.language ?? 2;
|
|
|
|
|
const langIdx = SUPPORTED_LANGUAGE_INDICES.has(rawLangIdx) ? rawLangIdx : 2;
|
2026-03-31 18:52:37 +08:00
|
|
|
const knobBreathLightOn = (ds?.knob_breathlight ?? 1) === 0;
|
2026-04-14 16:33:52 +08:00
|
|
|
const localeData = LOCALE_BY_LANG[langIdx] ?? localeZh;
|
|
|
|
|
const settingsText = localeData.settings;
|
2026-05-13 17:42:26 +08:00
|
|
|
const ui = settingsText.systemPage;
|
2026-04-14 16:33:52 +08:00
|
|
|
const SCREEN_LIGHT_OPTIONS = optionLabels(settingsText.screenBrightness?.options, ["亮", "中等", "暗"]);
|
|
|
|
|
const KNOB_LIGHT_OPTIONS = optionLabels(settingsText.knobBrightness?.options, ["关闭", "亮", "中等", "暗"]);
|
|
|
|
|
const SCREEN_OFF_OPTIONS = optionLabels(settingsText.turnOffScreen?.options, ["常亮", "30秒", "1分钟", "3分钟", "5分钟"]);
|
|
|
|
|
const SLEEP_OPTIONS = optionLabels(settingsText.sleepTime?.options ?? settingsText.sleep?.options, ["关闭", "1分钟", "5分钟", "10分钟"]);
|
|
|
|
|
const AUTO_HOME_OPTIONS = optionLabels(settingsText.Automatic?.options, ["关闭", "20秒", "40秒", "60秒"]);
|
2026-05-25 16:30:40 +08:00
|
|
|
const LANG_OPTIONS = languageLabels(settingsText.language?.options, [
|
|
|
|
|
"English",
|
|
|
|
|
"繁體中文",
|
|
|
|
|
"简体中文",
|
|
|
|
|
]);
|
2026-03-31 18:52:37 +08:00
|
|
|
|
2026-05-13 17:42:26 +08:00
|
|
|
const sleepRowLabel =
|
|
|
|
|
settingsText.sleepTime?.label ??
|
|
|
|
|
settingsText.sleep?.label ??
|
|
|
|
|
(localeEn as LocaleSettings).settings.sleep?.label ??
|
|
|
|
|
"Sleep";
|
|
|
|
|
|
2026-03-31 18:52:37 +08:00
|
|
|
const goSelect = (title: string, options: string[], selected: number, key: string) => {
|
|
|
|
|
navigateToSelect(title, options, selected, "/system", key);
|
|
|
|
|
setLocation("/select");
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className="min-h-screen bg-black">
|
|
|
|
|
<div className="page-header">
|
|
|
|
|
<button onClick={() => setLocation("/")} className="mr-4 text-white/60 active:text-white transition-colors">
|
|
|
|
|
<ChevronLeft size={24} />
|
|
|
|
|
</button>
|
2026-04-14 16:33:52 +08:00
|
|
|
<h1 className="flex-1 text-center text-[17px] font-semibold text-white">{settingsText.vu}</h1>
|
2026-03-31 18:52:37 +08:00
|
|
|
<div className="w-8" />
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div className="px-4 pb-32">
|
|
|
|
|
{/* ── 显示 ── */}
|
2026-05-13 17:42:26 +08:00
|
|
|
<SectionHeader title={ui.sectionDisplay} />
|
2026-03-31 18:52:37 +08:00
|
|
|
<div className="ios-list-group">
|
2026-05-13 17:42:26 +08:00
|
|
|
<ListRow label={settingsText.screenBrightness.label} description={ui.screenBrightnessDesc}
|
2026-03-31 18:52:37 +08:00
|
|
|
value={SCREEN_LIGHT_OPTIONS[screenLightIdx]}
|
2026-04-14 16:33:52 +08:00
|
|
|
onClick={() => goSelect(settingsText.screenBrightness.label, SCREEN_LIGHT_OPTIONS, screenLightIdx, "screenLight")} />
|
2026-05-13 17:42:26 +08:00
|
|
|
<ListRow label={settingsText.turnOffScreen.label} description={ui.turnOffScreenDesc}
|
2026-03-31 18:52:37 +08:00
|
|
|
value={SCREEN_OFF_OPTIONS[screenOffIdx]}
|
2026-04-14 16:33:52 +08:00
|
|
|
onClick={() => goSelect(settingsText.turnOffScreen.label, SCREEN_OFF_OPTIONS, screenOffIdx, "screenOff")} />
|
2026-05-13 17:42:26 +08:00
|
|
|
<ListRow label={settingsText.knobBrightness.label} description={ui.knobBrightnessDesc}
|
2026-03-31 18:52:37 +08:00
|
|
|
value={KNOB_LIGHT_OPTIONS[buttonLightIdx]}
|
2026-04-14 16:33:52 +08:00
|
|
|
onClick={() => goSelect(settingsText.knobBrightness.label, KNOB_LIGHT_OPTIONS, buttonLightIdx, "buttonLight")} />
|
2026-05-13 17:42:26 +08:00
|
|
|
<ListRow label={settingsText.buttonLight.label} description={ui.buttonLightDesc}
|
2026-03-31 18:52:37 +08:00
|
|
|
toggle checked={knobBreathLightOn}
|
|
|
|
|
onToggle={(v) => updateSetting({ knob_breathlight: v ? 0 : 1 })} />
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{/* ── 通用 ── */}
|
2026-05-13 17:42:26 +08:00
|
|
|
<SectionHeader title={ui.sectionGeneral} />
|
2026-03-31 18:52:37 +08:00
|
|
|
<div className="ios-list-group">
|
2026-05-13 17:42:26 +08:00
|
|
|
<ListRow label={settingsText.language.label} description={ui.languageDesc}
|
2026-03-31 18:52:37 +08:00
|
|
|
value={LANG_OPTIONS[langIdx]}
|
2026-04-14 16:33:52 +08:00
|
|
|
onClick={() => goSelect(settingsText.language.label, LANG_OPTIONS, langIdx, "language")} />
|
2026-05-13 17:42:26 +08:00
|
|
|
<ListRow label={settingsText.Automatic.label} description={ui.automaticDesc}
|
2026-03-31 18:52:37 +08:00
|
|
|
value={AUTO_HOME_OPTIONS[autoHomeIdx]}
|
2026-04-14 16:33:52 +08:00
|
|
|
onClick={() => goSelect(settingsText.Automatic.label, AUTO_HOME_OPTIONS, autoHomeIdx, "autoHome")} />
|
2026-05-13 17:42:26 +08:00
|
|
|
<ListRow label={sleepRowLabel} description={ui.sleepDesc}
|
2026-03-31 18:52:37 +08:00
|
|
|
value={SLEEP_OPTIONS[sleepIdx]}
|
2026-05-13 17:42:26 +08:00
|
|
|
onClick={() => goSelect(sleepRowLabel, SLEEP_OPTIONS, sleepIdx, "sleep")} />
|
2026-03-31 18:52:37 +08:00
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{/* ── 关于 ── */}
|
2026-05-13 17:42:26 +08:00
|
|
|
<SectionHeader title={ui.sectionAbout} />
|
2026-03-31 18:52:37 +08:00
|
|
|
<div className="ios-list-group">
|
|
|
|
|
<div className="ios-list-row">
|
2026-05-13 17:42:26 +08:00
|
|
|
<span className="flex-1 text-[16px] text-white">{ui.deviceName}</span>
|
2026-03-31 18:52:37 +08:00
|
|
|
<span className="ios-row-value">{ds?.device ?? "Luxsin X9"}</span>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="ios-list-row">
|
2026-05-13 17:42:26 +08:00
|
|
|
<span className="flex-1 text-[16px] text-white">{ui.firmwareVersion}</span>
|
2026-05-27 15:10:04 +08:00
|
|
|
<span className="ios-row-value">{formatFirmwareVersionDisplay(ds?.version)}</span>
|
2026-03-31 18:52:37 +08:00
|
|
|
</div>
|
|
|
|
|
<div className="ios-list-row">
|
2026-05-13 17:42:26 +08:00
|
|
|
<span className="flex-1 text-[16px] text-white">{ui.macAddress}</span>
|
2026-03-31 18:52:37 +08:00
|
|
|
<span className="ios-row-value text-[12px]">{ds?.mac ?? "—"}</span>
|
|
|
|
|
</div>
|
2026-05-22 15:54:11 +08:00
|
|
|
<div className="ios-list-row">
|
|
|
|
|
<span className="flex-1 text-[16px] text-white">{ui.deviceIp ?? "设备 IP"}</span>
|
|
|
|
|
<span className="ios-row-value text-[12px]">{ip || "—"}</span>
|
|
|
|
|
</div>
|
2026-03-31 18:52:37 +08:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<BottomNav />
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|