Files
cunkebao_v3/SuperAdmin/app/dashboard/layout.tsx

60 lines
1.6 KiB
TypeScript
Raw Normal View History

2025-04-09 09:45:06 +08:00
"use client"
import type React from "react"
2025-04-10 11:54:21 +08:00
import { useState, useEffect } from "react"
import { useRouter } from "next/navigation"
2025-04-09 09:45:06 +08:00
import { Button } from "@/components/ui/button"
2025-04-10 11:54:21 +08:00
import { Menu, X } from "lucide-react"
2025-04-09 17:21:29 +08:00
import { Sidebar } from "@/components/layout/sidebar"
import { Header } from "@/components/layout/header"
2025-04-10 11:54:21 +08:00
import { getAdminInfo } from "@/lib/utils"
2025-04-09 09:45:06 +08:00
export default function DashboardLayout({
children,
}: {
children: React.ReactNode
}) {
const [sidebarOpen, setSidebarOpen] = useState(true)
2025-04-10 11:54:21 +08:00
const router = useRouter()
// 认证检查
useEffect(() => {
const checkAuth = () => {
const adminInfo = getAdminInfo()
if (!adminInfo) {
// 未登录时跳转到登录页
router.push('/login')
}
}
checkAuth()
}, [router])
2025-04-09 09:45:06 +08:00
return (
<div className="flex h-screen overflow-hidden">
{/* Mobile sidebar toggle */}
<div className="fixed top-4 left-4 z-50 md:hidden">
<Button variant="outline" size="icon" onClick={() => setSidebarOpen(!sidebarOpen)}>
{sidebarOpen ? <X className="h-5 w-5" /> : <Menu className="h-5 w-5" />}
</Button>
</div>
{/* Sidebar */}
<div
2025-04-09 17:21:29 +08:00
className={`bg-background border-r w-64 flex-shrink-0 transition-all duration-300 ease-in-out ${
2025-04-09 09:45:06 +08:00
sidebarOpen ? "translate-x-0" : "-translate-x-full"
} md:translate-x-0 fixed md:relative z-40 h-full`}
>
2025-04-09 17:21:29 +08:00
<Sidebar />
2025-04-09 09:45:06 +08:00
</div>
{/* Main content */}
2025-04-09 17:21:29 +08:00
<div className="flex-1 flex flex-col overflow-hidden">
<Header />
<main className="flex-1 overflow-y-auto p-6">{children}</main>
2025-04-09 09:45:06 +08:00
</div>
</div>
)
}