mirror of
https://github.com/snowykami/neo-blog.git
synced 2025-09-26 11:06:23 +00:00
feat: 优化仪表板数据结构类型定义,提升代码可读性
This commit is contained in:
@ -2,10 +2,11 @@
|
|||||||
import { getDashboard, DashboardResp } from "@/api/admin"
|
import { getDashboard, DashboardResp } from "@/api/admin"
|
||||||
import { Card, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"
|
import { Card, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"
|
||||||
import { Eye, MessageCircle, Newspaper, Users } from "lucide-react"
|
import { Eye, MessageCircle, Newspaper, Users } from "lucide-react"
|
||||||
import { useEffect, useState } from "react"
|
import { JSX, useEffect, useState } from "react"
|
||||||
import { toast } from "sonner"
|
import { toast } from "sonner"
|
||||||
import { path } from "../data"
|
import { path } from "../data"
|
||||||
import Link from "next/link"
|
import Link from "next/link"
|
||||||
|
import { IconType } from "@/types/icon"
|
||||||
|
|
||||||
export function Dashboard() {
|
export function Dashboard() {
|
||||||
return (
|
return (
|
||||||
@ -16,30 +17,30 @@ export function Dashboard() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function DataOverview() {
|
function DataOverview() {
|
||||||
const data = [
|
const data: { key: keyof DashboardResp; label: string; icon: IconType; url: string }[] = [
|
||||||
{
|
{
|
||||||
"key": "totalPosts",
|
key: "totalPosts",
|
||||||
"label": "Total Posts",
|
label: "Total Posts",
|
||||||
"icon": Newspaper,
|
icon: Newspaper,
|
||||||
"url": path.post
|
url: path.post
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"key": "totalUsers",
|
key: "totalUsers",
|
||||||
"label": "Total Users",
|
label: "Total Users",
|
||||||
"icon": Users,
|
icon: Users,
|
||||||
"url": path.user
|
url: path.user
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"key": "totalComments",
|
key: "totalComments",
|
||||||
"label": "Total Comments",
|
label: "Total Comments",
|
||||||
"icon": MessageCircle,
|
icon: MessageCircle,
|
||||||
"url": path.comment
|
url: path.comment
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"key": "totalViews",
|
key: "totalViews",
|
||||||
"label": "Total Views",
|
label: "Total Views",
|
||||||
"icon": Eye,
|
icon: Eye,
|
||||||
"url": path.file
|
url: path.file
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -63,7 +64,7 @@ function DataOverview() {
|
|||||||
<CardDescription>{item.label}</CardDescription>
|
<CardDescription>{item.label}</CardDescription>
|
||||||
<CardTitle className="text-2xl font-semibold tabular-nums @[250px]/card:text-3xl text-primary">
|
<CardTitle className="text-2xl font-semibold tabular-nums @[250px]/card:text-3xl text-primary">
|
||||||
<item.icon className="inline mr-2" />
|
<item.icon className="inline mr-2" />
|
||||||
{(fetchData as any)[item.key]}
|
{fetchData[item.key]}
|
||||||
</CardTitle>
|
</CardTitle>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
</Card>
|
</Card>
|
||||||
|
Reference in New Issue
Block a user