'use client'; import { Separator } from '@nice/ui/components/separator'; import { SidebarTrigger } from '@nice/ui/components/sidebar'; import { IconCalendar } from '@tabler/icons-react'; import { cn } from '@nice/ui/lib/utils'; import { useState, useEffect } from 'react'; import { useDashboard } from './providers/dashboard-provider'; // 页面信息接口 export interface PageInfo { title: string; subtitle?: string; rightContent?: React.ReactNode; } // 组件属性接口 export interface SiteHeaderProps { pageInfo?: PageInfo; showDate?: boolean; rightContent?: React.ReactNode; className?: string; useContext?: boolean; // 新增:是否使用 context 中的页面信息 } // 格式化日期 const formatDate = (date: Date) => { return date.toLocaleDateString('zh-CN', { year: 'numeric', month: 'long', day: 'numeric', }); }; // 默认时间显示组件 const DefaultTimeDisplay = () => { const [currentDate, setCurrentDate] = useState(null); useEffect(() => { // 只在客户端设置当前时间 setCurrentDate(new Date()); }, []); // 在水合完成之前显示占位符 if (!currentDate) { return (
); } return (
); }; // 页面标题区域组件 const PageTitleSection = ({ pageInfo }: { pageInfo: PageInfo }) => { return (

{pageInfo.title}

{pageInfo.subtitle && ( <> ·

{pageInfo.subtitle}

)}
); }; // 主组件 export function SiteHeader() { const {Dashboard}=useDashboard() return (
{/* 侧边栏触发器 */} {/* 页面标题区域 */} {/* 右侧内容区域 */}
{Dashboard.pageInfo?.rightContent || }
); }