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

92 lines
3.0 KiB
TypeScript
Raw Normal View History

2025-04-09 14:07:54 +08:00
"use client"
import { useEffect, useState } from "react"
2025-04-09 09:45:06 +08:00
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"
import { Users, FolderKanban, UserCog } from "lucide-react"
2025-04-09 14:07:54 +08:00
import useAuthCheck from "@/hooks/useAuthCheck"
import { getAdminInfo, getGreeting } from "@/lib/utils"
import ClientOnly from "@/components/ClientOnly"
2025-04-09 09:45:06 +08:00
export default function DashboardPage() {
2025-04-09 14:07:54 +08:00
const [greeting, setGreeting] = useState("")
const [userName, setUserName] = useState("")
// 验证用户是否已登录
useAuthCheck()
useEffect(() => {
// 获取用户信息
const adminInfo = getAdminInfo()
2025-04-09 14:07:54 +08:00
if (adminInfo) {
setUserName(adminInfo.name || "管理员")
2025-04-09 14:07:54 +08:00
} else {
setUserName("管理员")
2025-04-09 14:07:54 +08:00
}
}, [])
// 单独处理问候语,避免依赖问题
useEffect(() => {
// 设置问候语
const updateGreeting = () => {
if (userName) {
setGreeting(getGreeting(userName))
}
}
updateGreeting()
// 每分钟更新一次问候语,以防用户长时间停留在页面
const interval = setInterval(updateGreeting, 60000)
return () => clearInterval(interval)
}, [userName])
2025-04-09 09:45:06 +08:00
return (
<div className="space-y-6">
<h1 className="text-3xl font-bold">使</h1>
2025-04-09 14:07:54 +08:00
<p className="text-muted-foreground">
<ClientOnly fallback={`你好,${userName}`}>
{greeting || getGreeting(userName)}
</ClientOnly>
2025-04-09 14:07:54 +08:00
</p>
2025-04-09 09:45:06 +08:00
<div className="grid gap-6 md:grid-cols-2 lg:grid-cols-3">
<Card>
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
<CardTitle className="text-sm font-medium"></CardTitle>
<FolderKanban className="h-4 w-4 text-muted-foreground" />
</CardHeader>
<CardContent>
<div className="text-2xl font-bold">24</div>
<p className="text-xs text-muted-foreground"> 12%</p>
</CardContent>
</Card>
<Card>
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
<CardTitle className="text-sm font-medium"></CardTitle>
<Users className="h-4 w-4 text-muted-foreground" />
</CardHeader>
<CardContent>
<div className="text-2xl font-bold">1,284</div>
<p className="text-xs text-muted-foreground"> 8%</p>
</CardContent>
</Card>
<Card>
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
<CardTitle className="text-sm font-medium"></CardTitle>
<UserCog className="h-4 w-4 text-muted-foreground" />
</CardHeader>
<CardContent>
<div className="text-2xl font-bold">8</div>
<p className="text-xs text-muted-foreground"> 2 </p>
</CardContent>
</Card>
</div>
</div>
)
}