monitor-ai/src/app/client-layout.tsx

40 lines
1.2 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

'use client'
// src/app/client-layout.tsx — 客户端布局(登录页不显示 Sidebar/TopBar
import { usePathname } from 'next/navigation'
import { useEffect, useState } from 'react'
import Sidebar from '@/components/Sidebar'
import ThemeProvider from '@/components/ThemeProvider'
import TopBar from '@/components/TopBar'
interface User { username: string; display_name: string; role: string }
export default function ClientLayout({ children }: { children: React.ReactNode }) {
const pathname = usePathname()
const isLoginPage = pathname === '/login'
const [user, setUser] = useState<User | null>(null)
useEffect(() => {
if (isLoginPage) return
fetch('/api/auth/me')
.then(r => r.json())
.then(d => { if (d.user) setUser(d.user) })
.catch(() => {})
}, [isLoginPage])
if (isLoginPage) {
return <ThemeProvider>{children}</ThemeProvider>
}
return (
<ThemeProvider>
<div className="min-h-screen bg-slate-50 dark:bg-slate-950">
<Sidebar userRole={user?.role} />
<TopBar user={user} />
<main className="ml-60 pt-14 min-h-screen">
<div className="p-6">{children}</div>
</main>
</div>
</ThemeProvider>
)
}