feat(app): add error/loading boundaries and update dashboard routes
- Add error.tsx and loading.tsx boundaries for admin, parent, student, teacher routes - Add dashboard-error-fallback and dashboard-loading-skeleton components - Add student/learning page, parent/leave routes, teacher textbook components - Update existing app routes across auth, dashboard, and API endpoints - Update proxy middleware and next-auth type declarations
This commit is contained in:
@@ -13,6 +13,7 @@ import { getSubjectOptions } from "@/modules/school/data-access"
|
||||
|
||||
import {
|
||||
getClassComparison,
|
||||
getExamOptionsForGrades,
|
||||
getGradeDistribution,
|
||||
getGradeTrend,
|
||||
getSubjectComparison,
|
||||
@@ -22,6 +23,7 @@ import { ClassComparisonChart } from "@/modules/grades/components/class-comparis
|
||||
import { SubjectComparisonChart } from "@/modules/grades/components/subject-comparison-chart"
|
||||
import { GradeDistributionChart } from "@/modules/grades/components/grade-distribution-chart"
|
||||
import { AnalyticsFilters } from "@/modules/grades/components/analytics-filters"
|
||||
import { WidgetBoundary } from "@/modules/grades/components/widget-boundary"
|
||||
|
||||
export const dynamic = "force-dynamic"
|
||||
|
||||
@@ -36,6 +38,9 @@ export default async function GradeAnalyticsPage({
|
||||
const classId = getParam(sp, "classId")
|
||||
const subjectId = getParam(sp, "subjectId")
|
||||
const gradeId = getParam(sp, "gradeId")
|
||||
// v3-P2-7: 学期和考试筛选
|
||||
const examId = getParam(sp, "examId")
|
||||
const semester = getParam(sp, "semester")
|
||||
|
||||
const [classes, allGrades, allSubjects] = await Promise.all([
|
||||
getTeacherClasses(),
|
||||
@@ -66,33 +71,50 @@ export default async function GradeAnalyticsPage({
|
||||
const targetSubjectId =
|
||||
subjectId && subjectId !== "all" ? subjectId : undefined
|
||||
const targetGradeId = gradeId ?? allGrades[0]?.id
|
||||
// v3-P2-7: 解析 semester 和 examId
|
||||
const targetSemester: "1" | "2" | undefined =
|
||||
semester === "1" || semester === "2" ? semester : undefined
|
||||
const targetExamId = examId && examId !== "all" ? examId : undefined
|
||||
|
||||
// Run analytics queries in parallel
|
||||
const [trend, distribution, subjectComparison, classComparison] =
|
||||
const [trend, distribution, subjectComparison, classComparison, examOptions] =
|
||||
await Promise.all([
|
||||
getGradeTrend({
|
||||
classId: targetClassId,
|
||||
subjectId: targetSubjectId,
|
||||
semester: targetSemester,
|
||||
examId: targetExamId,
|
||||
scope: ctx.dataScope,
|
||||
currentUserId: ctx.userId,
|
||||
}),
|
||||
getGradeDistribution({
|
||||
classId: targetClassId,
|
||||
subjectId: targetSubjectId,
|
||||
examId: targetExamId,
|
||||
semester: targetSemester,
|
||||
scope: ctx.dataScope,
|
||||
currentUserId: ctx.userId,
|
||||
}),
|
||||
getSubjectComparison({
|
||||
classId: targetClassId,
|
||||
examId: targetExamId,
|
||||
semester: targetSemester,
|
||||
scope: ctx.dataScope,
|
||||
}),
|
||||
targetGradeId
|
||||
? getClassComparison({
|
||||
gradeId: targetGradeId,
|
||||
subjectId: targetSubjectId ?? allSubjects[0]?.id ?? "",
|
||||
examId: targetExamId,
|
||||
semester: targetSemester,
|
||||
scope: ctx.dataScope,
|
||||
})
|
||||
: Promise.resolve([]),
|
||||
getExamOptionsForGrades({
|
||||
classId: targetClassId,
|
||||
subjectId: targetSubjectId,
|
||||
scope: ctx.dataScope,
|
||||
}),
|
||||
])
|
||||
|
||||
return (
|
||||
@@ -116,16 +138,63 @@ export default async function GradeAnalyticsPage({
|
||||
classes={classes.map((c) => ({ id: c.id, name: c.name }))}
|
||||
grades={allGrades.map((g) => ({ id: g.id, name: g.name }))}
|
||||
subjects={allSubjects.map((s) => ({ id: s.id, name: s.name ?? "Unknown" }))}
|
||||
exams={examOptions}
|
||||
currentClassId={targetClassId}
|
||||
currentSubjectId={subjectId ?? "all"}
|
||||
currentGradeId={targetGradeId ?? ""}
|
||||
currentExamId={examId ?? "all"}
|
||||
currentSemester={semester ?? "all"}
|
||||
/>
|
||||
|
||||
<div className="grid grid-cols-1 gap-6 lg:grid-cols-2">
|
||||
<GradeTrendChart data={trend} />
|
||||
<GradeDistributionChart data={distribution} />
|
||||
<SubjectComparisonChart data={subjectComparison} />
|
||||
<ClassComparisonChart data={classComparison} />
|
||||
<WidgetBoundary title="成绩趋势">
|
||||
{trend ? (
|
||||
<GradeTrendChart data={trend} />
|
||||
) : (
|
||||
<EmptyState
|
||||
title="暂无趋势数据"
|
||||
description="当前筛选条件下没有可显示的成绩趋势。"
|
||||
icon={BarChart3}
|
||||
className="border-none shadow-none"
|
||||
/>
|
||||
)}
|
||||
</WidgetBoundary>
|
||||
<WidgetBoundary title="分数分布">
|
||||
{distribution.totalCount > 0 ? (
|
||||
<GradeDistributionChart data={distribution} />
|
||||
) : (
|
||||
<EmptyState
|
||||
title="暂无分布数据"
|
||||
description="当前筛选条件下没有可显示的分数分布。"
|
||||
icon={BarChart3}
|
||||
className="border-none shadow-none"
|
||||
/>
|
||||
)}
|
||||
</WidgetBoundary>
|
||||
<WidgetBoundary title="科目对比">
|
||||
{subjectComparison.length > 0 ? (
|
||||
<SubjectComparisonChart data={subjectComparison} />
|
||||
) : (
|
||||
<EmptyState
|
||||
title="暂无科目对比数据"
|
||||
description="当前筛选条件下没有可显示的科目对比。"
|
||||
icon={BarChart3}
|
||||
className="border-none shadow-none"
|
||||
/>
|
||||
)}
|
||||
</WidgetBoundary>
|
||||
<WidgetBoundary title="班级对比">
|
||||
{classComparison.length > 0 ? (
|
||||
<ClassComparisonChart data={classComparison} />
|
||||
) : (
|
||||
<EmptyState
|
||||
title="暂无班级对比数据"
|
||||
description="当前筛选条件下没有可显示的班级对比。"
|
||||
icon={BarChart3}
|
||||
className="border-none shadow-none"
|
||||
/>
|
||||
)}
|
||||
</WidgetBoundary>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
|
||||
@@ -3,7 +3,11 @@ import { getTeacherClasses } 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 { requirePermission } from "@/shared/lib/auth-guard"
|
||||
import { Permissions } from "@/shared/types/permissions"
|
||||
import { getParam, type SearchParams } from "@/shared/lib/search-params"
|
||||
import { EmptyState } from "@/shared/components/ui/empty-state"
|
||||
import { ClipboardList } from "lucide-react"
|
||||
|
||||
export const dynamic = "force-dynamic"
|
||||
|
||||
@@ -12,22 +16,52 @@ export default async function BatchEntryPage({
|
||||
}: {
|
||||
searchParams: Promise<SearchParams>
|
||||
}): Promise<JSX.Element> {
|
||||
const ctx = await requirePermission(Permissions.GRADE_RECORD_MANAGE)
|
||||
const sp = await searchParams
|
||||
|
||||
const defaultClassId = getParam(sp, "classId")
|
||||
const defaultSubjectId = getParam(sp, "subjectId")
|
||||
|
||||
// P3 修复:添加 scope 校验,对 class_taught scope 限制可录入的班级
|
||||
const [classes, allSubjects, students] = await Promise.all([
|
||||
getTeacherClasses(),
|
||||
getSubjectOptions(),
|
||||
defaultClassId
|
||||
? getClassStudentsForEntry(defaultClassId)
|
||||
? getClassStudentsForEntry(defaultClassId, ctx.dataScope)
|
||||
: Promise.resolve([] as Awaited<ReturnType<typeof getClassStudentsForEntry>>),
|
||||
])
|
||||
|
||||
const classOptions = classes.map((c) => ({ id: c.id, name: c.name }))
|
||||
// 对 class_taught scope,过滤掉不在 scope 中的班级
|
||||
const allowedClassIds =
|
||||
ctx.dataScope.type === "class_taught" ? ctx.dataScope.classIds : null
|
||||
const scopedClasses = allowedClassIds
|
||||
? classes.filter((c) => allowedClassIds.includes(c.id))
|
||||
: classes
|
||||
|
||||
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>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="h-full flex-1 flex-col space-y-8 p-8 md:flex">
|
||||
<div>
|
||||
|
||||
@@ -3,7 +3,7 @@ import Link from "next/link"
|
||||
import { PlusCircle, BarChart3, ClipboardList } from "lucide-react"
|
||||
import { Button } from "@/shared/components/ui/button"
|
||||
import { EmptyState } from "@/shared/components/ui/empty-state"
|
||||
import { ListPagination, computePagination, paginate } from "@/shared/components/ui/list-pagination"
|
||||
import { ListPagination, computePagination } from "@/shared/components/ui/list-pagination"
|
||||
import { requirePermission } from "@/shared/lib/auth-guard"
|
||||
import { Permissions } from "@/shared/types/permissions"
|
||||
import { getParam, type SearchParams } from "@/shared/lib/search-params"
|
||||
@@ -43,7 +43,11 @@ export default async function TeacherGradesPage({
|
||||
const type = getParam(sp, "type")
|
||||
const semester = getParam(sp, "semester")
|
||||
|
||||
const [classes, allSubjects, records] = await Promise.all([
|
||||
// P3 修复:使用 DB 层分页,移除重复计算
|
||||
const { page } = computePagination(sp, PAGE_SIZE)
|
||||
const offset = (page - 1) * PAGE_SIZE
|
||||
|
||||
const [classes, allSubjects, result] = await Promise.all([
|
||||
getTeacherClasses(),
|
||||
getSubjectOptions(),
|
||||
getGradeRecords({
|
||||
@@ -53,18 +57,19 @@ export default async function TeacherGradesPage({
|
||||
subjectId: subjectId && subjectId !== "all" ? subjectId : undefined,
|
||||
type: type && type !== "all" ? parseGradeType(type) : undefined,
|
||||
semester: semester && semester !== "all" ? parseSemester(semester) : undefined,
|
||||
limit: PAGE_SIZE,
|
||||
offset,
|
||||
}),
|
||||
])
|
||||
|
||||
const classOptions = classes.map((c) => ({ id: c.id, name: c.name }))
|
||||
const subjectOptions = allSubjects.map((s) => ({ id: s.id, name: s.name }))
|
||||
|
||||
// 分页计算
|
||||
const { page } = computePagination(sp, PAGE_SIZE)
|
||||
const total = records.length
|
||||
// 使用 DB 返回的 total 和 totalPages,移除重复计算
|
||||
const total = result.total
|
||||
const totalPages = Math.max(1, Math.ceil(total / PAGE_SIZE))
|
||||
const currentPage = Math.min(page, totalPages)
|
||||
const pagedRecords = paginate(records, currentPage, PAGE_SIZE)
|
||||
const pagedRecords = result.records
|
||||
const hasFilters = Boolean(classId || subjectId || type || semester)
|
||||
|
||||
return (
|
||||
@@ -103,7 +108,7 @@ export default async function TeacherGradesPage({
|
||||
|
||||
<GradeQueryFilters classes={classOptions} subjects={subjectOptions} />
|
||||
|
||||
{records.length === 0 && !hasFilters ? (
|
||||
{total === 0 && !hasFilters ? (
|
||||
<EmptyState
|
||||
title="暂无成绩记录"
|
||||
description="开始为您的班级录入成绩。"
|
||||
|
||||
@@ -6,6 +6,8 @@ import { ClassGradeReport } from "@/modules/grades/components/class-grade-report
|
||||
import { ExportButton } from "@/modules/grades/components/export-button"
|
||||
import { StatsClassSelector } from "@/modules/grades/components/stats-class-selector"
|
||||
import { EmptyState } from "@/shared/components/ui/empty-state"
|
||||
import { requirePermission } from "@/shared/lib/auth-guard"
|
||||
import { Permissions } from "@/shared/types/permissions"
|
||||
import { getParam, type SearchParams } from "@/shared/lib/search-params"
|
||||
import { BarChart3 } from "lucide-react"
|
||||
|
||||
@@ -16,6 +18,7 @@ export default async function StatsPage({
|
||||
}: {
|
||||
searchParams: Promise<SearchParams>
|
||||
}): Promise<JSX.Element> {
|
||||
const ctx = await requirePermission(Permissions.GRADE_RECORD_READ)
|
||||
const sp = await searchParams
|
||||
|
||||
const classId = getParam(sp, "classId")
|
||||
@@ -43,15 +46,52 @@ export default async function StatsPage({
|
||||
)
|
||||
}
|
||||
|
||||
const targetClassId = classId ?? classes[0].id
|
||||
// P3 修复:对 class_taught scope 过滤可选班级
|
||||
const allowedClassIds =
|
||||
ctx.dataScope.type === "class_taught" ? ctx.dataScope.classIds : null
|
||||
const scopedClasses = allowedClassIds
|
||||
? classes.filter((c) => allowedClassIds.includes(c.id))
|
||||
: classes
|
||||
|
||||
if (scopedClasses.length === 0) {
|
||||
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">Grade Statistics</h1>
|
||||
<p className="text-muted-foreground">View class grade statistics and rankings.</p>
|
||||
</div>
|
||||
<EmptyState
|
||||
title="No accessible classes"
|
||||
description="You don't have permission to view any classes."
|
||||
icon={BarChart3}
|
||||
className="border-none shadow-none"
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
const targetClassId = classId ?? scopedClasses[0].id
|
||||
const targetSubjectId = subjectId && subjectId !== "all" ? subjectId : undefined
|
||||
|
||||
// P3 修复:传递 scope 到 data-access 层
|
||||
const [stats, ranking] = await Promise.all([
|
||||
getClassGradeStatsWithMeta(targetClassId, targetSubjectId),
|
||||
getClassRanking(targetClassId, targetSubjectId),
|
||||
getClassGradeStatsWithMeta(
|
||||
targetClassId,
|
||||
targetSubjectId,
|
||||
undefined,
|
||||
ctx.dataScope,
|
||||
ctx.userId
|
||||
),
|
||||
getClassRanking(
|
||||
targetClassId,
|
||||
targetSubjectId,
|
||||
undefined,
|
||||
ctx.dataScope,
|
||||
ctx.userId
|
||||
),
|
||||
])
|
||||
|
||||
const classOptions = classes.map((c) => ({ id: c.id, name: c.name }))
|
||||
const classOptions = scopedClasses.map((c) => ({ id: c.id, name: c.name }))
|
||||
const subjectOptions = allSubjects.map((s) => ({ id: s.id, name: s.name }))
|
||||
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user