From 5444e7a579e1c810ca5db22354d803a30952ff7e Mon Sep 17 00:00:00 2001 From: gaoziman <2942894660@qq.com> Date: Fri, 19 Dec 2025 13:57:22 +0800 Subject: [PATCH] =?UTF-8?q?feat(providers):=20=E6=B7=BB=E5=8A=A0=E5=85=A8?= =?UTF-8?q?=E5=B1=80=E8=AE=BE=E7=BD=AE=E6=8F=90=E4=BE=9B=E8=80=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增 SettingsProvider 组件用于管理全局设置状态 - 在 Layout 中集成 SettingsProvider - 应用启动时自动加载字体大小和主题设置 --- src/app/layout.tsx | 5 ++- src/components/providers/SettingsProvider.tsx | 32 +++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 src/components/providers/SettingsProvider.tsx diff --git a/src/app/layout.tsx b/src/app/layout.tsx index 4c8f0b3..5091443 100644 --- a/src/app/layout.tsx +++ b/src/app/layout.tsx @@ -1,5 +1,6 @@ import type { Metadata } from "next"; import "./globals.css"; +import { SettingsProvider } from "@/components/providers/SettingsProvider"; export const metadata: Metadata = { title: "cchcode - AI 智能助手", @@ -17,7 +18,9 @@ export default function RootLayout({ return ( - {children} + + {children} + ); diff --git a/src/components/providers/SettingsProvider.tsx b/src/components/providers/SettingsProvider.tsx new file mode 100644 index 0000000..c51f081 --- /dev/null +++ b/src/components/providers/SettingsProvider.tsx @@ -0,0 +1,32 @@ +'use client'; + +import { useEffect, type ReactNode } from 'react'; +import { useSettings } from '@/hooks/useSettings'; + +interface SettingsProviderProps { + children: ReactNode; +} + +export function SettingsProvider({ children }: SettingsProviderProps) { + const { settings, loading } = useSettings(); + + // 应用全局设置 + useEffect(() => { + if (!loading && settings) { + // 应用字体大小 + if (settings.fontSize) { + document.documentElement.style.setProperty( + '--font-size-base', + `${settings.fontSize}px` + ); + } + + // 应用主题 + if (settings.theme) { + document.documentElement.setAttribute('data-theme', settings.theme); + } + } + }, [settings, loading]); + + return <>{children}; +}