refactor: 修复深色模式背景色问题: 添加动态主题类管理,将深色背景改为纯黑色

This commit is contained in:
2025-09-18 16:42:52 +08:00
parent b4d1249684
commit a9ca94e2d6
2 changed files with 22 additions and 2 deletions

View File

@@ -1,4 +1,4 @@
import { StrictMode, useState, lazy, Suspense } from "react";
import { StrictMode, useState, lazy, Suspense, useEffect } from "react";
import { createRoot } from "react-dom/client";
import { BrowserRouter as Router, Routes, Route } from "react-router-dom";
import "./index.css";
@@ -29,6 +29,16 @@ export const AppContent = () => {
const enableVideoBackground = useConfigItem("enableVideoBackground");
const videoBackgroundUrl = useConfigItem("videoBackgroundUrl");
// 动态设置 HTML 根元素的 dark 类
useEffect(() => {
const htmlElement = document.documentElement;
if (appearance === "dark") {
htmlElement.classList.add("dark");
} else {
htmlElement.classList.remove("dark");
}
}, [appearance]);
return (
<>
{enableVideoBackground && videoBackgroundUrl && (