feat(app): add lesson-plans, practice, and grade dashboard routes
- Add admin/lesson-plans, parent/lesson-plans, student/lesson-plans routes - Add student/practice and teacher/practice routes for adaptive practice - Add management/grade/dashboard and management/grade/practice routes - Add teacher/lesson-plans error and loading boundaries - Update existing admin, parent, student, teacher pages with new features - Update globals.css and proxy middleware
This commit is contained in:
@@ -1,36 +1,52 @@
|
||||
import type { JSX } from "react"
|
||||
import { Suspense } from "react"
|
||||
import { BarChart3 } 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 { Skeleton } from "@/shared/components/ui/skeleton"
|
||||
import { getParam, type SearchParams } from "@/shared/lib/search-params"
|
||||
import { getStudentIdsByClassIds, getClassIdsByGradeIds } from "@/modules/classes/data-access"
|
||||
|
||||
import {
|
||||
getStudentErrorBookSummaries,
|
||||
getTopWrongQuestionsByStudentIds,
|
||||
getKnowledgePointWeakness,
|
||||
getSubjectErrorDistribution,
|
||||
getStudentNameMap,
|
||||
getSubjectErrorOverviews,
|
||||
getClassErrorOverviews,
|
||||
getChapterWeakness,
|
||||
} from "@/modules/error-book/data-access"
|
||||
import { ClassErrorBookOverview, StudentErrorTable } from "@/modules/error-book/components/class-error-overview"
|
||||
import { TopWrongQuestions } from "@/modules/error-book/components/top-wrong-questions"
|
||||
import { SubjectTabs } from "@/modules/error-book/components/subject-tabs"
|
||||
import { ClassFilter } from "@/modules/error-book/components/class-filter"
|
||||
import { AnalyticsStatsCards } from "@/modules/error-book/components/analytics-stats-cards"
|
||||
import { ClassErrorBarChart } from "@/modules/error-book/components/class-error-bar-chart"
|
||||
import { KnowledgePointWeaknessChart } from "@/modules/error-book/components/knowledge-point-weakness-chart"
|
||||
import { ChapterWeaknessChart } from "@/modules/error-book/components/chapter-weakness-chart"
|
||||
import { GroupedStudentErrorTable } from "@/modules/error-book/components/grouped-student-error-table"
|
||||
|
||||
export const dynamic = "force-dynamic"
|
||||
|
||||
export default async function TeacherErrorBookPage(): Promise<JSX.Element> {
|
||||
async function TeacherErrorBookContent({
|
||||
searchParams,
|
||||
}: {
|
||||
searchParams: Promise<SearchParams>
|
||||
}): Promise<JSX.Element> {
|
||||
const ctx = await requirePermission(Permissions.ERROR_BOOK_ANALYTICS_READ)
|
||||
|
||||
// 教师的 dataScope 为 class_taught,年级主任/教研组长为 grade_managed,管理员为 all
|
||||
const params = await searchParams
|
||||
const classIds = ctx.dataScope.type === "class_taught" ? ctx.dataScope.classIds : []
|
||||
const gradeIds = ctx.dataScope.type === "grade_managed" ? ctx.dataScope.gradeIds : []
|
||||
const teacherSubjectIds = ctx.dataScope.type === "class_taught" ? (ctx.dataScope.subjectIds ?? []) : []
|
||||
|
||||
if (classIds.length === 0 && gradeIds.length === 0 && ctx.dataScope.type !== "all") {
|
||||
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>
|
||||
<p className="text-muted-foreground">按学科、班级查看学生的错题统计与薄弱知识点。</p>
|
||||
</div>
|
||||
<EmptyState
|
||||
icon={BarChart3}
|
||||
@@ -42,21 +58,22 @@ export default async function TeacherErrorBookPage(): Promise<JSX.Element> {
|
||||
)
|
||||
}
|
||||
|
||||
// 年级主任/教研组长:先根据 gradeIds 查询班级,再查询学生
|
||||
// 年级主任/教研组长:展开年级为班级
|
||||
let targetClassIds = classIds
|
||||
if (gradeIds.length > 0) {
|
||||
const gradeClassIds = await getClassIdsByGradeIds(gradeIds)
|
||||
targetClassIds = [...new Set([...classIds, ...gradeClassIds])]
|
||||
}
|
||||
|
||||
const studentIds = await getStudentIdsByClassIds(targetClassIds)
|
||||
// 获取所有学生 ID(用于学科概览查询)
|
||||
const allStudentIds = await getStudentIdsByClassIds(targetClassIds)
|
||||
|
||||
if (studentIds.length === 0) {
|
||||
if (allStudentIds.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>
|
||||
<p className="text-muted-foreground">按学科、班级查看学生的错题统计与薄弱知识点。</p>
|
||||
</div>
|
||||
<EmptyState
|
||||
icon={BarChart3}
|
||||
@@ -68,52 +85,168 @@ export default async function TeacherErrorBookPage(): Promise<JSX.Element> {
|
||||
)
|
||||
}
|
||||
|
||||
// 并行查询所有统计数据
|
||||
const [summaries, topWrongQuestions, weakKps, subjectDist, nameMap] = await Promise.all([
|
||||
getStudentErrorBookSummaries(studentIds),
|
||||
getTopWrongQuestionsByStudentIds(studentIds, 10),
|
||||
getKnowledgePointWeakness(studentIds, 10),
|
||||
getSubjectErrorDistribution(studentIds),
|
||||
getStudentNameMap(studentIds),
|
||||
// 解析 URL 参数:学科筛选 + 班级筛选
|
||||
const subjectParam = getParam(params, "subject")
|
||||
const classParam = getParam(params, "classId")
|
||||
|
||||
// 学科概览(用于 Tab 显示,不受学科筛选影响)
|
||||
const subjectOverviews = await getSubjectErrorOverviews(allStudentIds)
|
||||
|
||||
// 班级概览(用于班级筛选器显示,受学科筛选影响)
|
||||
const classOverviews = await getClassErrorOverviews(targetClassIds, subjectParam)
|
||||
|
||||
// 确定实际查询的学科和班级
|
||||
// 如果教师有所教学科,默认只显示所教学科;否则显示全部
|
||||
const effectiveSubjectId =
|
||||
subjectParam ?? (teacherSubjectIds.length === 1 ? teacherSubjectIds[0] : null)
|
||||
const effectiveClassId = classParam ?? "all"
|
||||
|
||||
// 确定查询的学生范围(按班级筛选)
|
||||
const queryClassIds = effectiveClassId === "all" ? targetClassIds : [effectiveClassId]
|
||||
const queryStudentIds = await getStudentIdsByClassIds(queryClassIds)
|
||||
|
||||
// 并行查询所有统计数据(按学科+班级过滤)
|
||||
const [summaries, topWrongQuestions, weakKps, chapterWeakness, nameMap] = await Promise.all([
|
||||
getStudentErrorBookSummaries(queryStudentIds, effectiveSubjectId),
|
||||
getTopWrongQuestionsByStudentIds(queryStudentIds, 10, effectiveSubjectId),
|
||||
getKnowledgePointWeakness(queryStudentIds, 10, effectiveSubjectId),
|
||||
getChapterWeakness(queryStudentIds, 10, effectiveSubjectId),
|
||||
getStudentNameMap(queryStudentIds),
|
||||
])
|
||||
|
||||
const studentsWithErrorBook = summaries.filter((s) => s.totalCount > 0)
|
||||
const totalErrorItems = summaries.reduce((sum, s) => sum + s.totalCount, 0)
|
||||
const totalDueReview = summaries.reduce((sum, s) => sum + s.dueReviewCount, 0)
|
||||
const averageMasteryRate = studentsWithErrorBook.length > 0
|
||||
? studentsWithErrorBook.reduce((sum, s) => sum + s.masteredRate, 0) / studentsWithErrorBook.length
|
||||
: 0
|
||||
const knowledgePointCount = weakKps.length
|
||||
|
||||
// 按错题数降序排列
|
||||
const sortedSummaries = [...summaries].sort((a, b) => b.totalCount - a.totalCount)
|
||||
|
||||
return (
|
||||
<div className="flex h-full flex-col space-y-8 p-8">
|
||||
<div className="flex h-full flex-col space-y-6 p-8">
|
||||
<div>
|
||||
<h1 className="text-2xl font-bold tracking-tight">错题分析</h1>
|
||||
<p className="text-muted-foreground">
|
||||
查看班级学生的错题统计与薄弱知识点,辅助精准教学。
|
||||
按学科、班级查看学生的错题统计与薄弱知识点,辅助精准教学。
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<ClassErrorBookOverview
|
||||
totalStudents={studentIds.length}
|
||||
{/* 学科 Tab */}
|
||||
{subjectOverviews.length > 0 ? (
|
||||
<Suspense fallback={<Skeleton className="h-10 w-full" />}>
|
||||
<SubjectTabs
|
||||
subjects={subjectOverviews}
|
||||
currentSubjectId={effectiveSubjectId}
|
||||
/>
|
||||
</Suspense>
|
||||
) : null}
|
||||
|
||||
{/* 班级筛选器 */}
|
||||
{classOverviews.length > 0 ? (
|
||||
<Suspense fallback={<Skeleton className="h-10 w-full" />}>
|
||||
<ClassFilter
|
||||
classes={classOverviews}
|
||||
currentClassId={effectiveClassId}
|
||||
/>
|
||||
</Suspense>
|
||||
) : null}
|
||||
|
||||
{/* 统计卡片 */}
|
||||
<AnalyticsStatsCards
|
||||
totalStudents={queryStudentIds.length}
|
||||
studentsWithErrorBook={studentsWithErrorBook.length}
|
||||
totalErrorItems={totalErrorItems}
|
||||
averageMasteryRate={averageMasteryRate}
|
||||
topWeakKnowledgePoints={weakKps}
|
||||
subjectDistribution={subjectDist}
|
||||
dueReviewCount={totalDueReview}
|
||||
knowledgePointCount={knowledgePointCount}
|
||||
/>
|
||||
|
||||
<div className="space-y-4">
|
||||
<h2 className="text-lg font-semibold">学生错题详情</h2>
|
||||
<StudentErrorTable
|
||||
students={sortedSummaries}
|
||||
studentNames={nameMap}
|
||||
basePath="/teacher/error-book"
|
||||
/>
|
||||
{/* 班级错题对比图(仅在"全部班级"视图下显示) */}
|
||||
{effectiveClassId === "all" && classOverviews.length > 1 ? (
|
||||
<ClassErrorBarChart data={classOverviews} />
|
||||
) : null}
|
||||
|
||||
{/* 章节错题分布 + 知识点薄弱度(并排) */}
|
||||
<div className="grid gap-4 lg:grid-cols-2">
|
||||
{chapterWeakness.length > 0 ? (
|
||||
<ChapterWeaknessChart data={chapterWeakness} />
|
||||
) : (
|
||||
<EmptyState
|
||||
icon={BarChart3}
|
||||
title="暂无章节错题数据"
|
||||
description="尚未关联知识点到章节,无法显示章节维度统计。"
|
||||
className="h-[300px] bg-card"
|
||||
/>
|
||||
)}
|
||||
{weakKps.length > 0 ? (
|
||||
<KnowledgePointWeaknessChart data={weakKps} />
|
||||
) : (
|
||||
<EmptyState
|
||||
icon={BarChart3}
|
||||
title="暂无知识点数据"
|
||||
description="错题尚未关联知识点,无法显示薄弱知识点统计。"
|
||||
className="h-[300px] bg-card"
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<TopWrongQuestions questions={topWrongQuestions} />
|
||||
{/* 学生错题详情(按班级分组) */}
|
||||
<div className="space-y-3">
|
||||
<div className="flex items-center justify-between">
|
||||
<h2 className="text-lg font-semibold">学生错题详情</h2>
|
||||
<span className="text-sm text-muted-foreground">
|
||||
共 {queryStudentIds.length} 名学生,{studentsWithErrorBook.length} 名有错题
|
||||
</span>
|
||||
</div>
|
||||
{sortedSummaries.length > 0 ? (
|
||||
<GroupedStudentErrorTable
|
||||
students={sortedSummaries}
|
||||
studentNames={nameMap}
|
||||
basePath="/teacher/error-book"
|
||||
/>
|
||||
) : (
|
||||
<EmptyState
|
||||
icon={BarChart3}
|
||||
title="暂无学生错题"
|
||||
description="所选范围内没有学生错题数据。"
|
||||
className="h-[200px] bg-card"
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* 高频错题 Top 10 */}
|
||||
{topWrongQuestions.length > 0 ? (
|
||||
<TopWrongQuestions questions={topWrongQuestions} />
|
||||
) : null}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default async function TeacherErrorBookPage({
|
||||
searchParams,
|
||||
}: {
|
||||
searchParams: Promise<SearchParams>
|
||||
}): Promise<JSX.Element> {
|
||||
return (
|
||||
<Suspense
|
||||
fallback={
|
||||
<div className="flex h-full flex-col space-y-8 p-8">
|
||||
<Skeleton className="h-10 w-48" />
|
||||
<Skeleton className="h-10 w-full" />
|
||||
<Skeleton className="h-10 w-full" />
|
||||
<div className="grid gap-3 sm:grid-cols-2 lg:grid-cols-5">
|
||||
{Array.from({ length: 5 }).map((_, i) => (
|
||||
<Skeleton key={i} className="h-[100px]" />
|
||||
))}
|
||||
</div>
|
||||
<Skeleton className="h-[300px] w-full" />
|
||||
</div>
|
||||
}
|
||||
>
|
||||
<TeacherErrorBookContent searchParams={searchParams} />
|
||||
</Suspense>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import type { JSX } from "react"
|
||||
import { getTeacherClasses } from "@/modules/classes/data-access"
|
||||
import { getTeacherClasses, getClassGradeIdsByClassIds } from "@/modules/classes/data-access"
|
||||
import { getClassStudentsForEntry } from "@/modules/grades/data-access"
|
||||
import { getSubjectOptions } from "@/modules/school/data-access"
|
||||
import { BatchGradeEntry } from "@/modules/grades/components/batch-grade-entry"
|
||||
import { getExamsForGradeEntry, getExamForGradeEntry } from "@/modules/exams/data-access"
|
||||
import { BatchGradeEntryByExam } from "@/modules/grades/components/batch-grade-entry"
|
||||
import { requirePermission } from "@/shared/lib/auth-guard"
|
||||
import { Permissions } from "@/shared/types/permissions"
|
||||
import { getParam, type SearchParams } from "@/shared/lib/search-params"
|
||||
@@ -19,63 +19,73 @@ export default async function BatchEntryPage({
|
||||
const ctx = await requirePermission(Permissions.GRADE_RECORD_MANAGE)
|
||||
const sp = await searchParams
|
||||
|
||||
const defaultClassId = getParam(sp, "classId")
|
||||
const defaultSubjectId = getParam(sp, "subjectId")
|
||||
const examId = getParam(sp, "examId")
|
||||
const classId = getParam(sp, "classId")
|
||||
|
||||
// P3 修复:添加 scope 校验,对 class_taught scope 限制可录入的班级
|
||||
const [classes, allSubjects, students] = await Promise.all([
|
||||
// 获取试卷列表 + 班级列表
|
||||
const [exams, teacherClasses] = await Promise.all([
|
||||
getExamsForGradeEntry(ctx.dataScope),
|
||||
getTeacherClasses(),
|
||||
getSubjectOptions(),
|
||||
defaultClassId
|
||||
? getClassStudentsForEntry(defaultClassId, ctx.dataScope)
|
||||
: Promise.resolve([] as Awaited<ReturnType<typeof getClassStudentsForEntry>>),
|
||||
])
|
||||
|
||||
// 对 class_taught scope,过滤掉不在 scope 中的班级
|
||||
// scope 过滤班级
|
||||
const allowedClassIds =
|
||||
ctx.dataScope.type === "class_taught" ? ctx.dataScope.classIds : null
|
||||
const scopedClasses = allowedClassIds
|
||||
? classes.filter((c) => allowedClassIds.includes(c.id))
|
||||
: classes
|
||||
? teacherClasses.filter((c) => allowedClassIds.includes(c.id))
|
||||
: teacherClasses
|
||||
|
||||
const classOptions = scopedClasses.map((c) => ({ id: c.id, name: c.name }))
|
||||
const subjectOptions = allSubjects.map((s) => ({ id: s.id, name: s.name }))
|
||||
|
||||
// 如果指定了 classId 但 scope 不允许,显示提示
|
||||
if (defaultClassId && students.length === 0 && scopedClasses.length > 0) {
|
||||
const classExists = scopedClasses.some((c) => c.id === defaultClassId)
|
||||
if (!classExists) {
|
||||
return (
|
||||
<div className="h-full flex-1 flex-col space-y-8 p-8 md:flex">
|
||||
<div>
|
||||
<h1 className="text-2xl font-bold tracking-tight">Batch Grade Entry</h1>
|
||||
<p className="text-muted-foreground">Enter grades for all students in a class at once.</p>
|
||||
</div>
|
||||
<EmptyState
|
||||
title="无权访问该班级"
|
||||
description="您没有权限为该班级录入成绩。"
|
||||
icon={ClipboardList}
|
||||
className="border-none shadow-none"
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
// 获取 classId → gradeId 映射(用于客户端按试卷年级过滤班级)
|
||||
const classGradeMap: Record<string, string> = {}
|
||||
if (scopedClasses.length > 0) {
|
||||
const gradeMap = await getClassGradeIdsByClassIds(
|
||||
scopedClasses.map((c) => c.id)
|
||||
)
|
||||
for (const [cid, gid] of gradeMap.entries()) {
|
||||
classGradeMap[cid] = gid
|
||||
}
|
||||
}
|
||||
|
||||
// 如果有 examId,获取试卷详情(含题目列表)
|
||||
const exam = examId
|
||||
? await getExamForGradeEntry(examId, ctx.dataScope)
|
||||
: null
|
||||
|
||||
// 如果有 examId + classId,获取学生列表
|
||||
const students =
|
||||
examId && classId
|
||||
? await getClassStudentsForEntry(classId, ctx.dataScope)
|
||||
: []
|
||||
|
||||
return (
|
||||
<div className="h-full flex-1 flex-col space-y-8 p-8 md:flex">
|
||||
<div>
|
||||
<h1 className="text-2xl font-bold tracking-tight">Batch Grade Entry</h1>
|
||||
<p className="text-muted-foreground">Enter grades for all students in a class at once.</p>
|
||||
<h1 className="text-2xl font-bold tracking-tight">批量录入成绩</h1>
|
||||
<p className="text-muted-foreground">
|
||||
从试卷库选择试卷,按每题得分录入,像填 Excel 表格一样。
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<BatchGradeEntry
|
||||
classes={classOptions}
|
||||
subjects={subjectOptions}
|
||||
students={students}
|
||||
defaultClassId={defaultClassId}
|
||||
defaultSubjectId={defaultSubjectId}
|
||||
/>
|
||||
{exams.length === 0 ? (
|
||||
<EmptyState
|
||||
title="没有可用的试卷"
|
||||
description="请先在试卷管理中创建试卷并添加题目,才能录入成绩。"
|
||||
icon={ClipboardList}
|
||||
className="border-none shadow-none"
|
||||
/>
|
||||
) : (
|
||||
<BatchGradeEntryByExam
|
||||
exams={exams}
|
||||
classes={classOptions}
|
||||
classGradeMap={classGradeMap}
|
||||
exam={exam}
|
||||
students={students}
|
||||
defaultExamId={examId}
|
||||
defaultClassId={classId}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
"use client"
|
||||
|
||||
import { useTranslations } from "next-intl"
|
||||
import { BookOpen } from "lucide-react"
|
||||
import { EmptyState } from "@/shared/components/ui/empty-state"
|
||||
|
||||
export default function EditLessonPlanError() {
|
||||
const t = useTranslations("lessonPreparation")
|
||||
return (
|
||||
<div className="p-8">
|
||||
<EmptyState
|
||||
icon={BookOpen}
|
||||
title={t("error.loadFailed")}
|
||||
description={t("error.loadFailedDesc")}
|
||||
action={{ label: t("error.retry"), onClick: () => window.location.reload() }}
|
||||
className="border-none shadow-none"
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
import { Skeleton } from "@/shared/components/ui/skeleton"
|
||||
|
||||
export default function TeacherEditLessonPlanLoading() {
|
||||
return (
|
||||
<div className="h-[calc(100vh-4rem)]">
|
||||
<div className="flex h-full items-center justify-center">
|
||||
<Skeleton className="h-[80%] w-[80%]" />
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -3,6 +3,7 @@ import { Suspense } from "react"
|
||||
import { notFound } from "next/navigation"
|
||||
import { getLessonPlanById } from "@/modules/lesson-preparation/data-access"
|
||||
import { LessonPlanEditor } from "@/modules/lesson-preparation/components/lesson-plan-editor"
|
||||
import { LessonPlanProviderSetup } from "@/modules/lesson-preparation/providers/lesson-plan-provider-setup"
|
||||
import { getTeacherClasses } from "@/modules/classes/data-access"
|
||||
import { getTextbookById, getChaptersByTextbookId } from "@/modules/textbooks/data-access"
|
||||
import { getAuthContext } from "@/shared/lib/auth-guard"
|
||||
@@ -82,26 +83,29 @@ export default async function EditLessonPlanPage({
|
||||
|
||||
return (
|
||||
<AiClientProvider service={aiClientService}>
|
||||
<div className="h-[calc(100vh-4rem)]">
|
||||
<Suspense
|
||||
fallback={
|
||||
<div className="flex h-full items-center justify-center">
|
||||
<Skeleton className="h-[80%] w-[80%]" />
|
||||
</div>
|
||||
}
|
||||
>
|
||||
<LessonPlanEditor
|
||||
planId={plan.id}
|
||||
initialTitle={plan.title}
|
||||
initialDoc={plan.content}
|
||||
textbookId={plan.textbookId ?? undefined}
|
||||
chapterId={plan.chapterId ?? undefined}
|
||||
textbookTitle={textbookTitle}
|
||||
chapterTitle={chapterTitle}
|
||||
classes={classes}
|
||||
/>
|
||||
</Suspense>
|
||||
</div>
|
||||
<LessonPlanProviderSetup>
|
||||
<div className="h-[calc(100vh-4rem)]">
|
||||
<Suspense
|
||||
fallback={
|
||||
<div className="flex h-full items-center justify-center">
|
||||
<Skeleton className="h-[80%] w-[80%]" />
|
||||
</div>
|
||||
}
|
||||
>
|
||||
<LessonPlanEditor
|
||||
planId={plan.id}
|
||||
initialTitle={plan.title}
|
||||
initialDoc={plan.content}
|
||||
initialStatus={plan.status}
|
||||
textbookId={plan.textbookId ?? undefined}
|
||||
chapterId={plan.chapterId ?? undefined}
|
||||
textbookTitle={textbookTitle}
|
||||
chapterTitle={chapterTitle}
|
||||
classes={classes}
|
||||
/>
|
||||
</Suspense>
|
||||
</div>
|
||||
</LessonPlanProviderSetup>
|
||||
</AiClientProvider>
|
||||
)
|
||||
}
|
||||
|
||||
20
src/app/(dashboard)/teacher/lesson-plans/error.tsx
Normal file
20
src/app/(dashboard)/teacher/lesson-plans/error.tsx
Normal file
@@ -0,0 +1,20 @@
|
||||
"use client"
|
||||
|
||||
import { useTranslations } from "next-intl"
|
||||
import { BookOpen } from "lucide-react"
|
||||
import { EmptyState } from "@/shared/components/ui/empty-state"
|
||||
|
||||
export default function LessonPlansError() {
|
||||
const t = useTranslations("lessonPreparation")
|
||||
return (
|
||||
<div className="p-8">
|
||||
<EmptyState
|
||||
icon={BookOpen}
|
||||
title={t("error.loadFailed")}
|
||||
description={t("error.loadFailedDesc")}
|
||||
action={{ label: t("error.retry"), onClick: () => window.location.reload() }}
|
||||
className="border-none shadow-none"
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
25
src/app/(dashboard)/teacher/lesson-plans/loading.tsx
Normal file
25
src/app/(dashboard)/teacher/lesson-plans/loading.tsx
Normal file
@@ -0,0 +1,25 @@
|
||||
import { Skeleton } from "@/shared/components/ui/skeleton"
|
||||
|
||||
export default function TeacherLessonPlansLoading() {
|
||||
return (
|
||||
<div className="p-6 space-y-4">
|
||||
<div className="flex justify-between items-center">
|
||||
<div className="space-y-2">
|
||||
<Skeleton className="h-8 w-[180px]" />
|
||||
<Skeleton className="h-4 w-[300px]" />
|
||||
</div>
|
||||
<Skeleton className="h-9 w-[120px]" />
|
||||
</div>
|
||||
<div className="flex gap-2 flex-wrap items-center">
|
||||
<Skeleton className="h-9 w-[240px]" />
|
||||
<Skeleton className="h-9 w-[160px]" />
|
||||
<Skeleton className="h-9 w-[160px]" />
|
||||
</div>
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
|
||||
{Array.from({ length: 6 }).map((_, i) => (
|
||||
<Skeleton key={i} className="h-[180px] w-full" />
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
20
src/app/(dashboard)/teacher/lesson-plans/new/error.tsx
Normal file
20
src/app/(dashboard)/teacher/lesson-plans/new/error.tsx
Normal file
@@ -0,0 +1,20 @@
|
||||
"use client"
|
||||
|
||||
import { useTranslations } from "next-intl"
|
||||
import { BookOpen } from "lucide-react"
|
||||
import { EmptyState } from "@/shared/components/ui/empty-state"
|
||||
|
||||
export default function NewLessonPlanError() {
|
||||
const t = useTranslations("lessonPreparation")
|
||||
return (
|
||||
<div className="p-8">
|
||||
<EmptyState
|
||||
icon={BookOpen}
|
||||
title={t("error.loadFailed")}
|
||||
description={t("error.loadFailedDesc")}
|
||||
action={{ label: t("error.retry"), onClick: () => window.location.reload() }}
|
||||
className="border-none shadow-none"
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
20
src/app/(dashboard)/teacher/lesson-plans/new/loading.tsx
Normal file
20
src/app/(dashboard)/teacher/lesson-plans/new/loading.tsx
Normal file
@@ -0,0 +1,20 @@
|
||||
import { Skeleton } from "@/shared/components/ui/skeleton"
|
||||
|
||||
export default function TeacherNewLessonPlanLoading() {
|
||||
return (
|
||||
<div className="p-6">
|
||||
<div className="mb-6 flex items-center gap-4">
|
||||
<Skeleton className="h-9 w-[120px]" />
|
||||
<Skeleton className="h-8 w-[180px]" />
|
||||
</div>
|
||||
<div className="max-w-3xl mx-auto p-6 space-y-6">
|
||||
<Skeleton className="h-10 w-full" />
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-3">
|
||||
{Array.from({ length: 4 }).map((_, i) => (
|
||||
<Skeleton key={i} className="h-[100px] w-full" />
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import { getTranslations } from "next-intl/server"
|
||||
import { Button } from "@/shared/components/ui/button"
|
||||
import { Skeleton } from "@/shared/components/ui/skeleton"
|
||||
import { TemplatePicker } from "@/modules/lesson-preparation/components/template-picker"
|
||||
import { LessonPlanProviderSetup } from "@/modules/lesson-preparation/providers/lesson-plan-provider-setup"
|
||||
|
||||
export const dynamic = "force-dynamic"
|
||||
|
||||
@@ -22,20 +23,22 @@ export default async function NewLessonPlanPage(): Promise<JSX.Element> {
|
||||
</Button>
|
||||
<h1 className="text-2xl font-bold tracking-tight">{t("title.new")}</h1>
|
||||
</div>
|
||||
<Suspense
|
||||
fallback={
|
||||
<div className="max-w-3xl mx-auto p-6 space-y-6">
|
||||
<Skeleton className="h-10 w-full" />
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-3">
|
||||
{Array.from({ length: 4 }).map((_, i) => (
|
||||
<Skeleton key={i} className="h-[100px] w-full" />
|
||||
))}
|
||||
<LessonPlanProviderSetup>
|
||||
<Suspense
|
||||
fallback={
|
||||
<div className="max-w-3xl mx-auto p-6 space-y-6">
|
||||
<Skeleton className="h-10 w-full" />
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-3">
|
||||
{Array.from({ length: 4 }).map((_, i) => (
|
||||
<Skeleton key={i} className="h-[100px] w-full" />
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
>
|
||||
<TemplatePicker />
|
||||
</Suspense>
|
||||
}
|
||||
>
|
||||
<TemplatePicker />
|
||||
</Suspense>
|
||||
</LessonPlanProviderSetup>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import { getAuthContext } from "@/shared/lib/auth-guard"
|
||||
import { getLessonPlans } from "@/modules/lesson-preparation/data-access"
|
||||
import { getSubjectOptions } from "@/modules/school/data-access"
|
||||
import { LessonPlanList } from "@/modules/lesson-preparation/components/lesson-plan-list"
|
||||
import { LessonPlanProviderSetup } from "@/modules/lesson-preparation/providers/lesson-plan-provider-setup"
|
||||
|
||||
export const dynamic = "force-dynamic"
|
||||
|
||||
@@ -37,24 +38,26 @@ export default async function LessonPlansPage(): Promise<JSX.Element> {
|
||||
</Link>
|
||||
</Button>
|
||||
</div>
|
||||
<Suspense
|
||||
fallback={
|
||||
<div className="space-y-4">
|
||||
<div className="flex gap-2 flex-wrap items-center">
|
||||
<Skeleton className="h-9 w-[240px]" />
|
||||
<Skeleton className="h-9 w-[160px]" />
|
||||
<Skeleton className="h-9 w-[160px]" />
|
||||
<LessonPlanProviderSetup>
|
||||
<Suspense
|
||||
fallback={
|
||||
<div className="space-y-4">
|
||||
<div className="flex gap-2 flex-wrap items-center">
|
||||
<Skeleton className="h-9 w-[240px]" />
|
||||
<Skeleton className="h-9 w-[160px]" />
|
||||
<Skeleton className="h-9 w-[160px]" />
|
||||
</div>
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
|
||||
{Array.from({ length: 6 }).map((_, i) => (
|
||||
<Skeleton key={i} className="h-[180px] w-full" />
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
|
||||
{Array.from({ length: 6 }).map((_, i) => (
|
||||
<Skeleton key={i} className="h-[180px] w-full" />
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
>
|
||||
<LessonPlanList initialItems={items} subjects={subjects} />
|
||||
</Suspense>
|
||||
}
|
||||
>
|
||||
<LessonPlanList initialItems={items} subjects={subjects} />
|
||||
</Suspense>
|
||||
</LessonPlanProviderSetup>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
27
src/app/(dashboard)/teacher/practice/error.tsx
Normal file
27
src/app/(dashboard)/teacher/practice/error.tsx
Normal file
@@ -0,0 +1,27 @@
|
||||
"use client"
|
||||
|
||||
import { useEffect } from "react"
|
||||
import { BarChart3 } from "lucide-react"
|
||||
|
||||
import { EmptyState } from "@/shared/components/ui/empty-state"
|
||||
|
||||
export default function Error() {
|
||||
useEffect(() => {
|
||||
console.error("Practice analytics page error")
|
||||
}, [])
|
||||
|
||||
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={BarChart3}
|
||||
title="加载失败"
|
||||
description="请刷新页面重试,或联系管理员检查数据访问权限。"
|
||||
className="h-[360px] bg-card"
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
17
src/app/(dashboard)/teacher/practice/loading.tsx
Normal file
17
src/app/(dashboard)/teacher/practice/loading.tsx
Normal file
@@ -0,0 +1,17 @@
|
||||
import { Skeleton } from "@/shared/components/ui/skeleton"
|
||||
|
||||
export default function Loading() {
|
||||
return (
|
||||
<div className="flex h-full flex-col space-y-8 p-8">
|
||||
<Skeleton className="h-10 w-48" />
|
||||
<Skeleton className="h-10 w-full" />
|
||||
<div className="grid gap-3 sm:grid-cols-2 lg:grid-cols-5">
|
||||
{Array.from({ length: 5 }).map((_, i) => (
|
||||
<Skeleton key={i} className="h-[100px]" />
|
||||
))}
|
||||
</div>
|
||||
<Skeleton className="h-[300px] w-full" />
|
||||
<Skeleton className="h-[280px] w-full" />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
273
src/app/(dashboard)/teacher/practice/page.tsx
Normal file
273
src/app/(dashboard)/teacher/practice/page.tsx
Normal file
@@ -0,0 +1,273 @@
|
||||
import type { Metadata } from "next"
|
||||
import type { JSX } from "react"
|
||||
import { Suspense } from "react"
|
||||
import { BarChart3 } from "lucide-react"
|
||||
import { getTranslations } from "next-intl/server"
|
||||
|
||||
import { requirePermission } from "@/shared/lib/auth-guard"
|
||||
import { Permissions } from "@/shared/types/permissions"
|
||||
import { EmptyState } from "@/shared/components/ui/empty-state"
|
||||
import { Skeleton } from "@/shared/components/ui/skeleton"
|
||||
import { getParam, type SearchParams } from "@/shared/lib/search-params"
|
||||
import {
|
||||
getClassIdsByGradeIds,
|
||||
getStudentIdsByClassIds,
|
||||
} from "@/modules/classes/data-access"
|
||||
|
||||
import {
|
||||
getTeacherClassPracticeOverviews,
|
||||
getClassStudentPracticeSummaries,
|
||||
getPracticeTypeBreakdown,
|
||||
getClassKnowledgePointWeakness,
|
||||
getStudentsWithoutPractice,
|
||||
getStudentNameMap,
|
||||
} from "@/modules/adaptive-practice/data-access-analytics"
|
||||
import { PracticeOverviewStatsCards } from "@/modules/adaptive-practice/components/practice-overview-stats-cards"
|
||||
import { ClassPracticeComparisonTable } from "@/modules/adaptive-practice/components/class-practice-comparison-table"
|
||||
import { PracticeTypeBreakdownChart } from "@/modules/adaptive-practice/components/practice-type-breakdown-chart"
|
||||
import { ClassKnowledgePointWeaknessChart } from "@/modules/adaptive-practice/components/class-knowledge-point-weakness-chart"
|
||||
import { StudentPracticeRankingTable } from "@/modules/adaptive-practice/components/student-practice-ranking-table"
|
||||
import { InactiveStudentsAlert } from "@/modules/adaptive-practice/components/inactive-students-alert"
|
||||
import { ClassFilter } from "@/modules/error-book/components/class-filter"
|
||||
import type { ClassErrorOverview } from "@/modules/error-book/types"
|
||||
|
||||
export const dynamic = "force-dynamic"
|
||||
|
||||
export async function generateMetadata(): Promise<Metadata> {
|
||||
const t = await getTranslations("practice")
|
||||
return {
|
||||
title: `${t("teacher.title")} - Next_Edu`,
|
||||
description: t("teacher.description"),
|
||||
}
|
||||
}
|
||||
|
||||
async function TeacherPracticeContent({
|
||||
searchParams,
|
||||
}: {
|
||||
searchParams: Promise<SearchParams>
|
||||
}): Promise<JSX.Element> {
|
||||
const ctx = await requirePermission(Permissions.ADAPTIVE_PRACTICE_READ)
|
||||
const t = await getTranslations("practice")
|
||||
|
||||
const params = await searchParams
|
||||
const classIds = ctx.dataScope.type === "class_taught" ? ctx.dataScope.classIds : []
|
||||
const gradeIds = ctx.dataScope.type === "grade_managed" ? ctx.dataScope.gradeIds : []
|
||||
|
||||
if (classIds.length === 0 && gradeIds.length === 0 && ctx.dataScope.type !== "all") {
|
||||
return (
|
||||
<div className="flex h-full flex-col space-y-8 p-8">
|
||||
<div>
|
||||
<h1 className="text-2xl font-bold tracking-tight">{t("teacher.title")}</h1>
|
||||
<p className="text-muted-foreground">{t("teacher.description")}</p>
|
||||
</div>
|
||||
<EmptyState
|
||||
icon={BarChart3}
|
||||
title={t("teacher.noClass")}
|
||||
description={t("teacher.noClassDescription")}
|
||||
className="h-[360px] bg-card"
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// 年级主任/教研组长:展开年级为班级
|
||||
let targetClassIds = classIds
|
||||
if (gradeIds.length > 0) {
|
||||
const gradeClassIds = await getClassIdsByGradeIds(gradeIds)
|
||||
targetClassIds = [...new Set([...classIds, ...gradeClassIds])]
|
||||
}
|
||||
|
||||
// 获取所有学生 ID
|
||||
const allStudentIds = await getStudentIdsByClassIds(targetClassIds)
|
||||
|
||||
if (allStudentIds.length === 0) {
|
||||
return (
|
||||
<div className="flex h-full flex-col space-y-8 p-8">
|
||||
<div>
|
||||
<h1 className="text-2xl font-bold tracking-tight">{t("teacher.title")}</h1>
|
||||
<p className="text-muted-foreground">{t("teacher.description")}</p>
|
||||
</div>
|
||||
<EmptyState
|
||||
icon={BarChart3}
|
||||
title={t("teacher.noStudent")}
|
||||
description={t("teacher.noStudentDescription")}
|
||||
className="h-[360px] bg-card"
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// 解析 URL 参数:班级筛选
|
||||
const classParam = getParam(params, "classId")
|
||||
const effectiveClassId = classParam ?? "all"
|
||||
|
||||
// 班级概览(用于班级筛选器显示)
|
||||
const classOverviews = await getTeacherClassPracticeOverviews(targetClassIds)
|
||||
|
||||
// 构造 ClassFilter 所需的数据格式
|
||||
const classFilterData: ClassErrorOverview[] = classOverviews.map((c) => ({
|
||||
classId: c.classId,
|
||||
className: c.className,
|
||||
studentCount: c.totalStudents,
|
||||
totalErrorItems: c.totalSessions,
|
||||
dueReviewCount: 0,
|
||||
averageErrorPerStudent: c.totalStudents > 0 ? c.totalSessions / c.totalStudents : 0,
|
||||
averageMasteryRate: c.averageAccuracy,
|
||||
}))
|
||||
|
||||
// 确定查询的班级范围
|
||||
const queryClassIds = effectiveClassId === "all" ? targetClassIds : [effectiveClassId]
|
||||
const queryStudentIds = await getStudentIdsByClassIds(queryClassIds)
|
||||
|
||||
// 并行查询所有统计数据
|
||||
const [typeBreakdown, studentSummaries, nameMap, inactiveIds] = await Promise.all([
|
||||
getPracticeTypeBreakdown(queryStudentIds),
|
||||
// 按班级查询学生摘要(如果是单班级视图,直接查询;如果是全部视图,按班级逐个查询后合并)
|
||||
effectiveClassId === "all"
|
||||
? getClassStudentPracticeSummariesForClasses(queryClassIds)
|
||||
: getClassStudentPracticeSummaries(effectiveClassId),
|
||||
getStudentNameMap(queryStudentIds),
|
||||
effectiveClassId === "all"
|
||||
? getInactiveStudentsForClasses(queryClassIds)
|
||||
: getStudentsWithoutPractice(effectiveClassId),
|
||||
])
|
||||
|
||||
// 聚合统计
|
||||
const totalSessions = classOverviews.reduce((sum, c) => sum + c.totalSessions, 0)
|
||||
const totalAnswered = classOverviews.reduce((sum, c) => sum + c.totalQuestionsAnswered, 0)
|
||||
const totalCorrect = classOverviews.reduce((sum, c) => sum + c.totalCorrect, 0)
|
||||
const totalActiveStudents = classOverviews.reduce((sum, c) => sum + c.activeStudents, 0)
|
||||
const totalStudents = classOverviews.reduce((sum, c) => sum + c.totalStudents, 0)
|
||||
const averageAccuracy = totalAnswered > 0 ? totalCorrect / totalAnswered : 0
|
||||
const participationRate = totalStudents > 0 ? totalActiveStudents / totalStudents : 0
|
||||
|
||||
// 单班级视图:查询知识点薄弱度
|
||||
const weakKps = effectiveClassId !== "all"
|
||||
? await getClassKnowledgePointWeakness(effectiveClassId, 10)
|
||||
: []
|
||||
|
||||
const hasData = totalSessions > 0
|
||||
|
||||
if (!hasData) {
|
||||
return (
|
||||
<div className="flex h-full flex-col space-y-8 p-8">
|
||||
<div>
|
||||
<h1 className="text-2xl font-bold tracking-tight">{t("teacher.title")}</h1>
|
||||
<p className="text-muted-foreground">{t("teacher.description")}</p>
|
||||
</div>
|
||||
<EmptyState
|
||||
icon={BarChart3}
|
||||
title={t("teacher.noData")}
|
||||
description={t("teacher.noDataDescription")}
|
||||
className="h-[360px] bg-card"
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex h-full flex-col space-y-6 p-8">
|
||||
<div>
|
||||
<h1 className="text-2xl font-bold tracking-tight">{t("teacher.title")}</h1>
|
||||
<p className="text-muted-foreground">{t("teacher.description")}</p>
|
||||
</div>
|
||||
|
||||
{/* 班级筛选器 */}
|
||||
{classFilterData.length > 0 ? (
|
||||
<Suspense fallback={<Skeleton className="h-10 w-full" />}>
|
||||
<ClassFilter
|
||||
classes={classFilterData}
|
||||
currentClassId={effectiveClassId}
|
||||
/>
|
||||
</Suspense>
|
||||
) : null}
|
||||
|
||||
{/* 统计卡片 */}
|
||||
<PracticeOverviewStatsCards
|
||||
totalClasses={classOverviews.length}
|
||||
totalSessions={totalSessions}
|
||||
totalAnswered={totalAnswered}
|
||||
averageAccuracy={averageAccuracy}
|
||||
participationRate={participationRate}
|
||||
/>
|
||||
|
||||
{/* 班级对比表(仅在"全部班级"视图下显示) */}
|
||||
{effectiveClassId === "all" && classOverviews.length > 1 ? (
|
||||
<ClassPracticeComparisonTable data={classOverviews} />
|
||||
) : null}
|
||||
|
||||
{/* 练习类型分布图 */}
|
||||
{typeBreakdown.length > 0 ? (
|
||||
<PracticeTypeBreakdownChart data={typeBreakdown} />
|
||||
) : null}
|
||||
|
||||
{/* 知识点薄弱度(仅在单班级视图下显示) */}
|
||||
{effectiveClassId !== "all" ? (
|
||||
<ClassKnowledgePointWeaknessChart data={weakKps} />
|
||||
) : null}
|
||||
|
||||
{/* 学生练习排名 */}
|
||||
{studentSummaries.length > 0 ? (
|
||||
<StudentPracticeRankingTable data={studentSummaries} studentNames={nameMap} />
|
||||
) : null}
|
||||
|
||||
{/* 未参与练习学生提醒 */}
|
||||
<InactiveStudentsAlert
|
||||
inactiveStudentIds={inactiveIds}
|
||||
studentNames={nameMap}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取多个班级的学生练习摘要(合并结果)。
|
||||
*
|
||||
* 用于"全部班级"视图,按班级逐个查询后合并。
|
||||
*/
|
||||
async function getClassStudentPracticeSummariesForClasses(
|
||||
classIds: string[],
|
||||
) {
|
||||
const results = await Promise.all(
|
||||
classIds.map((classId) => getClassStudentPracticeSummaries(classId)),
|
||||
)
|
||||
// 合并并按练习数降序排列
|
||||
return results.flat().sort((a, b) => b.totalSessions - a.totalSessions)
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取多个班级中未参与练习的学生 ID 列表(合并结果)。
|
||||
*/
|
||||
async function getInactiveStudentsForClasses(
|
||||
classIds: string[],
|
||||
): Promise<string[]> {
|
||||
const results = await Promise.all(
|
||||
classIds.map((classId) => getStudentsWithoutPractice(classId)),
|
||||
)
|
||||
return results.flat()
|
||||
}
|
||||
|
||||
export default async function TeacherPracticePage({
|
||||
searchParams,
|
||||
}: {
|
||||
searchParams: Promise<SearchParams>
|
||||
}): Promise<JSX.Element> {
|
||||
return (
|
||||
<Suspense
|
||||
fallback={
|
||||
<div className="flex h-full flex-col space-y-8 p-8">
|
||||
<Skeleton className="h-10 w-48" />
|
||||
<Skeleton className="h-10 w-full" />
|
||||
<div className="grid gap-3 sm:grid-cols-2 lg:grid-cols-5">
|
||||
{Array.from({ length: 5 }).map((_, i) => (
|
||||
<Skeleton key={i} className="h-[100px]" />
|
||||
))}
|
||||
</div>
|
||||
<Skeleton className="h-[300px] w-full" />
|
||||
</div>
|
||||
}
|
||||
>
|
||||
<TeacherPracticeContent searchParams={searchParams} />
|
||||
</Suspense>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user