feat(providers): 添加全局设置提供者
- 新增 SettingsProvider 组件用于管理全局设置状态 - 在 Layout 中集成 SettingsProvider - 应用启动时自动加载字体大小和主题设置
This commit is contained in:
parent
29b2d99a82
commit
5444e7a579
@ -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 (
|
||||
<html lang="zh-CN">
|
||||
<body className="antialiased">
|
||||
<SettingsProvider>
|
||||
{children}
|
||||
</SettingsProvider>
|
||||
</body>
|
||||
</html>
|
||||
);
|
||||
|
||||
32
src/components/providers/SettingsProvider.tsx
Normal file
32
src/components/providers/SettingsProvider.tsx
Normal file
@ -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}</>;
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user