调整目录

This commit is contained in:
mlogclub
2026-04-24 12:01:30 +08:00
parent 7889ecb0d2
commit a9275c2d4a
209 changed files with 0 additions and 0 deletions
@@ -0,0 +1,71 @@
"use client"
import Link from "next/link"
import { ArrowRightIcon, ShieldAlertIcon } from "lucide-react"
import type { DashboardAlert } from "@/lib/api/dashboard"
import { Badge } from "@/components/ui/badge"
import {
Card,
CardContent,
CardDescription,
CardHeader,
CardTitle,
} from "@/components/ui/card"
type AlertListProps = {
alerts: DashboardAlert[]
}
function getAlertBadgeVariant(level: DashboardAlert["level"]) {
if (level === "error") {
return "destructive" as const
}
if (level === "warning") {
return "secondary" as const
}
return "outline" as const
}
export function AlertList({ alerts }: AlertListProps) {
return (
<Card>
<CardHeader>
<CardTitle></CardTitle>
<CardDescription> AI </CardDescription>
</CardHeader>
<CardContent className="space-y-3">
{alerts.length === 0 ? (
<div className="rounded-2xl border border-dashed px-4 py-10 text-center">
<ShieldAlertIcon className="mx-auto mb-3 size-8 text-muted-foreground" />
<div className="text-sm font-medium"></div>
<div className="mt-1 text-sm text-muted-foreground">
AI
</div>
</div>
) : (
alerts.map((item) => (
<Link key={item.id} href={item.link} className="block">
<div className="rounded-2xl border p-4 transition-colors hover:border-primary/40">
<div className="flex items-start justify-between gap-3">
<div>
<div className="flex items-center gap-2">
<div className="font-medium">{item.title}</div>
<Badge variant={getAlertBadgeVariant(item.level)}>
{item.count}
</Badge>
</div>
<div className="mt-1 text-sm text-muted-foreground">
{item.description}
</div>
</div>
<ArrowRightIcon className="mt-0.5 size-4 text-muted-foreground" />
</div>
</div>
</Link>
))
)}
</CardContent>
</Card>
)
}
@@ -0,0 +1,172 @@
"use client"
import { useCallback, useEffect, useState } from "react"
import { RefreshCwIcon } from "lucide-react"
import { toast } from "sonner"
import { Button } from "@/components/ui/button"
import { Skeleton } from "@/components/ui/skeleton"
import { Card, CardContent } from "@/components/ui/card"
import {
fetchDashboardOverview,
type DashboardOverview,
type DashboardRange,
} from "@/lib/api/dashboard"
import { SummaryCards } from "./summary-cards"
import { TrendPanel } from "./trend-panel"
import { TeamLoadPanel } from "./team-load-panel"
import { AlertList } from "./alert-list"
const rangeOptions: Array<{ value: DashboardRange; label: string }> = [
{ value: "today", label: "今天" },
{ value: "7d", label: "近 7 天" },
{ value: "30d", label: "近 30 天" },
]
function LoadingCards() {
return (
<div className="grid gap-4 md:grid-cols-2 xl:grid-cols-3 2xl:grid-cols-6">
{Array.from({ length: 6 }).map((_, index) => (
<Card key={index}>
<CardContent className="space-y-3 p-6">
<Skeleton className="h-4 w-24" />
<Skeleton className="h-8 w-20" />
<Skeleton className="h-4 w-full" />
</CardContent>
</Card>
))}
</div>
)
}
export function DashboardHome() {
const [range, setRange] = useState<DashboardRange>("7d")
const [data, setData] = useState<DashboardOverview | null>(null)
const [loading, setLoading] = useState(true)
const [refreshing, setRefreshing] = useState(false)
const loadData = useCallback(
async (nextRange: DashboardRange, showRefreshing = false) => {
if (showRefreshing) {
setRefreshing(true)
} else {
setLoading(true)
}
try {
const result = await fetchDashboardOverview(nextRange)
setData(result)
} catch (error) {
toast.error(error instanceof Error ? error.message : "加载首页概览失败")
} finally {
setLoading(false)
setRefreshing(false)
}
},
[]
)
useEffect(() => {
void loadData(range)
}, [loadData, range])
return (
<div className="flex flex-1 flex-col gap-6 p-4 lg:p-6">
<div className="flex flex-col gap-3 xl:flex-row xl:items-start xl:justify-between">
<div>
<h1 className="text-2xl font-semibold tracking-tight"></h1>
<p className="mt-1 text-sm text-muted-foreground">
AI
{data ? `,更新于 ${data.generatedAt}` : ""}
</p>
</div>
<div className="flex flex-wrap items-center gap-2">
<div className="rounded-xl border bg-muted/30 p-1">
{rangeOptions.map((item) => (
<Button
key={item.value}
variant={range === item.value ? "secondary" : "ghost"}
size="sm"
onClick={() => setRange(item.value)}
>
{item.label}
</Button>
))}
</div>
<Button
variant="outline"
size="sm"
onClick={() => void loadData(range, true)}
disabled={loading || refreshing}
>
<RefreshCwIcon className={refreshing ? "mr-2 size-4 animate-spin" : "mr-2 size-4"} />
</Button>
</div>
</div>
{loading && !data ? (
<LoadingCards />
) : data ? (
<>
<SummaryCards summary={data.summary} />
<TrendPanel
title="会话趋势"
description="观察新增与关闭会话变化,快速判断接待压力是否持续上升"
trend={data.conversationStats.trend}
distribution={data.conversationStats.statusDistribution}
/>
<div className="grid gap-4 xl:grid-cols-[1.15fr_0.85fr]">
<TeamLoadPanel agentStats={data.agentStats} />
<Card>
<CardContent className="grid gap-4 p-6 sm:grid-cols-2">
<div className="rounded-2xl border bg-muted/30 p-4">
<div className="text-sm text-muted-foreground"> AI Agent</div>
<div className="mt-2 text-3xl font-semibold">{data.aiStats.enabledAiAgents}</div>
</div>
<div className="rounded-2xl border bg-muted/30 p-4">
<div className="text-sm text-muted-foreground"></div>
<div className="mt-2 text-3xl font-semibold">{data.aiStats.enabledChannels}</div>
</div>
<div className="rounded-2xl border bg-muted/30 p-4">
<div className="text-sm text-muted-foreground"></div>
<div className="mt-2 text-3xl font-semibold">
{data.aiStats.todayKnowledgeRetrieves}
</div>
</div>
<div className="rounded-2xl border bg-muted/30 p-4">
<div className="text-sm text-muted-foreground"></div>
<div className="mt-2 text-3xl font-semibold">
{data.aiStats.todayKnowledgeRetrieveFailRate.toFixed(1)}%
</div>
</div>
<div className="rounded-2xl border bg-muted/30 p-4">
<div className="text-sm text-muted-foreground"> Skill </div>
<div className="mt-2 text-3xl font-semibold">
{data.aiStats.todaySkillRunFailCount}
</div>
</div>
<div className="rounded-2xl border bg-muted/30 p-4">
<div className="text-sm text-muted-foreground"> AI </div>
<div className="mt-2 text-3xl font-semibold">
{data.aiStats.todayAiHandoffCount}
</div>
</div>
</CardContent>
</Card>
</div>
<AlertList alerts={data.alerts} />
</>
) : (
<Card>
<CardContent className="flex min-h-60 items-center justify-center p-6 text-sm text-muted-foreground">
</CardContent>
</Card>
)}
</div>
)
}
@@ -0,0 +1,105 @@
"use client"
import Link from "next/link"
import {
BotMessageSquareIcon,
CircleDashedIcon,
HeadsetIcon,
SparklesIcon,
WavesIcon,
} from "lucide-react"
import type { DashboardOverview } from "@/lib/api/dashboard"
import {
Card,
CardContent,
CardDescription,
CardHeader,
CardTitle,
} from "@/components/ui/card"
type SummaryCardsProps = {
summary: DashboardOverview["summary"]
}
type SummaryCardItem = {
key: keyof DashboardOverview["summary"]
title: string
description: string
link: string
icon: typeof BotMessageSquareIcon
format?: (value: number) => string
}
const cards: SummaryCardItem[] = [
{
key: "todayNewConversations",
title: "今日新增会话",
description: "今日进入系统的新增咨询量",
link: "/conversations",
icon: BotMessageSquareIcon,
},
{
key: "processingConversations",
title: "当前处理中",
description: "正在由 AI 或人工接待的会话",
link: "/conversations",
icon: WavesIcon,
},
{
key: "pendingDispatchConversations",
title: "待分配会话",
description: "仍在待接入池中等待分配",
link: "/conversations",
icon: CircleDashedIcon,
},
{
key: "onlineAgents",
title: "在线客服",
description: "近 15 分钟内仍有活跃心跳的客服",
link: "/agents",
icon: HeadsetIcon,
},
{
key: "aiServiceRate",
title: "AI 接待占比",
description: "当前活跃会话中 AI 参与服务比例",
link: "/ai-agents",
icon: SparklesIcon,
format: (value: number) => `${value.toFixed(1)}%`,
},
]
export function SummaryCards({ summary }: SummaryCardsProps) {
return (
<div className="grid gap-4 md:grid-cols-2 xl:grid-cols-3 2xl:grid-cols-6">
{cards.map((item) => {
const Icon = item.icon
const rawValue = summary[item.key]
const value =
typeof item.format === "function"
? item.format(Number(rawValue))
: Number(rawValue).toLocaleString()
return (
<Link key={item.key} href={item.link}>
<Card className="h-full transition-colors hover:border-primary/40">
<CardHeader className="flex flex-row items-start justify-between space-y-0 pb-3">
<div className="space-y-1">
<CardTitle className="text-sm font-medium">{item.title}</CardTitle>
<CardDescription>{item.description}</CardDescription>
</div>
<div className="rounded-full bg-primary/10 p-2 text-primary">
<Icon className="size-4" />
</div>
</CardHeader>
<CardContent>
<div className="text-3xl font-semibold tracking-tight">{value}</div>
</CardContent>
</Card>
</Link>
)
})}
</div>
)
}
@@ -0,0 +1,98 @@
"use client"
import { Badge } from "@/components/ui/badge"
import {
Card,
CardContent,
CardDescription,
CardHeader,
CardTitle,
} from "@/components/ui/card"
import type { DashboardOverview } from "@/lib/api/dashboard"
type TeamLoadPanelProps = {
agentStats: DashboardOverview["agentStats"]
}
function getLoadTone(loadRate: number) {
if (loadRate >= 85) {
return "bg-red-500"
}
if (loadRate >= 60) {
return "bg-amber-500"
}
return "bg-emerald-500"
}
export function TeamLoadPanel({ agentStats }: TeamLoadPanelProps) {
return (
<Card>
<CardHeader>
<CardTitle></CardTitle>
<CardDescription>
线 {agentStats.onlineAgents} {agentStats.busyAgents}线 {agentStats.offlineAgents}
</CardDescription>
</CardHeader>
<CardContent className="space-y-4">
{agentStats.teamLoads.length === 0 ? (
<div className="rounded-xl border border-dashed px-4 py-8 text-center text-sm text-muted-foreground">
</div>
) : (
agentStats.teamLoads.map((item) => (
<div key={item.teamId} className="rounded-2xl border p-4">
<div className="flex flex-wrap items-center justify-between gap-3">
<div>
<div className="flex items-center gap-2">
<div className="font-medium">{item.teamName}</div>
{item.hasScheduleNow ? (
<Badge variant="secondary"></Badge>
) : (
<Badge variant="outline"></Badge>
)}
</div>
<div className="mt-1 text-sm text-muted-foreground">
{item.totalAgents}线 {item.onlineAgents} {item.busyAgents}线{" "}
{item.offlineAgents}
</div>
</div>
<div className="text-right">
<div className="text-2xl font-semibold">{item.loadRate.toFixed(1)}%</div>
<div className="text-xs text-muted-foreground">
{item.processingConversations}/{item.maxConcurrentCapacity || 0}
</div>
</div>
</div>
<div className="mt-4 h-2 rounded-full bg-muted">
<div
className={`h-2 rounded-full ${getLoadTone(item.loadRate)}`}
style={{ width: `${Math.min(item.loadRate, 100)}%` }}
/>
</div>
<div className="mt-4 grid gap-3 text-sm md:grid-cols-2 xl:grid-cols-4">
<div className="rounded-xl bg-muted/40 px-3 py-2">
<div className="text-muted-foreground"></div>
<div className="mt-1 text-lg font-semibold">{item.waitingConversations}</div>
</div>
<div className="rounded-xl bg-muted/40 px-3 py-2">
<div className="text-muted-foreground"></div>
<div className="mt-1 text-lg font-semibold">{item.processingConversations}</div>
</div>
<div className="rounded-xl bg-muted/40 px-3 py-2">
<div className="text-muted-foreground"></div>
<div className="mt-1 text-lg font-semibold">{item.maxConcurrentCapacity}</div>
</div>
<div className="rounded-xl bg-muted/40 px-3 py-2">
<div className="text-muted-foreground"></div>
<div className="mt-1 text-lg font-semibold">{item.busyAgents}</div>
</div>
</div>
</div>
))
)}
</CardContent>
</Card>
)
}
@@ -0,0 +1,117 @@
"use client"
import { Area, AreaChart, Bar, BarChart, CartesianGrid, XAxis, YAxis } from "recharts"
import type { DashboardStatusDistributionItem, DashboardTrendItem } from "@/lib/api/dashboard"
import {
Card,
CardContent,
CardDescription,
CardHeader,
CardTitle,
} from "@/components/ui/card"
import {
ChartContainer,
ChartTooltip,
ChartTooltipContent,
type ChartConfig,
} from "@/components/ui/chart"
type TrendPanelProps = {
title: string
description: string
trend: DashboardTrendItem[]
distribution: DashboardStatusDistributionItem[]
}
const trendConfig = {
newCount: {
label: "新增",
color: "hsl(24 95% 53%)",
},
closedCount: {
label: "关闭",
color: "hsl(190 95% 39%)",
},
} satisfies ChartConfig
const distributionConfig = {
count: {
label: "数量",
theme: {
light: "hsl(222 47% 11%)",
dark: "hsl(210 40% 98%)",
},
},
} satisfies ChartConfig
export function TrendPanel({
title,
description,
trend,
distribution,
}: TrendPanelProps) {
return (
<div className="grid gap-4 xl:grid-cols-[1.5fr_0.9fr]">
<Card>
<CardHeader>
<CardTitle>{title}</CardTitle>
<CardDescription>{description}</CardDescription>
</CardHeader>
<CardContent>
<ChartContainer config={trendConfig} className="h-72 w-full">
<AreaChart data={trend}>
<CartesianGrid vertical={false} />
<XAxis dataKey="date" tickLine={false} axisLine={false} tickMargin={8} />
<ChartTooltip content={<ChartTooltipContent />} />
<Area
type="monotone"
dataKey="newCount"
stroke="var(--color-newCount)"
fill="var(--color-newCount)"
fillOpacity={0.18}
strokeWidth={2}
/>
<Area
type="monotone"
dataKey="closedCount"
stroke="var(--color-closedCount)"
fill="var(--color-closedCount)"
fillOpacity={0.08}
strokeWidth={2}
/>
</AreaChart>
</ChartContainer>
</CardContent>
</Card>
<Card>
<CardHeader>
<CardTitle></CardTitle>
<CardDescription></CardDescription>
</CardHeader>
<CardContent className="space-y-4">
<ChartContainer config={distributionConfig} className="h-72 w-full">
<BarChart data={distribution} layout="vertical" margin={{ left: 20 }}>
<CartesianGrid horizontal={false} />
<YAxis
type="category"
dataKey="label"
tickLine={false}
axisLine={false}
width={64}
/>
<XAxis type="number" hide />
<ChartTooltip content={<ChartTooltipContent hideLabel />} />
<Bar
dataKey="count"
fill="var(--color-count)"
radius={[0, 8, 8, 0]}
/>
</BarChart>
</ChartContainer>
</CardContent>
</Card>
</div>
)
}