+
{theme === "light" ? lightIcon : theme === "dark" ? darkIcon : autoIcon}
);
diff --git a/ui/src/pages/admin/tabs/Setting.tsx b/ui/src/pages/admin/tabs/Setting.tsx
index 9cece976..33d3fe8a 100644
--- a/ui/src/pages/admin/tabs/Setting.tsx
+++ b/ui/src/pages/admin/tabs/Setting.tsx
@@ -157,6 +157,22 @@ export const Setting: React.FC
= (props) => {
+
+
+
+ prevValues.hideThemeSwitch !== currentValues.hideThemeSwitch}>
+ {({ getFieldValue }) =>
+ getFieldValue('hideThemeSwitch') ? (
+
+
+
+ ) : null
+ }
+
diff --git a/ui/src/utils/theme.ts b/ui/src/utils/theme.ts
index ca5197be..7ed83056 100644
--- a/ui/src/utils/theme.ts
+++ b/ui/src/utils/theme.ts
@@ -1,39 +1,47 @@
-export function decodeAuto() {
+export function decodeAuto(disableTimeBased: boolean = false) {
const d = new Date().getHours();
const night = d > 18 || d < 8;
if (typeof window == "undefined") {
+ // 服务端渲染时的逻辑
+ if (disableTimeBased) {
+ return "auto-light"; // 默认亮色
+ }
if (night) {
return "auto-dark";
} else {
return "auto-light";
}
}
- if (night || window.matchMedia("(prefers-color-scheme: dark)").matches) {
+
+ // 客户端逻辑
+ const systemPrefersDark = window.matchMedia("(prefers-color-scheme: dark)").matches;
+
+ if (disableTimeBased) {
+ // 仅跟随系统主题
+ return systemPrefersDark ? "auto-dark" : "auto-light";
+ }
+
+ // 时间或系统主题满足其一即使用暗色
+ if (night || systemPrefersDark) {
return "auto-dark";
} else {
return "auto-light";
}
}
-export const decodeTheme = (t: "auto" | "light" | "dark") => {
+export const decodeTheme = (t: "auto" | "light" | "dark", disableTimeBased: boolean = false) => {
if (t === "auto") {
- return decodeAuto();
+ return decodeAuto(disableTimeBased);
} else {
return t;
}
};
-export const applyTheme = (t: string, source: string, disableLog: boolean) => {
+export const applyTheme = (t: string) => {
if (t.includes("light")) {
const bodyEl = document.querySelector("body")!;
bodyEl.classList.toggle("dark-mode", false);
- if (!disableLog) {
- console.log(`[Apply Theme][${source}] ${t}`);
- }
} else {
const bodyEl = document.querySelector("body")!;
bodyEl.classList.toggle("dark-mode", true);
- if (!disableLog) {
- console.log(`[Apply Theme][${source}] ${t}`);
- }
}
};
export const initTheme = () => {