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:
SpecialX
2026-06-23 17:38:28 +08:00
parent c4d3433cc9
commit 1a9377222c
90 changed files with 1690 additions and 741 deletions

View File

@@ -0,0 +1,24 @@
"use client"
import { AlertCircle } from "lucide-react"
import { useTranslations } from "next-intl"
import { EmptyState } from "@/shared/components/ui/empty-state"
export default function StudentAttendanceError({ reset }: { error: Error & { digest?: string }; reset: () => void }) {
const t = useTranslations("attendance")
return (
<div className="flex h-full flex-col items-center justify-center space-y-4 p-8">
<EmptyState
icon={AlertCircle}
title={t("errors.unexpected")}
description={t("errors.unexpected")}
action={{
label: t("actions.save"),
onClick: () => reset(),
}}
className="border-none shadow-none h-auto"
/>
</div>
)
}

View File

@@ -0,0 +1,7 @@
"use client"
import { DashboardErrorFallback } from "@/modules/dashboard/components/dashboard-error-fallback"
export default function StudentDashboardError({ error, reset }: { error: Error & { digest?: string }; reset: () => void }) {
return <DashboardErrorFallback error={error} reset={reset} />
}

View File

@@ -1,61 +1,5 @@
import { Card, CardContent, CardHeader, CardTitle } from "@/shared/components/ui/card"
import { Skeleton } from "@/shared/components/ui/skeleton"
import { DashboardLoadingSkeleton } from "@/modules/dashboard/components/dashboard-loading-skeleton"
export default function Loading() {
return (
<div className="space-y-6">
<div className="flex flex-col justify-between gap-4 md:flex-row md:items-center">
<div className="space-y-2">
<Skeleton className="h-9 w-48" />
<Skeleton className="h-4 w-56" />
</div>
<Skeleton className="h-10 w-40" />
</div>
<div className="grid gap-4 md:grid-cols-2 lg:grid-cols-4">
{Array.from({ length: 4 }).map((_, i) => (
<Card key={i}>
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
<Skeleton className="h-4 w-24" />
<Skeleton className="h-4 w-4 rounded-full" />
</CardHeader>
<CardContent>
<Skeleton className="h-8 w-16" />
<Skeleton className="mt-2 h-3 w-28" />
</CardContent>
</Card>
))}
</div>
<div className="grid gap-4 md:grid-cols-2 lg:grid-cols-7">
<Card className="lg:col-span-3">
<CardHeader>
<CardTitle className="text-sm">
<Skeleton className="h-4 w-40" />
</CardTitle>
</CardHeader>
<CardContent className="space-y-3">
{Array.from({ length: 4 }).map((_, i) => (
<Skeleton key={i} className="h-10 w-full" />
))}
</CardContent>
</Card>
<Card className="lg:col-span-4">
<CardHeader className="flex flex-row items-center justify-between">
<CardTitle className="text-sm">
<Skeleton className="h-4 w-44" />
</CardTitle>
<Skeleton className="h-9 w-24" />
</CardHeader>
<CardContent className="space-y-2">
{Array.from({ length: 5 }).map((_, i) => (
<Skeleton key={i} className="h-10 w-full" />
))}
</CardContent>
</Card>
</div>
</div>
)
export default function StudentDashboardLoading() {
return <DashboardLoadingSkeleton />
}

View File

@@ -0,0 +1,27 @@
"use client"
import { AlertCircle } from "lucide-react"
import { EmptyState } from "@/shared/components/ui/empty-state"
export default function StudentDiagnosticError({
reset,
}: {
error: Error & { digest?: string }
reset: () => void
}) {
return (
<div className="flex h-full flex-col items-center justify-center space-y-4 p-8">
<EmptyState
icon={AlertCircle}
title="学情诊断页面加载失败"
description="抱歉,页面加载时发生了意外错误。请稍后重试。"
action={{
label: "重试",
onClick: () => reset(),
}}
className="border-none shadow-none h-auto"
/>
</div>
)
}

View File

@@ -1,5 +1,6 @@
import { Stethoscope } from "lucide-react"
import { getAuthContext } from "@/shared/lib/auth-guard"
import { requirePermission } from "@/shared/lib/auth-guard"
import { Permissions } from "@/shared/types/permissions"
import { getStudentMasterySummary } from "@/modules/diagnostic/data-access"
import { getDiagnosticReports } from "@/modules/diagnostic/data-access-reports"
import { StudentDiagnosticView } from "@/modules/diagnostic/components/student-diagnostic-view"
@@ -7,15 +8,20 @@ import { StudentDiagnosticView } from "@/modules/diagnostic/components/student-d
export const dynamic = "force-dynamic"
export default async function StudentDiagnosticPage() {
const ctx = await getAuthContext()
const ctx = await requirePermission(Permissions.DIAGNOSTIC_READ)
const [summary, reports] = await Promise.all([
const [summary, reportsResult] = await Promise.all([
getStudentMasterySummary(ctx.userId),
getDiagnosticReports({ studentId: ctx.userId }),
// v4-P1-3: 学生仅可见已发布报告,避免草稿泄露
getDiagnosticReports(
{ studentId: ctx.userId, status: "published" },
ctx.dataScope,
),
])
const reports = reportsResult.reports
return (
<div className="h-full flex-1 flex-col space-y-8 p-8 md:flex">
<div className="space-y-8">
<div>
<h2 className="flex items-center gap-2 text-2xl font-bold tracking-tight">
<Stethoscope className="h-6 w-6" />

View File

@@ -0,0 +1,27 @@
"use client"
import { AlertCircle } from "lucide-react"
import { EmptyState } from "@/shared/components/ui/empty-state"
export default function StudentGradesError({
reset,
}: {
error: Error & { digest?: string }
reset: () => void
}) {
return (
<div className="flex h-full flex-col items-center justify-center space-y-4 p-8">
<EmptyState
icon={AlertCircle}
title="成绩查询页面加载失败"
description="抱歉,页面加载时发生了意外错误。请稍后重试。"
action={{
label: "重试",
onClick: () => reset(),
}}
className="border-none shadow-none h-auto"
/>
</div>
)
}

View File

@@ -1,9 +1,13 @@
import { getTranslations } from "next-intl/server"
import { requirePermission } from "@/shared/lib/auth-guard"
import { Permissions } from "@/shared/types/permissions"
import { getStudentGradeSummary } from "@/modules/grades/data-access"
import { getRankingTrend, getClassAverageTrend } from "@/modules/grades/data-access-ranking"
import { getSubjectOptions } from "@/modules/school/data-access"
import { StudentGradeSummary } from "@/modules/grades/components/student-grade-summary"
import { GradeFilters } from "@/modules/grades/components/grade-filters"
import { GradeTrendCard } from "@/modules/grades/components/grade-trend-card"
import { RankingTrendCard } from "@/modules/grades/components/ranking-trend-card"
import { EmptyState } from "@/shared/components/ui/empty-state"
import { UserX } from "lucide-react"
import { getParam, type SearchParams } from "@/shared/lib/search-params"
@@ -16,21 +20,28 @@ export default async function StudentGradesPage({
searchParams: Promise<SearchParams>
}) {
const ctx = await requirePermission(Permissions.GRADE_RECORD_READ)
const [sp, summary] = await Promise.all([
const [sp, summary, rankingTrend, classAverageTrend, subjectOptions] = await Promise.all([
searchParams,
getStudentGradeSummary(ctx.userId),
getStudentGradeSummary(ctx.userId, ctx.dataScope),
// v3-P1-3接入排名趋势图
getRankingTrend(ctx.userId, undefined, undefined, ctx.dataScope),
// v3-P2-2接入班级平均趋势对比线
getClassAverageTrend(ctx.userId, undefined, undefined, ctx.dataScope),
// v3-P2-1获取科目列表用于过滤器
getSubjectOptions(),
])
if (!summary) {
const t = await getTranslations("grades")
return (
<div className="space-y-8">
<div>
<h2 className="text-2xl font-bold tracking-tight">My Grades</h2>
<p className="text-muted-foreground">View your grade records.</p>
<h2 className="text-2xl font-bold tracking-tight">{t("title.myGrades")}</h2>
<p className="text-muted-foreground">{t("summary.noDataDescription")}</p>
</div>
<EmptyState
title="No user found"
description="Unable to load your student profile."
title={t("summary.noDataTitle")}
description={t("summary.noDataDescription")}
icon={UserX}
className="border-none shadow-none"
/>
@@ -46,7 +57,8 @@ export default async function StudentGradesPage({
const filteredRecords = summary.records.filter((r) => {
if (q && !r.title.toLowerCase().includes(q)) return false
if (subjectFilter !== "all" && r.subjectName !== subjectFilter) return false
// v3-P2-1 修复:按 subjectId 而非 subjectName 过滤
if (subjectFilter !== "all" && r.subjectId !== subjectFilter) return false
if (typeFilter !== "all" && r.type !== typeFilter) return false
if (semesterFilter !== "all" && r.semester !== semesterFilter) return false
return true
@@ -60,11 +72,16 @@ export default async function StudentGradesPage({
return (
<div className="space-y-8">
<div>
<h2 className="text-2xl font-bold tracking-tight">My Grades</h2>
<p className="text-muted-foreground">View your grade records.</p>
<h2 className="text-2xl font-bold tracking-tight">{summary.studentName}</h2>
<p className="text-muted-foreground">{summary.records.length} </p>
</div>
<GradeFilters />
{filteredSummary.records.length > 0 && <GradeTrendCard summary={filteredSummary} />}
<GradeFilters subjects={subjectOptions.map((s) => ({ id: s.id, name: s.name }))} />
{filteredSummary.records.length > 0 && (
<div className="grid grid-cols-1 gap-6 lg:grid-cols-2">
<GradeTrendCard summary={filteredSummary} classAverageData={classAverageTrend} />
<RankingTrendCard trend={rankingTrend} />
</div>
)}
<StudentGradeSummary summary={filteredSummary} />
</div>
)

View File

@@ -24,7 +24,7 @@ export default async function StudentAssignmentTakePage({
const status = data.submission?.status
if (status === "graded" || status === "submitted") {
return (
<div className="h-full flex-1 flex-col space-y-8 p-8 md:flex">
<div className="space-y-8">
<div className="flex flex-col gap-1">
<h2 className="text-2xl font-bold tracking-tight">{data.assignment.title}</h2>
<div className="text-sm text-muted-foreground">
@@ -38,7 +38,7 @@ export default async function StudentAssignmentTakePage({
}
return (
<div className="flex h-full flex-col space-y-4 p-6">
<div className="space-y-4">
<div className="flex flex-col gap-1">
<h2 className="text-2xl font-bold tracking-tight">{data.assignment.title}</h2>
<div className="text-sm text-muted-foreground">

View File

@@ -6,6 +6,7 @@ import { Button } from "@/shared/components/ui/button"
import { Card, CardContent, CardHeader, CardTitle } from "@/shared/components/ui/card"
import { StatusBadge } from "@/shared/components/ui/status-badge"
import { formatDate, cn } from "@/shared/lib/utils"
import { getParam, type SearchParams } from "@/shared/lib/search-params"
import { getStudentHomeworkAssignments } from "@/modules/homework/data-access"
import { getCurrentStudentUser } from "@/modules/users/data-access"
import { AssignmentFilters } from "@/modules/homework/components/assignment-filters"
@@ -20,13 +21,6 @@ import {
export const dynamic = "force-dynamic"
type SearchParams = { [key: string]: string | string[] | undefined }
const getParam = (params: SearchParams, key: string) => {
const v = params[key]
return Array.isArray(v) ? v[0] : v
}
const getActionLabel = (status: StudentHomeworkProgressStatus, t: (key: string) => string): string => {
switch (status) {
case "graded":

View File

@@ -3,7 +3,7 @@ import { Skeleton } from "@/shared/components/ui/skeleton"
export default function Loading() {
return (
<div className="flex h-full flex-col space-y-8 p-8">
<div className="space-y-8">
<div className="space-y-2">
<Skeleton className="h-8 w-40" />
<Skeleton className="h-4 w-52" />

View File

@@ -5,16 +5,10 @@ import { getCurrentStudentUser } from "@/modules/users/data-access"
import { StudentCoursesView } from "@/modules/student/components/student-courses-view"
import { CourseFilters } from "@/modules/student/components/course-filters"
import { EmptyState } from "@/shared/components/ui/empty-state"
import { getParam, type SearchParams } from "@/shared/lib/search-params"
export const dynamic = "force-dynamic"
type SearchParams = { [key: string]: string | string[] | undefined }
const getParam = (params: SearchParams, key: string) => {
const v = params[key]
return Array.isArray(v) ? v[0] : v
}
export default async function StudentCoursesPage({
searchParams,
}: {

View File

@@ -0,0 +1,93 @@
import Link from "next/link"
import { BookOpen, PenTool, Library, ArrowRight } from "lucide-react"
import { getStudentClasses } from "@/modules/classes/data-access"
import { getStudentHomeworkAssignments } from "@/modules/homework/data-access"
import { getCurrentStudentUser } from "@/modules/users/data-access"
import { getTextbooks } from "@/modules/textbooks/data-access"
import { Card, CardContent, CardHeader, CardTitle } from "@/shared/components/ui/card"
import { EmptyState } from "@/shared/components/ui/empty-state"
import { UserX } from "lucide-react"
export const dynamic = "force-dynamic"
export default async function StudentLearningPage() {
const student = await getCurrentStudentUser()
if (!student) {
return (
<div className="space-y-8">
<EmptyState title="No user found" description="Create a student user to see learning." icon={UserX} />
</div>
)
}
const [classes, assignments, textbooks] = await Promise.all([
getStudentClasses(student.id),
getStudentHomeworkAssignments(student.id),
getTextbooks(),
])
const now = new Date()
const pendingCount = assignments.filter((a) => a.progressStatus !== "submitted" && a.progressStatus !== "graded").length
const dueSoonCount = assignments.filter((a) => {
if (a.progressStatus === "submitted" || a.progressStatus === "graded") return false
if (!a.dueAt) return false
const due = new Date(a.dueAt)
const in7Days = new Date(now)
in7Days.setDate(in7Days.getDate() + 7)
return due >= now && due <= in7Days
}).length
const cards = [
{
title: "Courses",
description: "Your enrolled classes.",
icon: BookOpen,
href: "/student/learning/courses",
stat: `${classes.length} enrolled`,
},
{
title: "Assignments",
description: "Homework and practice.",
icon: PenTool,
href: "/student/learning/assignments",
stat: `${pendingCount} pending${dueSoonCount > 0 ? ` · ${dueSoonCount} due soon` : ""}`,
},
{
title: "Textbooks",
description: "Browse course materials.",
icon: Library,
href: "/student/learning/textbooks",
stat: `${textbooks.length} available`,
},
]
return (
<div className="space-y-8">
<div>
<h2 className="text-2xl font-bold tracking-tight">My Learning</h2>
<p className="text-muted-foreground">Your learning hub: courses, assignments, and textbooks.</p>
</div>
<div className="grid gap-6 md:grid-cols-2 lg:grid-cols-3">
{cards.map((c) => (
<Link key={c.href} href={c.href}>
<Card className="h-full transition-all hover:shadow-md hover:border-primary/50">
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
<CardTitle className="text-base font-medium">{c.title}</CardTitle>
<c.icon className="h-5 w-5 text-muted-foreground" />
</CardHeader>
<CardContent className="space-y-2">
<p className="text-sm text-muted-foreground">{c.description}</p>
<div className="flex items-center justify-between">
<span className="text-sm font-medium">{c.stat}</span>
<ArrowRight className="h-4 w-4 text-muted-foreground" />
</div>
</CardContent>
</Card>
</Link>
))}
</div>
</div>
)
}

View File

@@ -3,8 +3,9 @@ import { getTranslations } from "next-intl/server"
import { BookOpen } from "lucide-react"
import { getTextbookById, getChaptersByTextbookId, getKnowledgePointsByTextbookId } from "@/modules/textbooks/data-access"
import { getTextbookById, getChaptersByTextbookId } from "@/modules/textbooks/data-access"
import { TextbookReader } from "@/modules/textbooks/components/textbook-reader"
import { getSubjectLabelKey, getGradeLabelKey } from "@/modules/textbooks/constants"
import { Badge } from "@/shared/components/ui/badge"
import { EmptyState } from "@/shared/components/ui/empty-state"
import { getCurrentStudentUser } from "@/modules/users/data-access"
@@ -23,10 +24,9 @@ export default async function StudentTextbookDetailPage({
const { id } = await params
const [textbook, chapters, knowledgePoints] = await Promise.all([
const [textbook, chapters] = await Promise.all([
getTextbookById(id),
getChaptersByTextbookId(id),
getKnowledgePointsByTextbookId(id)
])
if (!textbook) notFound()
@@ -45,9 +45,9 @@ export default async function StudentTextbookDetailPage({
<h1 className="text-lg font-bold tracking-tight truncate">{textbook.title}</h1>
<div className="flex items-center gap-2 text-sm text-muted-foreground">
<span className="hidden sm:inline-block w-px h-4 bg-border" aria-hidden="true" />
<Badge variant="outline" className="font-normal text-xs">{textbook.subject}</Badge>
<Badge variant="outline" className="font-normal text-xs">{t(`subject.${getSubjectLabelKey(textbook.subject)}`)}</Badge>
{textbook.grade && (
<Badge variant="secondary" className="font-normal text-xs">{textbook.grade}</Badge>
<Badge variant="secondary" className="font-normal text-xs">{t(`grade.${getGradeLabelKey(textbook.grade)}`)}</Badge>
)}
</div>
</div>
@@ -66,7 +66,7 @@ export default async function StudentTextbookDetailPage({
) : (
<div className="h-full min-h-0 max-w-[1600px] mx-auto w-full">
{/* 学生端不传 renderQuestionCreator无题目创建权限 */}
<TextbookReader chapters={chapters} knowledgePoints={knowledgePoints} />
<TextbookReader key={id} chapters={chapters} textbookId={id} />
</div>
)}
</div>

View File

@@ -7,16 +7,10 @@ import { TextbookFilters } from "@/modules/textbooks/components/textbook-filters
import { getCurrentStudentUser } from "@/modules/users/data-access"
import { getGradeNameById } from "@/modules/school/data-access"
import { EmptyState } from "@/shared/components/ui/empty-state"
import { getParam, type SearchParams } from "@/shared/lib/search-params"
export const dynamic = "force-dynamic"
type SearchParams = { [key: string]: string | string[] | undefined }
const getParam = (params: SearchParams, key: string): string | undefined => {
const v = params[key]
return Array.isArray(v) ? v[0] : v
}
export default async function StudentTextbooksPage({
searchParams,
}: {

View File

@@ -3,7 +3,7 @@ import { Skeleton } from "@/shared/components/ui/skeleton"
export default function Loading() {
return (
<div className="flex h-full flex-col space-y-8 p-8">
<div className="space-y-8">
<div className="flex flex-col justify-between gap-4 md:flex-row md:items-center">
<div className="space-y-2">
<Skeleton className="h-8 w-40" />

View File

@@ -5,11 +5,10 @@ import { getCurrentStudentUser } from "@/modules/users/data-access"
import { StudentScheduleFilters } from "@/modules/student/components/student-schedule-filters"
import { StudentScheduleView } from "@/modules/student/components/student-schedule-view"
import { EmptyState } from "@/shared/components/ui/empty-state"
import { getParam, type SearchParams } from "@/shared/lib/search-params"
export const dynamic = "force-dynamic"
type SearchParams = { [key: string]: string | string[] | undefined }
export default async function StudentSchedulePage({
searchParams,
}: {
@@ -18,7 +17,7 @@ export default async function StudentSchedulePage({
const student = await getCurrentStudentUser()
if (!student) {
return (
<div className="h-full flex-1 flex-col space-y-8 p-8 md:flex">
<div className="space-y-8">
<div>
<h2 className="text-2xl font-bold tracking-tight">Schedule</h2>
<p className="text-muted-foreground">Your weekly timetable.</p>
@@ -34,18 +33,12 @@ export default async function StudentSchedulePage({
getStudentSchedule(student.id),
])
const classIdParam = sp.classId
const resolveClassId = (param: string | string[] | undefined): string => {
if (typeof param === "string") return param
if (Array.isArray(param)) return param[0] ?? "all"
return "all"
}
const classId = resolveClassId(classIdParam)
const classId = getParam(sp, "classId") ?? "all"
const filteredItems =
classId !== "all" ? schedule.filter((s) => s.classId === classId) : schedule
return (
<div className="flex h-full flex-col space-y-8 p-8">
<div className="space-y-8">
<div className="flex flex-col justify-between gap-4 md:flex-row md:items-center">
<div>
<h2 className="text-2xl font-bold tracking-tight">Schedule</h2>