- Add export module for diagnostic report data export - Add stats-service for diagnostic analytics aggregation - Add confidence-utils for diagnostic confidence score calculations
294 lines
12 KiB
TypeScript
294 lines
12 KiB
TypeScript
"use client"
|
|
|
|
import Link from "next/link"
|
|
import { useTranslations } from "next-intl"
|
|
import { Award, AlertTriangle, Lightbulb, FileText, History, ArrowRight } from "lucide-react"
|
|
|
|
import { Card, CardContent, CardHeader, CardTitle, CardDescription } from "@/shared/components/ui/card"
|
|
import { Badge } from "@/shared/components/ui/badge"
|
|
import { Button } from "@/shared/components/ui/button"
|
|
import { Tooltip, TooltipContent, TooltipTrigger } from "@/shared/components/ui/tooltip"
|
|
import { EmptyState } from "@/shared/components/ui/empty-state"
|
|
import { formatDate } from "@/shared/lib/utils"
|
|
import { MasteryRadarChart } from "./mastery-radar-chart"
|
|
import {
|
|
getConfidenceLevel,
|
|
confidenceBadgeVariant,
|
|
type ConfidenceLevel,
|
|
} from "./confidence-utils"
|
|
import type { DiagnosticReportWithDetails, MasteryRadarPoint, StudentMasterySummary } from "../types"
|
|
|
|
interface StudentDiagnosticViewProps {
|
|
summary: StudentMasterySummary | null
|
|
reports: DiagnosticReportWithDetails[]
|
|
classAverageMastery?: MasteryRadarPoint[]
|
|
/**
|
|
* v3-P2-6: "练习"按钮的跳转基础路径。
|
|
* - 学生视角:默认 `/student/learning/assignments`
|
|
* - 教师视角:传入 `/teacher/questions`(题目库支持 kp 查询参数筛选)
|
|
* - 家长视角:传入 `null` 隐藏练习按钮(家长无练习入口)
|
|
* 最终链接会附加 `?kp={knowledgePointId}` 实现个性化练习推荐。
|
|
*/
|
|
practiceHrefBase?: string | null
|
|
}
|
|
|
|
export function StudentDiagnosticView({
|
|
summary,
|
|
reports,
|
|
classAverageMastery,
|
|
practiceHrefBase = "/student/learning/assignments",
|
|
}: StudentDiagnosticViewProps) {
|
|
const t = useTranslations("diagnostic")
|
|
|
|
if (!summary) {
|
|
return (
|
|
<EmptyState
|
|
title={t("empty.noData")}
|
|
description={t("studentDiagnostic.noDataDescription")}
|
|
icon={FileText}
|
|
className="border-none shadow-none"
|
|
/>
|
|
)
|
|
}
|
|
|
|
const radarData: MasteryRadarPoint[] = summary.allMastery.map((m) => {
|
|
const classAvg = classAverageMastery?.find((c) => c.knowledgePoint === m.knowledgePointName)
|
|
return {
|
|
knowledgePoint: m.knowledgePointName,
|
|
student: Math.round(m.masteryLevel * 100) / 100,
|
|
classAverage: classAvg?.classAverage,
|
|
}
|
|
})
|
|
|
|
const publishedReports = reports.filter((r) => r.status === "published")
|
|
// v4-P1-3: 移除草稿回退逻辑,仅展示已发布报告
|
|
// 调用方(学生/家长页面)已传 status: "published" 过滤,此处双重保障
|
|
const latestReport = publishedReports[0] ?? null
|
|
|
|
const statusLabel = (status: string): string => {
|
|
if (status === "draft") return t("status.draft")
|
|
if (status === "published") return t("status.published")
|
|
if (status === "archived") return t("status.archived")
|
|
return status
|
|
}
|
|
|
|
const typeLabel = (reportType: string): string => {
|
|
if (reportType === "individual") return t("type.individual")
|
|
if (reportType === "class") return t("type.class")
|
|
if (reportType === "grade") return t("type.grade")
|
|
return reportType
|
|
}
|
|
|
|
// v4-P3-7: 置信度标签与提示
|
|
const confidenceLabel = (level: ConfidenceLevel): string => {
|
|
if (level === "high") return t("reportList.confidenceHigh")
|
|
if (level === "medium") return t("reportList.confidenceMedium")
|
|
if (level === "low") return t("reportList.confidenceLow")
|
|
return t("reportList.confidenceInsufficient")
|
|
}
|
|
|
|
const confidenceHint = (level: ConfidenceLevel): string => {
|
|
if (level === "high") return t("reportList.confidenceHighHint")
|
|
if (level === "medium") return t("reportList.confidenceMediumHint")
|
|
if (level === "low") return t("reportList.confidenceLowHint")
|
|
return t("reportList.confidenceInsufficient")
|
|
}
|
|
|
|
return (
|
|
<div className="space-y-6">
|
|
{/* 概览卡片 */}
|
|
<div className="grid grid-cols-1 gap-4 md:grid-cols-4">
|
|
<Card>
|
|
<CardHeader className="pb-2">
|
|
<CardTitle className="text-sm font-medium text-muted-foreground">{t("summary.student")}</CardTitle>
|
|
</CardHeader>
|
|
<CardContent>
|
|
<p className="text-2xl font-bold">{summary.studentName}</p>
|
|
</CardContent>
|
|
</Card>
|
|
<Card>
|
|
<CardHeader className="pb-2">
|
|
<CardTitle className="text-sm font-medium text-muted-foreground">{t("summary.overallMastery")}</CardTitle>
|
|
</CardHeader>
|
|
<CardContent>
|
|
<p className="text-2xl font-bold">{summary.averageMastery.toFixed(1)}%</p>
|
|
</CardContent>
|
|
</Card>
|
|
<Card>
|
|
<CardHeader className="pb-2">
|
|
<CardTitle className="text-sm font-medium text-muted-foreground">{t("summary.strengths")}</CardTitle>
|
|
</CardHeader>
|
|
<CardContent>
|
|
<p className="text-2xl font-bold text-green-600">{summary.strengths.length}</p>
|
|
</CardContent>
|
|
</Card>
|
|
<Card>
|
|
<CardHeader className="pb-2">
|
|
<CardTitle className="text-sm font-medium text-muted-foreground">{t("summary.weaknesses")}</CardTitle>
|
|
</CardHeader>
|
|
<CardContent>
|
|
<p className="text-2xl font-bold text-red-600">{summary.weaknesses.length}</p>
|
|
</CardContent>
|
|
</Card>
|
|
</div>
|
|
|
|
{/* 雷达图 */}
|
|
<MasteryRadarChart data={radarData} />
|
|
|
|
{/* 强项 / 弱项 */}
|
|
<div className="grid grid-cols-1 gap-4 md:grid-cols-2">
|
|
<Card>
|
|
<CardHeader>
|
|
<CardTitle className="flex items-center gap-2">
|
|
<Award className="h-4 w-4 text-green-600" />
|
|
{t("strengths.title")}
|
|
</CardTitle>
|
|
<CardDescription>{t("studentDiagnostic.strengthsDescription")}</CardDescription>
|
|
</CardHeader>
|
|
<CardContent>
|
|
{summary.strengths.length === 0 ? (
|
|
<p className="text-sm text-muted-foreground">{t("studentDiagnostic.noStrengths")}</p>
|
|
) : (
|
|
<ul className="space-y-2" role="list" aria-label={t("studentDiagnostic.strengthsListAriaLabel")}>
|
|
{summary.strengths.map((m) => (
|
|
<li key={m.knowledgePointId} className="flex items-center justify-between">
|
|
<span className="text-sm">{m.knowledgePointName}</span>
|
|
<Badge variant="default" className="bg-green-600">{m.masteryLevel.toFixed(1)}%</Badge>
|
|
</li>
|
|
))}
|
|
</ul>
|
|
)}
|
|
</CardContent>
|
|
</Card>
|
|
<Card>
|
|
<CardHeader>
|
|
<CardTitle className="flex items-center gap-2">
|
|
<AlertTriangle className="h-4 w-4 text-red-600" />
|
|
{t("weaknesses.title")}
|
|
</CardTitle>
|
|
<CardDescription>{t("studentDiagnostic.weaknessesDescription")}</CardDescription>
|
|
</CardHeader>
|
|
<CardContent>
|
|
{summary.weaknesses.length === 0 ? (
|
|
<p className="text-sm text-muted-foreground">{t("studentDiagnostic.noWeaknesses")}</p>
|
|
) : (
|
|
<ul className="space-y-2" role="list" aria-label={t("studentDiagnostic.weaknessesListAriaLabel")}>
|
|
{summary.weaknesses.map((m) => (
|
|
<li key={m.knowledgePointId} className="flex items-center justify-between gap-2">
|
|
<div className="flex items-center gap-2 min-w-0">
|
|
<span className="text-sm truncate">{m.knowledgePointName}</span>
|
|
<Badge variant="destructive" className="shrink-0">{m.masteryLevel.toFixed(1)}%</Badge>
|
|
</div>
|
|
{practiceHrefBase ? (
|
|
<Button asChild variant="ghost" size="sm" className="h-7 shrink-0 text-xs" aria-label={t("studentDiagnostic.practiceAriaLabel", { name: m.knowledgePointName })}>
|
|
<Link href={`${practiceHrefBase}?kp=${m.knowledgePointId}`}>
|
|
{t("weaknesses.practice")}
|
|
<ArrowRight className="ml-1 h-3 w-3" />
|
|
</Link>
|
|
</Button>
|
|
) : null}
|
|
</li>
|
|
))}
|
|
</ul>
|
|
)}
|
|
</CardContent>
|
|
</Card>
|
|
</div>
|
|
|
|
{/* 最新报告 / 建议 */}
|
|
{latestReport ? (
|
|
<Card>
|
|
<CardHeader>
|
|
<CardTitle className="flex items-center gap-2">
|
|
<Lightbulb className="h-4 w-4" />
|
|
{t("studentDiagnostic.diagnosticReportTitle")}
|
|
<Badge variant={latestReport.status === "published" ? "default" : "secondary"}>
|
|
{statusLabel(latestReport.status)}
|
|
</Badge>
|
|
{(() => {
|
|
const level = getConfidenceLevel(latestReport)
|
|
return (
|
|
<Tooltip>
|
|
<TooltipTrigger asChild>
|
|
<Badge
|
|
variant={confidenceBadgeVariant[level]}
|
|
aria-label={t("reportList.confidenceAriaLabel", { level: confidenceLabel(level) })}
|
|
>
|
|
{confidenceLabel(level)}
|
|
</Badge>
|
|
</TooltipTrigger>
|
|
<TooltipContent>{confidenceHint(level)}</TooltipContent>
|
|
</Tooltip>
|
|
)
|
|
})()}
|
|
</CardTitle>
|
|
<CardDescription>
|
|
{t("studentDiagnostic.reportMeta", {
|
|
period: latestReport.period ?? "-",
|
|
score: latestReport.overallScore?.toFixed(1) ?? "-",
|
|
})}
|
|
</CardDescription>
|
|
</CardHeader>
|
|
<CardContent className="space-y-4">
|
|
{latestReport.summary ? (
|
|
<p className="text-sm">{latestReport.summary}</p>
|
|
) : null}
|
|
{latestReport.recommendations && latestReport.recommendations.length > 0 ? (
|
|
<div>
|
|
<h4 className="mb-2 text-sm font-semibold">{t("report.recommendations")}</h4>
|
|
<ul className="space-y-1.5" role="list" aria-label={t("studentDiagnostic.recommendationsListAriaLabel")}>
|
|
{latestReport.recommendations.map((rec, i) => (
|
|
<li key={rec || `rec-${i}`} className="text-sm text-muted-foreground">• {rec}</li>
|
|
))}
|
|
</ul>
|
|
</div>
|
|
) : null}
|
|
</CardContent>
|
|
</Card>
|
|
) : null}
|
|
|
|
{/* 历史报告列表 */}
|
|
{publishedReports.length > 1 ? (
|
|
<Card>
|
|
<CardHeader>
|
|
<CardTitle className="flex items-center gap-2">
|
|
<History className="h-4 w-4" />
|
|
{t("report.history")}
|
|
</CardTitle>
|
|
<CardDescription>{t("studentDiagnostic.historyDescription")}</CardDescription>
|
|
</CardHeader>
|
|
<CardContent>
|
|
<div className="space-y-2">
|
|
{publishedReports.map((r) => (
|
|
<div
|
|
key={r.id}
|
|
className="flex items-center justify-between gap-3 rounded-md border p-3"
|
|
>
|
|
<div className="min-w-0 space-y-1">
|
|
<div className="flex items-center gap-2">
|
|
<span className="text-sm font-medium">
|
|
{r.period ?? t("studentDiagnostic.untitledPeriod")}
|
|
</span>
|
|
<Badge variant="outline" className="text-xs">
|
|
{typeLabel(r.reportType)}
|
|
</Badge>
|
|
</div>
|
|
<p className="text-xs text-muted-foreground">
|
|
{r.overallScore !== null
|
|
? t("studentDiagnostic.historyReportMeta", {
|
|
date: formatDate(r.createdAt),
|
|
score: r.overallScore.toFixed(1),
|
|
})
|
|
: formatDate(r.createdAt)}
|
|
</p>
|
|
</div>
|
|
</div>
|
|
))}
|
|
</div>
|
|
</CardContent>
|
|
</Card>
|
|
) : null}
|
|
</div>
|
|
)
|
|
}
|