mirror of
https://github.com/fankes/komari-theme-purcarte.git
synced 2025-10-19 11:59:21 +08:00
refactor: 修复深色模式背景色问题: 添加动态主题类管理,将深色背景改为纯黑色
This commit is contained in:
12
src/main.tsx
12
src/main.tsx
@@ -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 && (
|
||||
|
Reference in New Issue
Block a user