feat(error-book): implement error book module with SM2 spaced repetition
- Add SM2 algorithm implementation with tests for spaced repetition review scheduling - Add data-access, schema, types, and server actions for error book CRUD - Add components: add dialog, class overview, filters, item card, stats cards, review buttons, top wrong questions - Add error-book routes for admin, teacher, parent, and student roles - Add i18n messages (en, zh-CN) for error book module
This commit is contained in:
19
src/app/(dashboard)/parent/error-book/error.tsx
Normal file
19
src/app/(dashboard)/parent/error-book/error.tsx
Normal file
@@ -0,0 +1,19 @@
|
||||
"use client"
|
||||
|
||||
import { BookX } from "lucide-react"
|
||||
|
||||
import { EmptyState } from "@/shared/components/ui/empty-state"
|
||||
|
||||
export default function ParentErrorBookError() {
|
||||
return (
|
||||
<div className="p-8">
|
||||
<EmptyState
|
||||
icon={BookX}
|
||||
title="加载子女错题本失败"
|
||||
description="发生了一些错误,请刷新页面重试。"
|
||||
action={{ label: "刷新页面", onClick: () => window.location.reload() }}
|
||||
className="border-none shadow-none"
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
18
src/app/(dashboard)/parent/error-book/loading.tsx
Normal file
18
src/app/(dashboard)/parent/error-book/loading.tsx
Normal file
@@ -0,0 +1,18 @@
|
||||
import { Skeleton } from "@/shared/components/ui/skeleton"
|
||||
|
||||
export default function ParentErrorBookLoading() {
|
||||
return (
|
||||
<div className="flex h-full flex-col space-y-8 p-8">
|
||||
<div className="space-y-2">
|
||||
<Skeleton className="h-8 w-[180px]" />
|
||||
<Skeleton className="h-4 w-[280px]" />
|
||||
</div>
|
||||
<div className="grid gap-4 sm:grid-cols-2 lg:grid-cols-5">
|
||||
{Array.from({ length: 5 }).map((_, idx) => (
|
||||
<Skeleton key={idx} className="h-[120px] w-full rounded-md" />
|
||||
))}
|
||||
</div>
|
||||
<Skeleton className="h-[300px] w-full rounded-md" />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
138
src/app/(dashboard)/parent/error-book/page.tsx
Normal file
138
src/app/(dashboard)/parent/error-book/page.tsx
Normal file
@@ -0,0 +1,138 @@
|
||||
import type { JSX } from "react"
|
||||
import { Users } from "lucide-react"
|
||||
|
||||
import { requirePermission } from "@/shared/lib/auth-guard"
|
||||
import { Permissions } from "@/shared/types/permissions"
|
||||
import { EmptyState } from "@/shared/components/ui/empty-state"
|
||||
import { Card, CardContent, CardHeader, CardTitle } from "@/shared/components/ui/card"
|
||||
import { Badge } from "@/shared/components/ui/badge"
|
||||
import { Progress } from "@/shared/components/ui/progress"
|
||||
import { formatNumber } from "@/shared/lib/utils"
|
||||
|
||||
import {
|
||||
getErrorBookStats,
|
||||
getStudentNameMap,
|
||||
getTopWrongQuestionsByStudentIds,
|
||||
getKnowledgePointWeakness,
|
||||
} from "@/modules/error-book/data-access"
|
||||
import { ErrorBookStatsCards } from "@/modules/error-book/components/error-book-stats-cards"
|
||||
import { TopWrongQuestions } from "@/modules/error-book/components/top-wrong-questions"
|
||||
|
||||
export const dynamic = "force-dynamic"
|
||||
|
||||
export default async function ParentErrorBookPage(): Promise<JSX.Element> {
|
||||
const ctx = await requirePermission(Permissions.ERROR_BOOK_READ)
|
||||
|
||||
if (ctx.dataScope.type !== "children" || ctx.dataScope.childrenIds.length === 0) {
|
||||
return (
|
||||
<div className="flex h-full flex-col space-y-8 p-8">
|
||||
<div>
|
||||
<h1 className="text-2xl font-bold tracking-tight">子女错题本</h1>
|
||||
<p className="text-muted-foreground">查看子女的错题情况与学习进度。</p>
|
||||
</div>
|
||||
<EmptyState
|
||||
icon={Users}
|
||||
title="暂无子女关联"
|
||||
description="您的账号尚未关联子女,请联系学校管理员进行关联。"
|
||||
className="h-[360px] bg-card"
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
const childrenIds = ctx.dataScope.childrenIds
|
||||
|
||||
const [nameMap, ...childStatsList] = await Promise.all([
|
||||
getStudentNameMap(childrenIds),
|
||||
...childrenIds.map((id) => getErrorBookStats(id)),
|
||||
])
|
||||
|
||||
// 汇总所有子女的错题
|
||||
const [topWrongQuestions, weakKps] = await Promise.all([
|
||||
getTopWrongQuestionsByStudentIds(childrenIds, 5),
|
||||
getKnowledgePointWeakness(childrenIds, 5),
|
||||
])
|
||||
|
||||
return (
|
||||
<div className="flex h-full flex-col space-y-8 p-8">
|
||||
<div>
|
||||
<h1 className="text-2xl font-bold tracking-tight">子女错题本</h1>
|
||||
<p className="text-muted-foreground">查看子女的错题情况与学习进度。</p>
|
||||
</div>
|
||||
|
||||
{childrenIds.length === 1 ? (
|
||||
// 单子女:直接展示统计卡片
|
||||
<ErrorBookStatsCards stats={childStatsList[0]} />
|
||||
) : (
|
||||
// 多子女:每个子女一张卡片
|
||||
<div className="grid gap-4 md:grid-cols-2">
|
||||
{childrenIds.map((childId, idx) => {
|
||||
const stats = childStatsList[idx]
|
||||
const name = nameMap.get(childId) ?? "未知"
|
||||
return (
|
||||
<Card key={childId}>
|
||||
<CardHeader>
|
||||
<CardTitle className="flex items-center justify-between text-base">
|
||||
<span>{name}</span>
|
||||
<Badge variant="outline">
|
||||
{formatNumber(stats.masteredRate * 100, 0)}% 掌握
|
||||
</Badge>
|
||||
</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-3">
|
||||
<div className="grid grid-cols-2 gap-3 text-sm">
|
||||
<div>
|
||||
<div className="text-muted-foreground">错题总数</div>
|
||||
<div className="text-lg font-bold">{stats.totalCount}</div>
|
||||
</div>
|
||||
<div>
|
||||
<div className="text-muted-foreground">待复习</div>
|
||||
<div className="text-lg font-bold text-rose-600 dark:text-rose-400">
|
||||
{stats.dueReviewCount}
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<div className="text-muted-foreground">待学习</div>
|
||||
<div className="font-medium text-blue-600 dark:text-blue-400">{stats.newCount}</div>
|
||||
</div>
|
||||
<div>
|
||||
<div className="text-muted-foreground">已掌握</div>
|
||||
<div className="font-medium text-emerald-600 dark:text-emerald-400">{stats.masteredCount}</div>
|
||||
</div>
|
||||
</div>
|
||||
<Progress value={stats.masteredRate * 100} className="h-2" />
|
||||
</CardContent>
|
||||
</Card>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* 薄弱知识点 */}
|
||||
{weakKps.length > 0 ? (
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className="text-base">薄弱知识点</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="space-y-3">
|
||||
{weakKps.map((kp) => (
|
||||
<div key={kp.knowledgePointId} className="space-y-1">
|
||||
<div className="flex items-center justify-between text-sm">
|
||||
<span>{kp.knowledgePointName}</span>
|
||||
<span className="text-muted-foreground">
|
||||
{kp.errorCount} 错 · {formatNumber(kp.masteryRate * 100, 0)}% 掌握
|
||||
</span>
|
||||
</div>
|
||||
<Progress value={kp.masteryRate * 100} className="h-1.5" />
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
) : null}
|
||||
|
||||
<TopWrongQuestions questions={topWrongQuestions} />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user