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:
SpecialX
2026-06-24 12:03:47 +08:00
parent 8c2fe14c20
commit 37d2688a28
84 changed files with 2665 additions and 661 deletions

View File

@@ -1,14 +1,18 @@
import type { Metadata } from "next"
import type { JSX } from "react"
import { getTranslations } from "next-intl/server"
import { requirePermission } from "@/shared/lib/auth-guard"
import { Permissions } from "@/shared/types/permissions"
import { AiProviderSettingsCard } from "@/modules/settings/components/ai-provider-settings-card"
import { AiUsageDashboard } from "@/modules/ai/components/ai-usage-dashboard"
export const metadata: Metadata = {
title: "AI 配置 - Next_Edu",
description: "统一管理 AI 服务商、API 密钥与使用统计",
export async function generateMetadata(): Promise<Metadata> {
const t = await getTranslations("ai")
return {
title: `${t("admin.settings.title")} - Next_Edu`,
description: t("admin.settings.description"),
}
}
export const dynamic = "force-dynamic"
@@ -18,25 +22,31 @@ export const dynamic = "force-dynamic"
*
* 作为 AI 模块的独立配置入口,取代:
* - /settings?tab=ai已移除 AI 标签页)
* - 考试页面内嵌的 AI 配置弹窗(已改为跳转链接
* - 考试页面内嵌的 AI 配置弹窗(已移除
*
* 权限:AI_CONFIGURE当前仅 admin 角色拥有)
* 权限规则
* - AI_CHAT 用户均可访问(管理自己的 private provider
* - AI_CONFIGURE 用户(管理员)可额外管理 public provider 与他人 private provider
*/
export default async function AiSettingsPage(): Promise<JSX.Element> {
await requirePermission(Permissions.AI_CONFIGURE)
const t = await getTranslations("ai")
const ctx = await requirePermission(Permissions.AI_CHAT)
const isAdmin = ctx.permissions.includes(Permissions.AI_CONFIGURE)
return (
<div className="flex h-full flex-col gap-8 p-8">
<div className="flex flex-col justify-between gap-4 md:flex-row md:items-center">
<div className="space-y-1">
<h1 className="text-3xl font-bold tracking-tight">AI </h1>
<h1 className="text-3xl font-bold tracking-tight">{t("admin.settings.title")}</h1>
<div className="text-sm text-muted-foreground">
AI API 使
{isAdmin
? t("admin.settings.description")
: t("admin.settings.userDescription")}
</div>
</div>
</div>
<div className="space-y-6">
<AiProviderSettingsCard />
<AiUsageDashboard />
<AiProviderSettingsCard isAdmin={isAdmin} currentUserId={ctx.userId} />
{isAdmin ? <AiUsageDashboard /> : null}
</div>
</div>
)

View File

@@ -1,5 +1,6 @@
import type { Metadata } from "next"
import type { Metadata } from "next"
import type { JSX } from "react"
import { getTranslations } from "next-intl/server"
import { requirePermission } from "@/shared/lib/auth-guard"
import { Permissions } from "@/shared/types/permissions"
@@ -13,9 +14,12 @@ import { DataChangeLogTable } from "@/modules/audit/components/data-change-log-t
import { AuditLogExportButton } from "@/modules/audit/components/audit-log-export-button"
import type { DataChangeAction } from "@/modules/audit/types"
export const metadata: Metadata = {
title: "数据变更日志 - Next_Edu",
description: "追踪系统所有数据变更(增删改),保障合规",
export async function generateMetadata(): Promise<Metadata> {
const t = await getTranslations("audit")
return {
title: `${t("dataChanges.title")} - Next_Edu`,
description: t("dataChanges.description"),
}
}
export const dynamic = "force-dynamic"
@@ -28,6 +32,7 @@ export default async function DataChangeLogsPage({
}: {
searchParams: Promise<SearchParams>
}): Promise<JSX.Element> {
const t = await getTranslations("audit")
await requirePermission(Permissions.AUDIT_LOG_READ)
const params = await searchParams
@@ -54,10 +59,8 @@ export default async function DataChangeLogsPage({
<div className="flex h-full flex-col space-y-8 p-8">
<div className="flex items-start justify-between gap-4">
<div className="space-y-1">
<h2 className="text-2xl font-bold tracking-tight"></h2>
<p className="text-muted-foreground">
</p>
<h2 className="text-2xl font-bold tracking-tight">{t("dataChanges.title")}</h2>
<p className="text-muted-foreground">{t("dataChanges.description")}</p>
</div>
<AuditLogExportButton exportType="dataChange" params={exportParams} />
</div>

View File

@@ -1,5 +1,6 @@
import type { Metadata } from "next"
import type { Metadata } from "next"
import type { JSX } from "react"
import { getTranslations } from "next-intl/server"
import { requirePermission } from "@/shared/lib/auth-guard"
import { Permissions } from "@/shared/types/permissions"
@@ -9,9 +10,12 @@ import { LoginLogView } from "@/modules/audit/components/login-log-view"
import { AuditLogExportButton } from "@/modules/audit/components/audit-log-export-button"
import type { LoginLogAction, LoginLogStatus } from "@/modules/audit/types"
export const metadata: Metadata = {
title: "登录日志 - Next_Edu",
description: "监控所有认证事件,包括登录、登出与注册",
export async function generateMetadata(): Promise<Metadata> {
const t = await getTranslations("audit")
return {
title: `${t("loginLogs.title")} - Next_Edu`,
description: t("loginLogs.description"),
}
}
export const dynamic = "force-dynamic"
@@ -27,6 +31,7 @@ export default async function LoginLogsPage({
}: {
searchParams: Promise<SearchParams>
}): Promise<JSX.Element> {
const t = await getTranslations("audit")
await requirePermission(Permissions.AUDIT_LOG_READ)
const params = await searchParams
@@ -50,9 +55,9 @@ export default async function LoginLogsPage({
<div className="flex h-full flex-col space-y-8 p-8">
<div className="flex items-start justify-between gap-4">
<div className="space-y-1">
<h2 className="text-2xl font-bold tracking-tight"></h2>
<h2 className="text-2xl font-bold tracking-tight">{t("loginLogs.title")}</h2>
<p className="text-muted-foreground">
{t("loginLogs.description")}
</p>
</div>
<AuditLogExportButton exportType="login" params={exportParams} />

View File

@@ -1,5 +1,6 @@
import type { Metadata } from "next"
import type { Metadata } from "next"
import type { JSX } from "react"
import { getTranslations } from "next-intl/server"
import { requirePermission } from "@/shared/lib/auth-guard"
import { Permissions } from "@/shared/types/permissions"
@@ -9,9 +10,12 @@ import { AuditLogView } from "@/modules/audit/components/audit-log-view"
import { AuditLogExportButton } from "@/modules/audit/components/audit-log-export-button"
import type { AuditLogStatus } from "@/modules/audit/types"
export const metadata: Metadata = {
title: "审计日志 - Next_Edu",
description: "追踪系统内所有用户操作,保障安全与合规",
export async function generateMetadata(): Promise<Metadata> {
const t = await getTranslations("audit")
return {
title: `${t("title")} - Next_Edu`,
description: t("description"),
}
}
export const dynamic = "force-dynamic"
@@ -24,6 +28,7 @@ export default async function AuditLogsPage({
}: {
searchParams: Promise<SearchParams>
}): Promise<JSX.Element> {
const t = await getTranslations("audit")
await requirePermission(Permissions.AUDIT_LOG_READ)
const params = await searchParams
@@ -51,10 +56,8 @@ export default async function AuditLogsPage({
<div className="flex h-full flex-col space-y-8 p-8">
<div className="flex items-start justify-between gap-4">
<div className="space-y-1">
<h2 className="text-2xl font-bold tracking-tight"></h2>
<p className="text-muted-foreground">
</p>
<h2 className="text-2xl font-bold tracking-tight">{t("title")}</h2>
<p className="text-muted-foreground">{t("description")}</p>
</div>
<AuditLogExportButton exportType="audit" params={exportParams} />
</div>

View File

@@ -1,15 +1,19 @@
import { notFound } from "next/navigation"
import type { Metadata } from "next"
import type { JSX } from "react"
import { getTranslations } from "next-intl/server"
import { getCoursePlanById, getSubjectOptions } from "@/modules/course-plans/data-access"
import { getAdminClasses } from "@/modules/classes/data-access"
import { getAcademicYears, getStaffOptions } from "@/modules/school/data-access"
import { CoursePlanForm } from "@/modules/course-plans/components/course-plan-form"
export const metadata: Metadata = {
title: "编辑课程计划 - Next_Edu",
description: "更新课程计划详情",
export async function generateMetadata(): Promise<Metadata> {
const t = await getTranslations("coursePlans")
return {
title: `${t("edit.title")} - Next_Edu`,
description: t("edit.description"),
}
}
export const dynamic = "force-dynamic"
@@ -19,6 +23,7 @@ export default async function EditCoursePlanPage({
}: {
params: Promise<{ id: string }>
}): Promise<JSX.Element> {
const t = await getTranslations("coursePlans")
const { id } = await params
const [plan, classes, subjects, teachers, academicYears] = await Promise.all([
@@ -34,8 +39,8 @@ export default async function EditCoursePlanPage({
return (
<div className="flex h-full flex-col space-y-8 p-8">
<div>
<h2 className="text-2xl font-bold tracking-tight"></h2>
<p className="text-muted-foreground"></p>
<h2 className="text-2xl font-bold tracking-tight">{t("edit.title")}</h2>
<p className="text-muted-foreground">{t("edit.description")}</p>
</div>
<CoursePlanForm
mode="edit"

View File

@@ -1,13 +1,17 @@
import { notFound } from "next/navigation"
import type { Metadata } from "next"
import type { JSX } from "react"
import { getTranslations } from "next-intl/server"
import { getCoursePlanById } from "@/modules/course-plans/data-access"
import { CoursePlanDetail } from "@/modules/course-plans/components/course-plan-detail"
export const metadata: Metadata = {
title: "课程计划详情 - Next_Edu",
description: "查看课程计划详情",
export async function generateMetadata(): Promise<Metadata> {
const t = await getTranslations("coursePlans")
return {
title: `${t("detail.title")} - Next_Edu`,
description: t("detail.description"),
}
}
export const dynamic = "force-dynamic"

View File

@@ -1,19 +1,24 @@
import type { Metadata } from "next"
import type { Metadata } from "next"
import type { JSX } from "react"
import { getTranslations } from "next-intl/server"
import { getAdminClasses } from "@/modules/classes/data-access"
import { getAcademicYears, getStaffOptions } from "@/modules/school/data-access"
import { getSubjectOptions } from "@/modules/course-plans/data-access"
import { CoursePlanForm } from "@/modules/course-plans/components/course-plan-form"
export const metadata: Metadata = {
title: "新建课程计划 - Next_Edu",
description: "创建新的课程教学计划",
export async function generateMetadata(): Promise<Metadata> {
const t = await getTranslations("coursePlans")
return {
title: `${t("create.title")} - Next_Edu`,
description: t("create.description"),
}
}
export const dynamic = "force-dynamic"
export default async function CreateCoursePlanPage(): Promise<JSX.Element> {
const t = await getTranslations("coursePlans")
const [classes, subjects, teachers, academicYears] = await Promise.all([
getAdminClasses(),
getSubjectOptions(),
@@ -24,8 +29,8 @@ export default async function CreateCoursePlanPage(): Promise<JSX.Element> {
return (
<div className="flex h-full flex-col space-y-8 p-8">
<div>
<h2 className="text-2xl font-bold tracking-tight"></h2>
<p className="text-muted-foreground"></p>
<h2 className="text-2xl font-bold tracking-tight">{t("create.title")}</h2>
<p className="text-muted-foreground">{t("create.description")}</p>
</div>
<CoursePlanForm
mode="create"

View File

@@ -1,14 +1,18 @@
import type { Metadata } from "next"
import type { Metadata } from "next"
import type { JSX } from "react"
import { getTranslations } from "next-intl/server"
import { getCoursePlans } from "@/modules/course-plans/data-access"
import { CoursePlanList } from "@/modules/course-plans/components/course-plan-list"
import { getSearchParam, type SearchParams } from "@/shared/lib/utils"
import type { CoursePlanStatus } from "@/modules/course-plans/types"
export const metadata: Metadata = {
title: "课程计划 - Next_Edu",
description: "管理课程教学计划与周课时安排",
export async function generateMetadata(): Promise<Metadata> {
const t = await getTranslations("coursePlans")
return {
title: `${t("title")} - Next_Edu`,
description: t("description"),
}
}
export const dynamic = "force-dynamic"
@@ -21,6 +25,7 @@ export default async function AdminCoursePlansPage({
}: {
searchParams: Promise<SearchParams>
}): Promise<JSX.Element> {
const t = await getTranslations("coursePlans")
const sp = await searchParams
const statusParam = getSearchParam(sp, "status")
const status = isValidStatus(statusParam) ? statusParam : undefined
@@ -30,10 +35,8 @@ export default async function AdminCoursePlansPage({
return (
<div className="flex h-full flex-col space-y-8 p-8">
<div className="space-y-1">
<h2 className="text-2xl font-bold tracking-tight"></h2>
<p className="text-muted-foreground">
</p>
<h2 className="text-2xl font-bold tracking-tight">{t("title")}</h2>
<p className="text-muted-foreground">{t("description")}</p>
</div>
<CoursePlanList
plans={plans}

View File

@@ -1,57 +1,84 @@
import type { JSX } from "react"
import type { Metadata } from "next"
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 {
getStudentErrorBookSummaries,
getTopWrongQuestionsByStudentIds,
getKnowledgePointWeakness,
getSubjectErrorDistribution,
getStudentNameMap,
getSubjectErrorOverviews,
getSubjectErrorDistribution,
getChapterWeakness,
getAllStudentIds,
} 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 { AnalyticsStatsCards } from "@/modules/error-book/components/analytics-stats-cards"
import { SubjectDistributionChart } from "@/modules/error-book/components/subject-distribution-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 AdminErrorBookPage(): Promise<JSX.Element> {
export async function generateMetadata(): Promise<Metadata> {
const t = await getTranslations("errorBook")
return {
title: `${t("admin.title")} - Next_Edu`,
description: t("admin.description"),
}
}
async function AdminErrorBookContent({
searchParams,
}: {
searchParams: Promise<SearchParams>
}): Promise<JSX.Element> {
const t = await getTranslations("errorBook")
const ctx = await requirePermission(Permissions.ERROR_BOOK_ANALYTICS_READ)
if (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>
<h1 className="text-2xl font-bold tracking-tight">{t("admin.title")}</h1>
<p className="text-muted-foreground">{t("admin.description")}</p>
</div>
<EmptyState
icon={BarChart3}
title="权限不足"
description="您没有权限查看全校错题分析数据。"
title={t("admin.noPermissionTitle")}
description={t("admin.noPermissionDescription")}
className="h-[360px] bg-card"
/>
</div>
)
}
// 通过 data-access 层查询所有学生 ID遵循三层架构app 层不直接访问 DB
const studentIds = await getAllStudentIds()
const params = await searchParams
if (studentIds.length === 0) {
// 通过 data-access 层查询所有学生 ID遵循三层架构
const allStudentIds = await getAllStudentIds()
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>
<h1 className="text-2xl font-bold tracking-tight">{t("admin.title")}</h1>
<p className="text-muted-foreground">{t("admin.description")}</p>
</div>
<EmptyState
icon={BarChart3}
title="暂无学生数据"
description="系统中还没有学生用户,无法查看错题分析。"
title={t("admin.noStudentsTitle")}
description={t("admin.noStudentsDescription")}
className="h-[360px] bg-card"
/>
</div>
@@ -59,21 +86,33 @@ export default async function AdminErrorBookPage(): Promise<JSX.Element> {
}
// 限制查询数量,避免性能问题(取最近活跃的 500 名学生)
const limitedStudentIds = studentIds.slice(0, 500)
const limitedStudentIds = allStudentIds.slice(0, 500)
const [summaries, topWrongQuestions, weakKps, subjectDist, nameMap] = await Promise.all([
getStudentErrorBookSummaries(limitedStudentIds),
getTopWrongQuestionsByStudentIds(limitedStudentIds, 10),
getKnowledgePointWeakness(limitedStudentIds, 10),
// 解析 URL 参数:学科筛选
const subjectParam = getParam(params, "subject")
// 学科概览(用于 Tab 显示,不受学科筛选影响)
const [subjectOverviews, subjectDist] = await Promise.all([
getSubjectErrorOverviews(limitedStudentIds),
getSubjectErrorDistribution(limitedStudentIds),
])
// 并行查询所有统计数据(按学科过滤)
const [summaries, topWrongQuestions, weakKps, chapterWeakness, nameMap] = await Promise.all([
getStudentErrorBookSummaries(limitedStudentIds, subjectParam),
getTopWrongQuestionsByStudentIds(limitedStudentIds, 10, subjectParam),
getKnowledgePointWeakness(limitedStudentIds, 10, subjectParam),
getChapterWeakness(limitedStudentIds, 10, subjectParam),
getStudentNameMap(limitedStudentIds),
])
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]
.filter((s) => s.totalCount > 0)
@@ -81,33 +120,114 @@ export default async function AdminErrorBookPage(): Promise<JSX.Element> {
.slice(0, 50)
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>
<h1 className="text-2xl font-bold tracking-tight">{t("admin.title")}</h1>
<p className="text-muted-foreground">{t("admin.description")}</p>
</div>
<ClassErrorBookOverview
totalStudents={studentIds.length}
{/* 学科 Tab */}
{subjectOverviews.length > 0 ? (
<Suspense fallback={<Skeleton className="h-10 w-full" />}>
<SubjectTabs
subjects={subjectOverviews}
currentSubjectId={subjectParam ?? null}
/>
</Suspense>
) : null}
{/* 统计卡片 */}
<AnalyticsStatsCards
totalStudents={limitedStudentIds.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"> Top 50</h2>
<StudentErrorTable
students={sortedSummaries}
studentNames={nameMap}
basePath="/admin/error-book"
/>
{/* 学科错题分布图(仅在"全部学科"视图下显示) */}
{!subjectParam && subjectDist.length > 0 ? (
<SubjectDistributionChart data={subjectDist} />
) : null}
{/* 章节错题分布 + 知识点薄弱度(并排) */}
<div className="grid gap-4 lg:grid-cols-2">
{chapterWeakness.length > 0 ? (
<ChapterWeaknessChart data={chapterWeakness} />
) : (
<EmptyState
icon={BarChart3}
title={t("admin.noChapterDataTitle")}
description={t("admin.noChapterDataDescription")}
className="h-[300px] bg-card"
/>
)}
{weakKps.length > 0 ? (
<KnowledgePointWeaknessChart data={weakKps} />
) : (
<EmptyState
icon={BarChart3}
title={t("admin.noKnowledgePointDataTitle")}
description={t("admin.noKnowledgePointDataDescription")}
className="h-[300px] bg-card"
/>
)}
</div>
<TopWrongQuestions questions={topWrongQuestions} />
{/* 错题最多的学生 Top 50 */}
<div className="space-y-3">
<div className="flex items-center justify-between">
<h2 className="text-lg font-semibold">{t("admin.topStudents")}</h2>
<span className="text-sm text-muted-foreground">
{t("admin.studentsWithErrors", { count: studentsWithErrorBook.length })}
</span>
</div>
{sortedSummaries.length > 0 ? (
<GroupedStudentErrorTable
students={sortedSummaries}
studentNames={nameMap}
basePath="/admin/error-book"
/>
) : (
<EmptyState
icon={BarChart3}
title={t("admin.noStudentErrorsTitle")}
description={t("admin.noStudentErrorsDescription")}
className="h-[200px] bg-card"
/>
)}
</div>
{/* 高频错题 Top 10 */}
{topWrongQuestions.length > 0 ? (
<TopWrongQuestions questions={topWrongQuestions} />
) : null}
</div>
)
}
export default async function AdminErrorBookPage({
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>
}
>
<AdminErrorBookContent searchParams={searchParams} />
</Suspense>
)
}

View File

@@ -1,5 +1,6 @@
import type { Metadata } from "next"
import type { Metadata } from "next"
import type { JSX } from "react"
import { getTranslations } from "next-intl/server"
import { requirePermission } from "@/shared/lib/auth-guard"
import { Permissions } from "@/shared/types/permissions"
@@ -9,9 +10,12 @@ import {
} from "@/modules/files/data-access"
import { AdminFilesView } from "@/modules/files/components/admin-files-view"
export const metadata: Metadata = {
title: "文件管理 - Next_Edu",
description: "查看与管理系统中所有上传文件",
export async function generateMetadata(): Promise<Metadata> {
const t = await getTranslations("files")
return {
title: `${t("title")} - Next_Edu`,
description: t("description"),
}
}
export const dynamic = "force-dynamic"

View File

@@ -1,10 +1,7 @@
import { getAuthContext } from "@/shared/lib/auth-guard"
export default async function AdminLayout({
children,
}: {
children: React.ReactNode
}): Promise<React.ReactNode> {
await getAuthContext()
return <>{children}</>
}

View 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 AdminLessonPlanViewError() {
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>
)
}

View File

@@ -0,0 +1,11 @@
import { Skeleton } from "@/shared/components/ui/skeleton"
export default function AdminLessonPlanViewLoading() {
return (
<div className="h-[calc(100vh-4rem)]">
<div className="flex h-full items-center justify-center">
<Skeleton className="h-[80%] w-[80%]" />
</div>
</div>
)
}

View File

@@ -0,0 +1,62 @@
import type { JSX } from "react"
import { Suspense } from "react"
import { notFound } from "next/navigation"
import { getAuthContext } from "@/shared/lib/auth-guard"
import { getLessonPlanById } from "@/modules/lesson-preparation/data-access"
import { getTextbookById, getChaptersByTextbookId } from "@/modules/textbooks/data-access"
import { LessonPlanReadonlyView } from "@/modules/lesson-preparation/components/lesson-plan-readonly-view"
import { Skeleton } from "@/shared/components/ui/skeleton"
export const dynamic = "force-dynamic"
export default async function AdminLessonPlanViewPage({
params,
}: {
params: Promise<{ planId: string }>
}): Promise<JSX.Element> {
const { planId } = await params
const ctx = await getAuthContext()
const plan = await getLessonPlanById(planId, ctx.userId)
if (!plan) notFound()
let textbookTitle: string | undefined
let chapterTitle: string | undefined
if (plan.textbookId) {
const textbook = await getTextbookById(plan.textbookId)
textbookTitle = textbook?.title
if (plan.chapterId) {
const chapters = await getChaptersByTextbookId(plan.textbookId)
const findChapter = (list: typeof chapters): typeof chapters[number] | undefined => {
for (const ch of list) {
if (ch.id === plan.chapterId) return ch
if (ch.children && ch.children.length > 0) {
const found = findChapter(ch.children as typeof chapters)
if (found) return found
}
}
return undefined
}
const chapter = findChapter(chapters)
chapterTitle = chapter?.title
}
}
return (
<div className="h-[calc(100vh-4rem)]">
<Suspense
fallback={
<div className="flex h-full items-center justify-center">
<Skeleton className="h-[80%] w-[80%]" />
</div>
}
>
<LessonPlanReadonlyView
doc={plan.content}
textbookTitle={textbookTitle}
chapterTitle={chapterTitle}
/>
</Suspense>
</div>
)
}

View 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 AdminLessonPlansError() {
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>
)
}

View File

@@ -0,0 +1,22 @@
import { Skeleton } from "@/shared/components/ui/skeleton"
export default function AdminLessonPlansLoading() {
return (
<div className="p-6 space-y-4">
<div className="space-y-2">
<Skeleton className="h-8 w-[180px]" />
<Skeleton className="h-4 w-[300px]" />
</div>
<div className="grid grid-cols-2 md:grid-cols-4 gap-4">
{Array.from({ length: 4 }).map((_, i) => (
<Skeleton key={i} className="h-[100px] w-full" />
))}
</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>
)
}

View File

@@ -0,0 +1,88 @@
import type { JSX } from "react"
import { Suspense } from "react"
import { getTranslations } from "next-intl/server"
import { getAuthContext } from "@/shared/lib/auth-guard"
import { getLessonPlans, getLessonPlanStats } from "@/modules/lesson-preparation/data-access"
import { getSubjectOptions } from "@/modules/school/data-access"
import { LessonPlanList } from "@/modules/lesson-preparation/components/lesson-plan-list"
import { Skeleton } from "@/shared/components/ui/skeleton"
import { Card, CardContent, CardHeader, CardTitle } from "@/shared/components/ui/card"
export const dynamic = "force-dynamic"
export default async function AdminLessonPlansPage(): Promise<JSX.Element> {
const t = await getTranslations("lessonPreparation")
const ctx = await getAuthContext()
// 通过 data-access 层查询,避免 app 层直接访问数据库P0-1 修复)
const [items, subjects, stats] = await Promise.all([
getLessonPlans({}, ctx.dataScope, ctx.userId),
getSubjectOptions(),
getLessonPlanStats(),
])
return (
<div className="p-6 space-y-4">
<div>
<h1 className="text-2xl font-bold tracking-tight">{t("admin.title")}</h1>
<p className="text-muted-foreground">{t("admin.description")}</p>
</div>
{/* 统计卡片 */}
<div className="grid grid-cols-2 md:grid-cols-4 gap-4">
<Card>
<CardHeader className="pb-2">
<CardTitle className="text-sm font-medium text-on-surface-variant">
{t("admin.stats.total")}
</CardTitle>
</CardHeader>
<CardContent>
<div className="text-2xl font-bold">{stats.total}</div>
</CardContent>
</Card>
<Card>
<CardHeader className="pb-2">
<CardTitle className="text-sm font-medium text-on-surface-variant">
{t("admin.stats.published")}
</CardTitle>
</CardHeader>
<CardContent>
<div className="text-2xl font-bold text-primary">{stats.published}</div>
</CardContent>
</Card>
<Card>
<CardHeader className="pb-2">
<CardTitle className="text-sm font-medium text-on-surface-variant">
{t("admin.stats.draft")}
</CardTitle>
</CardHeader>
<CardContent>
<div className="text-2xl font-bold text-on-surface-variant">{stats.draft}</div>
</CardContent>
</Card>
<Card>
<CardHeader className="pb-2">
<CardTitle className="text-sm font-medium text-on-surface-variant">
{t("admin.stats.archived")}
</CardTitle>
</CardHeader>
<CardContent>
<div className="text-2xl font-bold text-on-surface-variant">{stats.archived}</div>
</CardContent>
</Card>
</div>
<Suspense
fallback={
<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>
}
>
<LessonPlanList initialItems={items} subjects={subjects} viewMode="admin" />
</Suspense>
</div>
)
}

View File

@@ -1,7 +1,8 @@
import Link from "next/link"
import Link from "next/link"
import { CalendarClock, ClipboardList, Settings2 } from "lucide-react"
import type { Metadata } from "next"
import type { JSX } from "react"
import { getTranslations } from "next-intl/server"
import { requirePermission } from "@/shared/lib/auth-guard"
import { Permissions } from "@/shared/types/permissions"
@@ -10,14 +11,18 @@ import { EmptyState } from "@/shared/components/ui/empty-state"
import { getAdminClassesForScheduling } from "@/modules/scheduling/data-access"
import { AutoSchedulePanel } from "@/modules/scheduling/components/auto-schedule-panel"
export const metadata: Metadata = {
title: "自动排课 - Next_Edu",
description: "基于规则与学科分配自动生成周课表",
export async function generateMetadata(): Promise<Metadata> {
const t = await getTranslations("scheduling")
return {
title: `${t("auto.title")} - Next_Edu`,
description: t("auto.description"),
}
}
export const dynamic = "force-dynamic"
export default async function AdminSchedulingAutoPage(): Promise<JSX.Element> {
const t = await getTranslations("scheduling")
await requirePermission(Permissions.SCHEDULE_AUTO)
const classes = await getAdminClassesForScheduling()
const classOptions = classes.map((c) => ({ id: c.id, name: c.name, grade: c.grade }))
@@ -26,15 +31,13 @@ export default async function AdminSchedulingAutoPage(): Promise<JSX.Element> {
<div className="flex h-full flex-col space-y-8 p-8">
<div className="flex items-center justify-between space-y-2">
<div className="space-y-1">
<h2 className="text-2xl font-bold tracking-tight"></h2>
<p className="text-muted-foreground">
</p>
<h2 className="text-2xl font-bold tracking-tight">{t("auto.title")}</h2>
<p className="text-muted-foreground">{t("auto.description")}</p>
</div>
<Button asChild variant="outline">
<Link href="/admin/scheduling/rules">
<Settings2 className="mr-2 h-4 w-4" />
{t("auto.configureRules")}
</Link>
</Button>
</div>
@@ -42,8 +45,8 @@ export default async function AdminSchedulingAutoPage(): Promise<JSX.Element> {
{classOptions.length === 0 ? (
<EmptyState
icon={ClipboardList}
title="暂无可用班级"
description="请先创建班级,再进行自动排课。"
title={t("auto.noClassesTitle")}
description={t("auto.noClassesDescription")}
/>
) : (
<AutoSchedulePanel classes={classOptions} />
@@ -51,7 +54,7 @@ export default async function AdminSchedulingAutoPage(): Promise<JSX.Element> {
<div className="flex items-center gap-2 text-xs text-muted-foreground">
<CalendarClock className="h-4 w-4" />
<span></span>
<span>{t("auto.hint")}</span>
</div>
</div>
)

View File

@@ -1,7 +1,8 @@
import Link from "next/link"
import Link from "next/link"
import { PlusCircle, ClipboardList } from "lucide-react"
import type { Metadata } from "next"
import type { JSX } from "react"
import { getTranslations } from "next-intl/server"
import { requirePermission } from "@/shared/lib/auth-guard"
import { Permissions } from "@/shared/types/permissions"
@@ -18,9 +19,12 @@ import { ScheduleConflictsView } from "@/modules/scheduling/components/schedule-
import { ScheduleGridView } from "@/modules/scheduling/components/schedule-grid-view"
import type { ScheduleChangeStatus } from "@/modules/scheduling/types"
export const metadata: Metadata = {
title: "课表变更申请 - Next_Edu",
description: "审核、批准或拒绝课表变更与代课申请",
export async function generateMetadata(): Promise<Metadata> {
const t = await getTranslations("scheduling")
return {
title: `${t("changes.title")} - Next_Edu`,
description: t("changes.description"),
}
}
export const dynamic = "force-dynamic"
@@ -33,6 +37,7 @@ export default async function AdminSchedulingChangesPage({
}: {
searchParams: Promise<SearchParams>
}): Promise<JSX.Element> {
const t = await getTranslations("scheduling")
await requirePermission(Permissions.SCHEDULE_ADJUST)
const sp = await searchParams
const statusParam = getSearchParam(sp, "status")
@@ -51,15 +56,15 @@ export default async function AdminSchedulingChangesPage({
<div className="flex h-full flex-col space-y-8 p-8">
<div className="flex items-center justify-between space-y-2">
<div className="space-y-1">
<h2 className="text-2xl font-bold tracking-tight"></h2>
<h2 className="text-2xl font-bold tracking-tight">{t("changes.title")}</h2>
<p className="text-muted-foreground">
{t("changes.description")}
</p>
</div>
<Button asChild>
<Link href="/teacher/schedule-changes">
<PlusCircle className="mr-2 h-4 w-4" />
{t("changes.newRequest")}
</Link>
</Button>
</div>
@@ -67,10 +72,10 @@ export default async function AdminSchedulingChangesPage({
{items.length === 0 && !status && !classId ? (
<EmptyState
icon={ClipboardList}
title="暂无课表变更申请"
description="系统中尚未产生任何课表变更申请。"
title={t("changes.noChangesTitle")}
description={t("changes.noChangesDescription")}
action={{
label: "新建申请",
label: t("changes.newRequest"),
href: "/teacher/schedule-changes",
}}
/>
@@ -79,15 +84,15 @@ export default async function AdminSchedulingChangesPage({
)}
<div className="space-y-2">
<h3 className="text-lg font-semibold"></h3>
<h3 className="text-lg font-semibold">{t("changes.conflictDetection")}</h3>
<p className="text-sm text-muted-foreground">
{t("changes.conflictDetectionDescription")}
</p>
{classOptions.length === 0 ? (
<EmptyState
icon={ClipboardList}
title="暂无可用班级"
description="请先创建班级,再进行冲突检测。"
title={t("changes.noClassesTitle")}
description={t("changes.noClassesDescription")}
/>
) : (
<ScheduleConflictsView classes={classOptions} />
@@ -95,9 +100,9 @@ export default async function AdminSchedulingChangesPage({
</div>
<div className="space-y-2">
<h3 className="text-lg font-semibold"></h3>
<h3 className="text-lg font-semibold">{t("changes.scheduleGrid")}</h3>
<p className="text-sm text-muted-foreground">
{t("changes.scheduleGridDescription")}
</p>
<ScheduleGridView entries={scheduleEntries} classes={classOptions} />
</div>

View File

@@ -1,6 +1,7 @@
import { CalendarCog, ClipboardList } from "lucide-react"
import { CalendarCog, ClipboardList } from "lucide-react"
import type { Metadata } from "next"
import type { JSX } from "react"
import { getTranslations } from "next-intl/server"
import { requirePermission } from "@/shared/lib/auth-guard"
import { Permissions } from "@/shared/types/permissions"
@@ -11,14 +12,18 @@ import {
} from "@/modules/scheduling/data-access"
import { SchedulingRulesForm } from "@/modules/scheduling/components/scheduling-rules-form"
export const metadata: Metadata = {
title: "排课规则 - Next_Edu",
description: "配置每日课时上限、课间窗口与均衡偏好",
export async function generateMetadata(): Promise<Metadata> {
const t = await getTranslations("scheduling")
return {
title: `${t("rules.title")} - Next_Edu`,
description: t("rules.description"),
}
}
export const dynamic = "force-dynamic"
export default async function AdminSchedulingRulesPage(): Promise<JSX.Element> {
const t = await getTranslations("scheduling")
await requirePermission(Permissions.SCHEDULE_ADJUST)
const [classes, existingRules] = await Promise.all([
getAdminClassesForScheduling(),
@@ -30,17 +35,15 @@ export default async function AdminSchedulingRulesPage(): Promise<JSX.Element> {
return (
<div className="flex h-full flex-col space-y-8 p-8">
<div className="space-y-1">
<h2 className="text-2xl font-bold tracking-tight"></h2>
<p className="text-muted-foreground">
</p>
<h2 className="text-2xl font-bold tracking-tight">{t("rules.title")}</h2>
<p className="text-muted-foreground">{t("rules.description")}</p>
</div>
{classOptions.length === 0 ? (
<EmptyState
icon={ClipboardList}
title="暂无可用班级"
description="请先创建班级,再配置排课规则。"
title={t("rules.noClassesTitle")}
description={t("rules.noClassesDescription")}
/>
) : (
<SchedulingRulesForm classes={classOptions} existingRules={existingRules} />
@@ -48,7 +51,7 @@ export default async function AdminSchedulingRulesPage(): Promise<JSX.Element> {
<div className="flex items-center gap-2 text-xs text-muted-foreground">
<CalendarCog className="h-4 w-4" />
<span></span>
<span>{t("rules.hint")}</span>
</div>
</div>
)

View File

@@ -2,6 +2,7 @@ import Link from "next/link"
import type { Metadata } from "next"
import type { JSX } 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"
@@ -9,6 +10,7 @@ import { getGrades } from "@/modules/school/data-access"
import { getGradeHomeworkInsights } from "@/modules/classes/data-access"
import { getSchoolWideGradeSummary } from "@/modules/grades/data-access-analytics"
import { SchoolWideSummaryCard } from "@/modules/grades/components/school-wide-summary-card"
import { GradeInsightsFilters } from "@/modules/school/components/grade-insights-filters"
import { EmptyState } from "@/shared/components/ui/empty-state"
import { StatCard } from "@/shared/components/ui/stat-card"
import { Card, CardContent, CardHeader, CardTitle } from "@/shared/components/ui/card"
@@ -18,19 +20,23 @@ import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@
import { formatDate, formatNumber } from "@/shared/lib/utils"
import { getParam, type SearchParams } from "@/shared/lib/search-params"
export const metadata: Metadata = {
title: "年级作业洞察 - Next_Edu",
description: "按年级聚合的作业统计与班级排名",
}
export const dynamic = "force-dynamic"
export async function generateMetadata(): Promise<Metadata> {
const t = await getTranslations("school")
return {
title: `${t("grades.gradeInsights.title")} - Next_Edu`,
description: t("grades.gradeInsights.description"),
}
}
export default async function AdminGradeInsightsPage({
searchParams,
}: {
searchParams: Promise<SearchParams>
}): Promise<JSX.Element> {
const ctx = await requirePermission(Permissions.SCHOOL_MANAGE)
const t = await getTranslations("school")
const params = await searchParams
const gradeId = getParam(params, "gradeId")
const selected = gradeId && gradeId !== "all" ? gradeId : ""
@@ -43,15 +49,22 @@ export default async function AdminGradeInsightsPage({
getSchoolWideGradeSummary(ctx.dataScope),
])
const buildHref = (gId: string): string => {
const p = new URLSearchParams()
if (gId && gId !== "all") p.set("gradeId", gId)
const qs = p.toString()
return qs ? `/admin/school/grades/insights?${qs}` : "/admin/school/grades/insights"
}
return (
<div className="flex h-full flex-col space-y-8 p-8">
<div className="flex flex-col gap-4 md:flex-row md:items-end md:justify-between">
<div className="space-y-1">
<h2 className="text-2xl font-bold tracking-tight"></h2>
<p className="text-muted-foreground"></p>
<h2 className="text-2xl font-bold tracking-tight">{t("grades.gradeInsights.title")}</h2>
<p className="text-muted-foreground">{t("grades.gradeInsights.description")}</p>
</div>
<Button asChild variant="outline">
<Link href="/admin/school/grades"></Link>
<Link href="/admin/school/grades">{t("grades.gradeInsights.manageGrades")}</Link>
</Button>
</div>
@@ -60,86 +73,57 @@ export default async function AdminGradeInsightsPage({
<SchoolWideSummaryCard summary={schoolWideSummary} />
)}
<Card className="shadow-none">
<CardHeader className="flex flex-row items-center justify-between space-y-0">
<CardTitle className="text-base"></CardTitle>
<Badge variant="secondary" className="tabular-nums">
{grades.length}
</Badge>
</CardHeader>
<CardContent>
<form
action="/admin/school/grades/insights"
method="get"
className="flex flex-col gap-3 md:flex-row md:items-center"
>
<label htmlFor="grade-filter" className="text-sm font-medium">
</label>
<select
id="grade-filter"
name="gradeId"
defaultValue={selected || "all"}
className="h-10 w-full rounded-md border bg-background px-3 text-sm md:w-80"
>
<option value="all"></option>
{grades.map((g) => (
<option key={g.id} value={g.id}>
{g.school.name} / {g.name}
</option>
))}
</select>
<Button type="submit" className="md:ml-2">
</Button>
</form>
</CardContent>
</Card>
{/* 年级筛选ChipNav 即时切换,无整页刷新 */}
<GradeInsightsFilters
grades={grades.map((g) => ({ id: g.id, name: g.name, schoolName: g.school.name }))}
currentGradeId={selected || "all"}
buildHref={buildHref}
/>
{!selected ? (
<EmptyState
icon={BarChart3}
title="请选择年级以查看洞察"
description="选择一个年级,查看最新作业与历史成绩统计。"
title={t("grades.gradeInsights.selectToView")}
description={t("grades.gradeInsights.selectToViewDescription")}
className="h-80 bg-card"
/>
) : !insights ? (
<EmptyState
icon={BarChart3}
title="年级未找到"
description="该年级可能不存在或无可访问数据。"
title={t("grades.gradeInsights.notFound")}
description={t("grades.gradeInsights.notFoundDescription")}
className="h-80 bg-card"
/>
) : insights.assignments.length === 0 ? (
<EmptyState
icon={BarChart3}
title="该年级暂无作业数据"
description="尚未向该年级学生布置任何作业。"
title={t("grades.gradeInsights.noData")}
description={t("grades.gradeInsights.noDataDescription")}
className="h-80 bg-card"
/>
) : (
<div className="space-y-6">
<div className="grid gap-4 md:grid-cols-4">
<StatCard
title="班级数"
title={t("grades.gradeInsights.classes")}
value={insights.classCount}
description={`${insights.grade.school.name} / ${insights.grade.name}`}
valueClassName="tabular-nums"
/>
<StatCard
title="学生数"
title={t("grades.gradeInsights.students")}
value={insights.studentCounts.total}
description={`在读 ${insights.studentCounts.active}停用 ${insights.studentCounts.inactive}`}
description={`${t("grades.gradeInsights.active")} ${insights.studentCounts.active}${t("grades.gradeInsights.inactive")} ${insights.studentCounts.inactive}`}
valueClassName="tabular-nums"
/>
<StatCard
title="总体均分"
title={t("grades.gradeInsights.overallAvg")}
value={formatNumber(insights.overallScores.avg)}
description="基于已批改作业"
description="-"
valueClassName="tabular-nums"
/>
<StatCard
title="最新均分"
title={t("grades.gradeInsights.latestAvg")}
value={formatNumber(insights.latest?.scoreStats.avg ?? null)}
description={insights.latest?.title ?? "-"}
valueClassName="tabular-nums"
@@ -148,87 +132,93 @@ export default async function AdminGradeInsightsPage({
<Card className="shadow-none">
<CardHeader className="flex flex-row items-center justify-between space-y-0">
<CardTitle className="text-base"></CardTitle>
<CardTitle className="text-base">{t("grades.gradeInsights.homeworkTimeline")}</CardTitle>
<Badge variant="secondary" className="tabular-nums">
{insights.assignments.length}
</Badge>
</CardHeader>
<CardContent>
<div className="rounded-md border">
<Table>
<TableHeader>
<TableRow className="bg-muted/50">
<TableHead></TableHead>
<TableHead></TableHead>
<TableHead></TableHead>
<TableHead className="text-right"></TableHead>
<TableHead className="text-right"></TableHead>
<TableHead className="text-right"></TableHead>
<TableHead className="text-right"></TableHead>
<TableHead className="text-right"></TableHead>
</TableRow>
</TableHeader>
<TableBody>
{insights.assignments.map((a) => (
<TableRow key={a.assignmentId}>
<TableCell className="font-medium">{a.title}</TableCell>
<TableCell>
<Badge variant="secondary" className="capitalize">
{a.status}
</Badge>
</TableCell>
<TableCell className="text-muted-foreground">{formatDate(a.createdAt)}</TableCell>
<TableCell className="text-right tabular-nums">{a.targetCount}</TableCell>
<TableCell className="text-right tabular-nums">{a.submittedCount}</TableCell>
<TableCell className="text-right tabular-nums">{a.gradedCount}</TableCell>
<TableCell className="text-right tabular-nums">{formatNumber(a.scoreStats.avg)}</TableCell>
<TableCell className="text-right tabular-nums">{formatNumber(a.scoreStats.median)}</TableCell>
{/* v4-P1-10: 移动端表格水平滚动 */}
<div className="overflow-x-auto">
<Table>
<TableHeader>
<TableRow className="bg-muted/50">
<TableHead>{t("grades.gradeInsights.assignment")}</TableHead>
<TableHead>{t("grades.gradeInsights.status")}</TableHead>
<TableHead>{t("grades.gradeInsights.created")}</TableHead>
<TableHead className="text-right">{t("grades.gradeInsights.targeted")}</TableHead>
<TableHead className="text-right">{t("grades.gradeInsights.submitted")}</TableHead>
<TableHead className="text-right">{t("grades.gradeInsights.graded")}</TableHead>
<TableHead className="text-right">{t("grades.gradeInsights.avg")}</TableHead>
<TableHead className="text-right">{t("grades.gradeInsights.median")}</TableHead>
</TableRow>
))}
</TableBody>
</Table>
</TableHeader>
<TableBody>
{insights.assignments.map((a) => (
<TableRow key={a.assignmentId}>
<TableCell className="font-medium">{a.title}</TableCell>
<TableCell>
<Badge variant="secondary" className="capitalize">
{a.status}
</Badge>
</TableCell>
<TableCell className="text-muted-foreground">{formatDate(a.createdAt)}</TableCell>
<TableCell className="text-right tabular-nums">{a.targetCount}</TableCell>
<TableCell className="text-right tabular-nums">{a.submittedCount}</TableCell>
<TableCell className="text-right tabular-nums">{a.gradedCount}</TableCell>
<TableCell className="text-right tabular-nums">{formatNumber(a.scoreStats.avg)}</TableCell>
<TableCell className="text-right tabular-nums">{formatNumber(a.scoreStats.median)}</TableCell>
</TableRow>
))}
</TableBody>
</Table>
</div>
</div>
</CardContent>
</Card>
<Card className="shadow-none">
<CardHeader className="flex flex-row items-center justify-between space-y-0">
<CardTitle className="text-base"></CardTitle>
<CardTitle className="text-base">{t("grades.gradeInsights.classRanking")}</CardTitle>
<Badge variant="secondary" className="tabular-nums">
{insights.classes.length}
</Badge>
</CardHeader>
<CardContent>
<div className="rounded-md border">
<Table>
<TableHeader>
<TableRow className="bg-muted/50">
<TableHead></TableHead>
<TableHead className="text-right"></TableHead>
<TableHead className="text-right"></TableHead>
<TableHead className="text-right"></TableHead>
<TableHead className="text-right">Δ</TableHead>
<TableHead className="text-right"></TableHead>
</TableRow>
</TableHeader>
<TableBody>
{insights.classes.map((c) => (
<TableRow key={c.class.id}>
<TableCell className="font-medium">
{c.class.name}
{c.class.homeroom ? (
<span className="text-muted-foreground"> {c.class.homeroom}</span>
) : null}
</TableCell>
<TableCell className="text-right tabular-nums">{c.studentCounts.total}</TableCell>
<TableCell className="text-right tabular-nums">{formatNumber(c.latestAvg)}</TableCell>
<TableCell className="text-right tabular-nums">{formatNumber(c.prevAvg)}</TableCell>
<TableCell className="text-right tabular-nums">{formatNumber(c.deltaAvg)}</TableCell>
<TableCell className="text-right tabular-nums">{formatNumber(c.overallScores.avg)}</TableCell>
{/* v4-P1-10: 移动端表格水平滚动 */}
<div className="overflow-x-auto">
<Table>
<TableHeader>
<TableRow className="bg-muted/50">
<TableHead>{t("grades.gradeInsights.class")}</TableHead>
<TableHead className="text-right">{t("grades.gradeInsights.students")}</TableHead>
<TableHead className="text-right">{t("grades.gradeInsights.latestAvgCol")}</TableHead>
<TableHead className="text-right">{t("grades.gradeInsights.prevAvg")}</TableHead>
<TableHead className="text-right">{t("grades.gradeInsights.delta")}</TableHead>
<TableHead className="text-right">{t("grades.gradeInsights.overallAvgCol")}</TableHead>
</TableRow>
))}
</TableBody>
</Table>
</TableHeader>
<TableBody>
{insights.classes.map((c) => (
<TableRow key={c.class.id}>
<TableCell className="font-medium">
{c.class.name}
{c.class.homeroom ? (
<span className="text-muted-foreground"> {c.class.homeroom}</span>
) : null}
</TableCell>
<TableCell className="text-right tabular-nums">{c.studentCounts.total}</TableCell>
<TableCell className="text-right tabular-nums">{formatNumber(c.latestAvg)}</TableCell>
<TableCell className="text-right tabular-nums">{formatNumber(c.prevAvg)}</TableCell>
<TableCell className="text-right tabular-nums">{formatNumber(c.deltaAvg)}</TableCell>
<TableCell className="text-right tabular-nums">{formatNumber(c.overallScores.avg)}</TableCell>
</TableRow>
))}
</TableBody>
</Table>
</div>
</div>
</CardContent>
</Card>

View File

@@ -6,7 +6,7 @@ import { requirePermission } from "@/shared/lib/auth-guard"
import { Permissions } from "@/shared/types/permissions"
import { GradesClient } from "@/modules/school/components/grades-view"
import { SchoolErrorBoundary } from "@/modules/school/components/school-error-boundary"
import { getGrades, getSchools, getStaffOptions } from "@/modules/school/data-access"
import { getGrades, getSchools, getStaffOptions, getGradeOverviewStats } from "@/modules/school/data-access"
export const dynamic = "force-dynamic"
@@ -21,7 +21,12 @@ export async function generateMetadata(): Promise<Metadata> {
export default async function AdminGradesPage(): Promise<JSX.Element> {
await requirePermission(Permissions.SCHOOL_MANAGE)
const t = await getTranslations("school")
const [grades, schools, staff] = await Promise.all([getGrades(), getSchools(), getStaffOptions()])
const [grades, schools, staff, gradeStats] = await Promise.all([
getGrades(),
getSchools(),
getStaffOptions(),
getGradeOverviewStats(),
])
return (
<div className="flex h-full flex-col space-y-8 p-8">
@@ -30,7 +35,7 @@ export default async function AdminGradesPage(): Promise<JSX.Element> {
<p className="text-muted-foreground">{t("grades.description")}</p>
</div>
<SchoolErrorBoundary>
<GradesClient grades={grades} schools={schools} staff={staff} />
<GradesClient grades={grades} schools={schools} staff={staff} gradeStats={gradeStats} />
</SchoolErrorBoundary>
</div>
)

View File

@@ -1,13 +1,17 @@
import type { Metadata } from "next"
import type { JSX } from "react"
import { getTranslations } from "next-intl/server"
import { requirePermission } from "@/shared/lib/auth-guard"
import { Permissions } from "@/shared/types/permissions"
import { AdminSettingsView } from "@/modules/settings/components/admin-settings-view"
export const metadata: Metadata = {
title: "系统设置 - Next_Edu",
description: "管理系统基础信息与运行参数",
export async function generateMetadata(): Promise<Metadata> {
const t = await getTranslations("settings")
return {
title: `${t("admin.title")} - Next_Edu`,
description: t("admin.description"),
}
}
export const dynamic = "force-dynamic"

View File

@@ -1,7 +1,8 @@
import { Metadata } from "next"
import { Metadata } from "next"
import type { JSX } from "react"
import Link from "next/link"
import { ArrowLeft, Users, FileSpreadsheet, Info } from "lucide-react"
import { getTranslations } from "next-intl/server"
import { requirePermission } from "@/shared/lib/auth-guard"
import { Permissions } from "@/shared/types/permissions"
@@ -17,14 +18,18 @@ import {
} from "@/shared/components/ui/table"
import { UserImportDialog } from "@/modules/users/components/user-import-dialog"
export const metadata: Metadata = {
title: "批量导入用户 - Next_Edu",
description: "通过 Excel 批量导入用户",
export async function generateMetadata(): Promise<Metadata> {
const t = await getTranslations("users")
return {
title: `${t("import.title")} - Next_Edu`,
description: t("import.description"),
}
}
export const dynamic = "force-dynamic"
export default async function UserImportPage(): Promise<JSX.Element> {
const t = await getTranslations("users")
await requirePermission(Permissions.USER_MANAGE)
return (
<div className="h-full flex-1 flex-col space-y-6 p-8 md:flex">
@@ -34,13 +39,13 @@ export default async function UserImportPage(): Promise<JSX.Element> {
<Button asChild variant="ghost" size="sm">
<Link href="/admin/dashboard">
<ArrowLeft className="mr-1 h-4 w-4" />
{t("import.back")}
</Link>
</Button>
<h2 className="text-2xl font-bold tracking-tight"></h2>
<h2 className="text-2xl font-bold tracking-tight">{t("import.title")}</h2>
</div>
<p className="text-muted-foreground mt-1">
Excel
{t("import.subtitle")}
</p>
</div>
<UserImportDialog />
@@ -51,26 +56,26 @@ export default async function UserImportPage(): Promise<JSX.Element> {
<CardHeader>
<div className="flex items-center gap-2">
<FileSpreadsheet className="h-5 w-5 text-primary" />
<CardTitle className="text-base"></CardTitle>
<CardTitle className="text-base">{t("import.instructionsTitle")}</CardTitle>
</div>
<CardDescription>使 Excel </CardDescription>
<CardDescription>{t("import.instructionsDescription")}</CardDescription>
</CardHeader>
<CardContent className="space-y-3 text-sm">
<div className="flex gap-3">
<span className="flex h-6 w-6 shrink-0 items-center justify-center rounded-full bg-primary/10 text-xs font-medium text-primary">1</span>
<p></p>
<p>{t("import.step1")}</p>
</div>
<div className="flex gap-3">
<span className="flex h-6 w-6 shrink-0 items-center justify-center rounded-full bg-primary/10 text-xs font-medium text-primary">2</span>
<p></p>
<p>{t("import.step2")}</p>
</div>
<div className="flex gap-3">
<span className="flex h-6 w-6 shrink-0 items-center justify-center rounded-full bg-primary/10 text-xs font-medium text-primary">3</span>
<p> Excel </p>
<p>{t("import.step3")}</p>
</div>
<div className="flex gap-3">
<span className="flex h-6 w-6 shrink-0 items-center justify-center rounded-full bg-primary/10 text-xs font-medium text-primary">4</span>
<p></p>
<p>{t("import.step4")}</p>
</div>
</CardContent>
</Card>
@@ -79,17 +84,17 @@ export default async function UserImportPage(): Promise<JSX.Element> {
<CardHeader>
<div className="flex items-center gap-2">
<Info className="h-5 w-5 text-muted-foreground" />
<CardTitle className="text-base"></CardTitle>
<CardTitle className="text-base">{t("import.notesTitle")}</CardTitle>
</div>
<CardDescription></CardDescription>
<CardDescription>{t("import.notesDescription")}</CardDescription>
</CardHeader>
<CardContent className="space-y-2 text-sm text-muted-foreground">
<p> <code className="rounded bg-muted px-1 py-0.5 text-xs">123456</code></p>
<p> </p>
<p> admin / teacher / student / parent / grade_head / teaching_head</p>
<p> student </p>
<p> 10MB 500 </p>
<p> </p>
<p>{t("import.note1")}</p>
<p>{t("import.note2")}</p>
<p>{t("import.note3")}</p>
<p>{t("import.note4")}</p>
<p>{t("import.note5")}</p>
<p>{t("import.note6")}</p>
</CardContent>
</Card>
</div>
@@ -98,45 +103,45 @@ export default async function UserImportPage(): Promise<JSX.Element> {
<CardHeader>
<div className="flex items-center gap-2">
<Users className="h-5 w-5 text-primary" />
<CardTitle className="text-base"></CardTitle>
<CardTitle className="text-base">{t("import.templateTitle")}</CardTitle>
</div>
<CardDescription>Excel </CardDescription>
<CardDescription>{t("import.templateDescription")}</CardDescription>
</CardHeader>
<CardContent>
<div className="overflow-x-auto">
<Table>
<TableHeader>
<TableRow>
<TableHead></TableHead>
<TableHead></TableHead>
<TableHead></TableHead>
<TableHead>{t("import.columnName")}</TableHead>
<TableHead>{t("import.columnRequired")}</TableHead>
<TableHead>{t("import.columnDescription")}</TableHead>
</TableRow>
</TableHeader>
<TableBody>
<TableRow>
<TableCell className="font-medium"></TableCell>
<TableCell></TableCell>
<TableCell className="text-muted-foreground"></TableCell>
<TableCell className="font-medium">{t("import.fieldName")}</TableCell>
<TableCell>{t("import.fieldNameRequired")}</TableCell>
<TableCell className="text-muted-foreground">{t("import.fieldNameDescription")}</TableCell>
</TableRow>
<TableRow>
<TableCell className="font-medium"></TableCell>
<TableCell></TableCell>
<TableCell className="text-muted-foreground"></TableCell>
<TableCell className="font-medium">{t("import.fieldEmail")}</TableCell>
<TableCell>{t("import.fieldEmailRequired")}</TableCell>
<TableCell className="text-muted-foreground">{t("import.fieldEmailDescription")}</TableCell>
</TableRow>
<TableRow>
<TableCell className="font-medium"></TableCell>
<TableCell></TableCell>
<TableCell className="text-muted-foreground">admin / teacher / student / parent / grade_head / teaching_head</TableCell>
<TableCell className="font-medium">{t("import.fieldRole")}</TableCell>
<TableCell>{t("import.fieldRoleRequired")}</TableCell>
<TableCell className="text-muted-foreground">{t("import.fieldRoleDescription")}</TableCell>
</TableRow>
<TableRow>
<TableCell className="font-medium"></TableCell>
<TableCell></TableCell>
<TableCell className="text-muted-foreground"></TableCell>
<TableCell className="font-medium">{t("import.fieldPhone")}</TableCell>
<TableCell>{t("import.fieldPhoneRequired")}</TableCell>
<TableCell className="text-muted-foreground">{t("import.fieldPhoneDescription")}</TableCell>
</TableRow>
<TableRow>
<TableCell className="font-medium"></TableCell>
<TableCell></TableCell>
<TableCell className="text-muted-foreground"> student 6 </TableCell>
<TableCell className="font-medium">{t("import.fieldInviteCode")}</TableCell>
<TableCell>{t("import.fieldInviteCodeRequired")}</TableCell>
<TableCell className="text-muted-foreground">{t("import.fieldInviteCodeDescription")}</TableCell>
</TableRow>
</TableBody>
</Table>

View File

@@ -1,5 +1,6 @@
import type { Metadata } from "next"
import type { JSX } from "react"
import { getTranslations } from "next-intl/server"
import { requirePermission } from "@/shared/lib/auth-guard"
import { Permissions } from "@/shared/types/permissions"
@@ -7,9 +8,12 @@ import { getSearchParam, type SearchParams } from "@/shared/lib/utils"
import { getAdminUsers, getAdminUserRoles } from "@/modules/users/data-access"
import { AdminUsersView } from "@/modules/users/components/admin-users-view"
export const metadata: Metadata = {
title: "用户管理 - Next_Edu",
description: "管理系统所有用户",
export async function generateMetadata(): Promise<Metadata> {
const t = await getTranslations("users")
return {
title: `${t("title")} - Next_Edu`,
description: t("description"),
}
}
export const dynamic = "force-dynamic"

View File

@@ -0,0 +1,42 @@
import { Card, CardContent, CardHeader } from "@/shared/components/ui/card"
import { Skeleton } from "@/shared/components/ui/skeleton"
export default function ManagementGradeDashboardLoading() {
return (
<div className="flex h-full flex-col space-y-8 p-8">
<div className="space-y-2">
<Skeleton className="h-8 w-48" />
<Skeleton className="h-4 w-64" />
</div>
<Skeleton className="h-10 w-full max-w-md" />
<Skeleton className="h-10 w-full max-w-2xl" />
<div className="grid gap-4 md:grid-cols-2 lg:grid-cols-4">
{Array.from({ length: 4 }).map((_, i) => (
<Card key={i}>
<CardHeader className="pb-2">
<Skeleton className="h-4 w-24" />
</CardHeader>
<CardContent>
<Skeleton className="h-8 w-16" />
<Skeleton className="mt-2 h-3 w-28" />
</CardContent>
</Card>
))}
</div>
<Card>
<CardHeader>
<Skeleton className="h-5 w-32" />
</CardHeader>
<CardContent className="space-y-3">
{Array.from({ length: 6 }).map((_, i) => (
<Skeleton key={i} className="h-12 w-full" />
))}
</CardContent>
</Card>
</div>
)
}

View File

@@ -0,0 +1,178 @@
import type { Metadata } from "next"
import type { JSX } from "react"
import { getTranslations } from "next-intl/server"
import { requirePermission } from "@/shared/lib/auth-guard"
import { Permissions } from "@/shared/types/permissions"
import { getTeacherIdForMutations } from "@/modules/classes/data-access"
import { getGradeHomeworkInsights } from "@/modules/classes/data-access"
import { getGradesForStaff } from "@/modules/school/data-access"
import { getGradeDistributionByGradeId } from "@/modules/grades/data-access-analytics"
import { getExamsByGradeId } from "@/modules/exams/data-access"
import { getGradeCoursePlanProgress } from "@/modules/course-plans/data-access"
import { GradeInsightsFilters } from "@/modules/school/components/grade-insights-filters"
import { GradeDistributionPanel } from "@/modules/school/components/grade-dashboard/grade-distribution-panel"
import { GradeHomeworkPanel } from "@/modules/school/components/grade-dashboard/grade-homework-panel"
import { GradeExamsPanel } from "@/modules/school/components/grade-dashboard/grade-exams-panel"
import { GradeProgressPanel } from "@/modules/school/components/grade-dashboard/grade-progress-panel"
import { EmptyState } from "@/shared/components/ui/empty-state"
import { ChipNav } from "@/shared/components/ui/chip-nav"
import { BarChart3 } from "lucide-react"
import { getParam, type SearchParams } from "@/shared/lib/search-params"
export const dynamic = "force-dynamic"
const TAB_OPTIONS = [
{ id: "distribution", name: "" },
{ id: "homework", name: "" },
{ id: "exams", name: "" },
{ id: "progress", name: "" },
] as const
type TabId = (typeof TAB_OPTIONS)[number]["id"]
const isTabId = (v: string): v is TabId =>
v === "distribution" || v === "homework" || v === "exams" || v === "progress"
export async function generateMetadata(): Promise<Metadata> {
const t = await getTranslations("school")
return {
title: `${t("grades.gradeDashboard.title")} - Next_Edu`,
description: t("grades.gradeDashboard.description"),
}
}
export default async function GradeDashboardPage({
searchParams,
}: {
searchParams: Promise<SearchParams>
}): Promise<JSX.Element> {
const ctx = await requirePermission(Permissions.GRADE_RECORD_READ)
const t = await getTranslations("school")
const params = await searchParams
const gradeId = getParam(params, "gradeId")
const tabRaw = getParam(params, "tab") || "distribution"
const tab: TabId = isTabId(tabRaw) ? tabRaw : "distribution"
const teacherId = await getTeacherIdForMutations()
const grades = await getGradesForStaff(teacherId)
const allowedIds = new Set(grades.map((g) => g.id))
const selected = gradeId && gradeId !== "all" && allowedIds.has(gradeId) ? gradeId : ""
const buildHref = (gId: string): string => {
const p = new URLSearchParams()
if (gId && gId !== "all") p.set("gradeId", gId)
if (tab !== "distribution") p.set("tab", tab)
const qs = p.toString()
return qs ? `/management/grade/dashboard?${qs}` : "/management/grade/dashboard"
}
const buildTabHref = (tId: string): string => {
const p = new URLSearchParams()
if (selected) p.set("gradeId", selected)
if (tId !== "distribution") p.set("tab", tId)
const qs = p.toString()
return qs ? `/management/grade/dashboard?${qs}` : "/management/grade/dashboard"
}
const tabOptions = TAB_OPTIONS.map((o) => ({
id: o.id,
name: t(`grades.gradeDashboard.tabs.${o.id}` as const),
}))
if (grades.length === 0) {
return (
<div className="flex h-full flex-col space-y-8 p-8">
<div className="space-y-1">
<h2 className="text-2xl font-bold tracking-tight">{t("grades.gradeDashboard.title")}</h2>
<p className="text-muted-foreground">{t("grades.gradeDashboard.description")}</p>
</div>
<EmptyState
icon={BarChart3}
title={t("grades.gradeDashboard.selectToView")}
description={t("grades.gradeDashboard.selectToViewDescription")}
className="h-[360px] bg-card"
/>
</div>
)
}
// Fetch data for the active tab only
let distributionData = null
let homeworkData = null
let examsData = null
let progressData = null
if (selected) {
if (tab === "distribution") {
distributionData = await getGradeDistributionByGradeId({
gradeId: selected,
scope: ctx.dataScope,
})
} else if (tab === "homework") {
homeworkData = await getGradeHomeworkInsights({ gradeId: selected, limit: 50 })
} else if (tab === "exams") {
examsData = await getExamsByGradeId({ gradeId: selected, scope: ctx.dataScope })
} else if (tab === "progress") {
progressData = await getGradeCoursePlanProgress({ gradeId: selected })
}
}
return (
<div className="flex h-full flex-col space-y-8 p-8">
<div className="space-y-1">
<h2 className="text-2xl font-bold tracking-tight">{t("grades.gradeDashboard.title")}</h2>
<p className="text-muted-foreground">{t("grades.gradeDashboard.description")}</p>
</div>
<GradeInsightsFilters
grades={grades.map((g) => ({ id: g.id, name: g.name, schoolName: g.school.name }))}
currentGradeId={selected || "all"}
buildHref={buildHref}
/>
{!selected ? (
<EmptyState
icon={BarChart3}
title={t("grades.gradeDashboard.selectToView")}
description={t("grades.gradeDashboard.selectToViewDescription")}
className="h-[360px] bg-card"
/>
) : (
<div className="space-y-6">
<ChipNav
options={tabOptions}
currentId={tab}
buildHref={buildTabHref}
/>
{tab === "distribution" && distributionData && (
<GradeDistributionPanel data={distributionData} />
)}
{tab === "homework" && homeworkData && (
<GradeHomeworkPanel data={homeworkData} />
)}
{tab === "exams" && examsData && (
<GradeExamsPanel data={examsData} />
)}
{tab === "progress" && progressData && (
<GradeProgressPanel data={progressData} />
)}
{/* Fallback: data was null (e.g. homework insights returned null) */}
{((tab === "distribution" && !distributionData) ||
(tab === "homework" && !homeworkData) ||
(tab === "exams" && !examsData) ||
(tab === "progress" && !progressData)) && (
<EmptyState
icon={BarChart3}
title={t("grades.gradeDashboard.noData")}
description={t("grades.gradeDashboard.noDataDescription")}
className="h-[360px] bg-card"
/>
)}
</div>
)}
</div>
)
}

View File

@@ -7,25 +7,23 @@ import { Permissions } from "@/shared/types/permissions"
import { getTeacherIdForMutations } from "@/modules/classes/data-access"
import { getGradeHomeworkInsights } from "@/modules/classes/data-access"
import { getGradesForStaff } from "@/modules/school/data-access"
import { GradeInsightsFilters } from "@/modules/school/components/grade-insights-filters"
import { EmptyState } from "@/shared/components/ui/empty-state"
import { StatCard } from "@/shared/components/ui/stat-card"
import { Card, CardContent, CardHeader, CardTitle } from "@/shared/components/ui/card"
import { Badge } from "@/shared/components/ui/badge"
import { Button } from "@/shared/components/ui/button"
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/shared/components/ui/table"
import { BarChart3 } from "lucide-react"
import { formatDate } from "@/shared/lib/utils"
import { formatDate, formatNumber } from "@/shared/lib/utils"
import { getParam, type SearchParams } from "@/shared/lib/search-params"
export const dynamic = "force-dynamic"
const formatScore = (v: number | null, digits = 1) => (typeof v === "number" && Number.isFinite(v) ? v.toFixed(digits) : "-")
export async function generateMetadata(): Promise<Metadata> {
const t = await getTranslations("school")
return {
title: `${t("classManagement.grade.insights.title")} - Next_Edu`,
description: t("classManagement.grade.insights.description"),
title: `${t("grades.gradeInsights.title")} - Next_Edu`,
description: t("grades.gradeInsights.description"),
}
}
@@ -42,17 +40,24 @@ export default async function TeacherGradeInsightsPage({ searchParams }: { searc
const insights = selected ? await getGradeHomeworkInsights({ gradeId: selected, limit: 50 }) : null
const buildHref = (gId: string): string => {
const p = new URLSearchParams()
if (gId && gId !== "all") p.set("gradeId", gId)
const qs = p.toString()
return qs ? `/management/grade/insights?${qs}` : "/management/grade/insights"
}
if (grades.length === 0) {
return (
<div className="flex h-full flex-col space-y-8 p-8">
<div className="space-y-1">
<h2 className="text-2xl font-bold tracking-tight">{t("classManagement.grade.insights.title")}</h2>
<p className="text-muted-foreground">{t("classManagement.grade.insights.description")}</p>
<h2 className="text-2xl font-bold tracking-tight">{t("grades.gradeInsights.title")}</h2>
<p className="text-muted-foreground">{t("grades.gradeInsights.description")}</p>
</div>
<EmptyState
icon={BarChart3}
title={t("classManagement.grade.insights.noGrades")}
description={t("classManagement.grade.insights.noGradesDescription")}
title={t("grades.gradeInsights.selectToView")}
description={t("grades.gradeInsights.selectToViewDescription")}
className="h-[360px] bg-card"
/>
</div>
@@ -62,85 +67,62 @@ export default async function TeacherGradeInsightsPage({ searchParams }: { searc
return (
<div className="flex h-full flex-col space-y-8 p-8">
<div className="space-y-1">
<h2 className="text-2xl font-bold tracking-tight">{t("classManagement.grade.insights.title")}</h2>
<p className="text-muted-foreground">{t("classManagement.grade.insights.description")}</p>
<h2 className="text-2xl font-bold tracking-tight">{t("grades.gradeInsights.title")}</h2>
<p className="text-muted-foreground">{t("grades.gradeInsights.description")}</p>
</div>
<Card className="shadow-none">
<CardHeader className="flex flex-row items-center justify-between space-y-0">
<CardTitle className="text-base">{t("classManagement.grade.insights.filters")}</CardTitle>
<Badge variant="secondary" className="tabular-nums">
{grades.length}
</Badge>
</CardHeader>
<CardContent>
<form action="/management/grade/insights" method="get" className="flex flex-col gap-3 md:flex-row md:items-center">
<label htmlFor="gradeId" className="text-sm font-medium">{t("classManagement.grade.insights.grade")}</label>
<select
id="gradeId"
name="gradeId"
defaultValue={selected || "all"}
className="h-10 w-full rounded-md border bg-background px-3 text-sm md:w-[360px]"
>
<option value="all">{t("classManagement.grade.insights.selectGrade")}</option>
{grades.map((g) => (
<option key={g.id} value={g.id}>
{g.school.name} / {g.name}
</option>
))}
</select>
<Button type="submit" className="md:ml-2">
{t("classManagement.grade.insights.apply")}
</Button>
</form>
</CardContent>
</Card>
{/* 年级筛选ChipNav 即时切换,无整页刷新 */}
<GradeInsightsFilters
grades={grades.map((g) => ({ id: g.id, name: g.name, schoolName: g.school.name }))}
currentGradeId={selected || "all"}
buildHref={buildHref}
/>
{!selected ? (
<EmptyState
icon={BarChart3}
title={t("classManagement.grade.insights.selectToView")}
description={t("classManagement.grade.insights.selectToViewDescription")}
title={t("grades.gradeInsights.selectToView")}
description={t("grades.gradeInsights.selectToViewDescription")}
className="h-[360px] bg-card"
/>
) : !insights ? (
<EmptyState
icon={BarChart3}
title={t("classManagement.grade.insights.notFound")}
description={t("classManagement.grade.insights.notFoundDescription")}
title={t("grades.gradeInsights.notFound")}
description={t("grades.gradeInsights.notFoundDescription")}
className="h-[360px] bg-card"
/>
) : insights.assignments.length === 0 ? (
<EmptyState
icon={BarChart3}
title={t("classManagement.grade.insights.noData")}
description={t("classManagement.grade.insights.noDataDescription")}
title={t("grades.gradeInsights.noData")}
description={t("grades.gradeInsights.noDataDescription")}
className="h-[360px] bg-card"
/>
) : (
<div className="space-y-6">
<div className="grid gap-4 md:grid-cols-4">
<StatCard
title={t("classManagement.grade.insights.classes")}
title={t("grades.gradeInsights.classes")}
value={insights.classCount}
description={`${insights.grade.school.name} / ${insights.grade.name}`}
valueClassName="tabular-nums"
/>
<StatCard
title={t("classManagement.grade.insights.students")}
title={t("grades.gradeInsights.students")}
value={insights.studentCounts.total}
description={`${t("classManagement.grade.insights.active")} ${insights.studentCounts.active}${t("classManagement.grade.insights.inactive")} ${insights.studentCounts.inactive}`}
description={`${t("grades.gradeInsights.active")} ${insights.studentCounts.active}${t("grades.gradeInsights.inactive")} ${insights.studentCounts.inactive}`}
valueClassName="tabular-nums"
/>
<StatCard
title={t("classManagement.grade.insights.overallAvg")}
value={formatScore(insights.overallScores.avg)}
title={t("grades.gradeInsights.overallAvg")}
value={formatNumber(insights.overallScores.avg)}
description="-"
valueClassName="tabular-nums"
/>
<StatCard
title={t("classManagement.grade.insights.latestAvg")}
value={formatScore(insights.latest?.scoreStats.avg ?? null)}
title={t("grades.gradeInsights.latestAvg")}
value={formatNumber(insights.latest?.scoreStats.avg ?? null)}
description={insights.latest ? insights.latest.title : "-"}
valueClassName="tabular-nums"
/>
@@ -148,85 +130,91 @@ export default async function TeacherGradeInsightsPage({ searchParams }: { searc
<Card className="shadow-none">
<CardHeader className="flex flex-row items-center justify-between space-y-0">
<CardTitle className="text-base">{t("classManagement.grade.insights.homeworkTimeline")}</CardTitle>
<CardTitle className="text-base">{t("grades.gradeInsights.homeworkTimeline")}</CardTitle>
<Badge variant="secondary" className="tabular-nums">
{insights.assignments.length}
</Badge>
</CardHeader>
<CardContent>
<div className="rounded-md border">
<Table>
<TableHeader>
<TableRow className="bg-muted/50">
<TableHead>{t("classManagement.grade.insights.assignment")}</TableHead>
<TableHead>{t("classManagement.grade.insights.status")}</TableHead>
<TableHead>{t("classManagement.grade.insights.created")}</TableHead>
<TableHead className="text-right">{t("classManagement.grade.insights.targeted")}</TableHead>
<TableHead className="text-right">{t("classManagement.grade.insights.submitted")}</TableHead>
<TableHead className="text-right">{t("classManagement.grade.insights.graded")}</TableHead>
<TableHead className="text-right">{t("classManagement.grade.insights.avg")}</TableHead>
<TableHead className="text-right">{t("classManagement.grade.insights.median")}</TableHead>
</TableRow>
</TableHeader>
<TableBody>
{insights.assignments.map((a) => (
<TableRow key={a.assignmentId}>
<TableCell className="font-medium">{a.title}</TableCell>
<TableCell>
<Badge variant="secondary" className="capitalize">
{a.status}
</Badge>
</TableCell>
<TableCell className="text-muted-foreground">{formatDate(a.createdAt)}</TableCell>
<TableCell className="text-right tabular-nums">{a.targetCount}</TableCell>
<TableCell className="text-right tabular-nums">{a.submittedCount}</TableCell>
<TableCell className="text-right tabular-nums">{a.gradedCount}</TableCell>
<TableCell className="text-right tabular-nums">{formatScore(a.scoreStats.avg)}</TableCell>
<TableCell className="text-right tabular-nums">{formatScore(a.scoreStats.median)}</TableCell>
{/* v4-P1-11: 移动端表格水平滚动 */}
<div className="overflow-x-auto">
<Table>
<TableHeader>
<TableRow className="bg-muted/50">
<TableHead>{t("grades.gradeInsights.assignment")}</TableHead>
<TableHead>{t("grades.gradeInsights.status")}</TableHead>
<TableHead>{t("grades.gradeInsights.created")}</TableHead>
<TableHead className="text-right">{t("grades.gradeInsights.targeted")}</TableHead>
<TableHead className="text-right">{t("grades.gradeInsights.submitted")}</TableHead>
<TableHead className="text-right">{t("grades.gradeInsights.graded")}</TableHead>
<TableHead className="text-right">{t("grades.gradeInsights.avg")}</TableHead>
<TableHead className="text-right">{t("grades.gradeInsights.median")}</TableHead>
</TableRow>
))}
</TableBody>
</Table>
</TableHeader>
<TableBody>
{insights.assignments.map((a) => (
<TableRow key={a.assignmentId}>
<TableCell className="font-medium">{a.title}</TableCell>
<TableCell>
<Badge variant="secondary" className="capitalize">
{a.status}
</Badge>
</TableCell>
<TableCell className="text-muted-foreground">{formatDate(a.createdAt)}</TableCell>
<TableCell className="text-right tabular-nums">{a.targetCount}</TableCell>
<TableCell className="text-right tabular-nums">{a.submittedCount}</TableCell>
<TableCell className="text-right tabular-nums">{a.gradedCount}</TableCell>
<TableCell className="text-right tabular-nums">{formatNumber(a.scoreStats.avg)}</TableCell>
<TableCell className="text-right tabular-nums">{formatNumber(a.scoreStats.median)}</TableCell>
</TableRow>
))}
</TableBody>
</Table>
</div>
</div>
</CardContent>
</Card>
<Card className="shadow-none">
<CardHeader className="flex flex-row items-center justify-between space-y-0">
<CardTitle className="text-base">{t("classManagement.grade.insights.classRanking")}</CardTitle>
<CardTitle className="text-base">{t("grades.gradeInsights.classRanking")}</CardTitle>
<Badge variant="secondary" className="tabular-nums">
{insights.classes.length}
</Badge>
</CardHeader>
<CardContent>
<div className="rounded-md border">
<Table>
<TableHeader>
<TableRow className="bg-muted/50">
<TableHead>{t("classManagement.grade.insights.class")}</TableHead>
<TableHead className="text-right">{t("classManagement.grade.insights.students")}</TableHead>
<TableHead className="text-right">{t("classManagement.grade.insights.latestAvgCol")}</TableHead>
<TableHead className="text-right">{t("classManagement.grade.insights.prevAvg")}</TableHead>
<TableHead className="text-right">{t("classManagement.grade.insights.delta")}</TableHead>
<TableHead className="text-right">{t("classManagement.grade.insights.overallAvgCol")}</TableHead>
</TableRow>
</TableHeader>
<TableBody>
{insights.classes.map((c) => (
<TableRow key={c.class.id}>
<TableCell className="font-medium">
{c.class.name}
{c.class.homeroom ? <span className="text-muted-foreground"> {c.class.homeroom}</span> : null}
</TableCell>
<TableCell className="text-right tabular-nums">{c.studentCounts.total}</TableCell>
<TableCell className="text-right tabular-nums">{formatScore(c.latestAvg)}</TableCell>
<TableCell className="text-right tabular-nums">{formatScore(c.prevAvg)}</TableCell>
<TableCell className="text-right tabular-nums">{formatScore(c.deltaAvg)}</TableCell>
<TableCell className="text-right tabular-nums">{formatScore(c.overallScores.avg)}</TableCell>
{/* v4-P1-11: 移动端表格水平滚动 */}
<div className="overflow-x-auto">
<Table>
<TableHeader>
<TableRow className="bg-muted/50">
<TableHead>{t("grades.gradeInsights.class")}</TableHead>
<TableHead className="text-right">{t("grades.gradeInsights.students")}</TableHead>
<TableHead className="text-right">{t("grades.gradeInsights.latestAvgCol")}</TableHead>
<TableHead className="text-right">{t("grades.gradeInsights.prevAvg")}</TableHead>
<TableHead className="text-right">{t("grades.gradeInsights.delta")}</TableHead>
<TableHead className="text-right">{t("grades.gradeInsights.overallAvgCol")}</TableHead>
</TableRow>
))}
</TableBody>
</Table>
</TableHeader>
<TableBody>
{insights.classes.map((c) => (
<TableRow key={c.class.id}>
<TableCell className="font-medium">
{c.class.name}
{c.class.homeroom ? <span className="text-muted-foreground"> {c.class.homeroom}</span> : null}
</TableCell>
<TableCell className="text-right tabular-nums">{c.studentCounts.total}</TableCell>
<TableCell className="text-right tabular-nums">{formatNumber(c.latestAvg)}</TableCell>
<TableCell className="text-right tabular-nums">{formatNumber(c.prevAvg)}</TableCell>
<TableCell className="text-right tabular-nums">{formatNumber(c.deltaAvg)}</TableCell>
<TableCell className="text-right tabular-nums">{formatNumber(c.overallScores.avg)}</TableCell>
</TableRow>
))}
</TableBody>
</Table>
</div>
</div>
</CardContent>
</Card>

View 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("Grade 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>
)
}

View File

@@ -0,0 +1,16 @@
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-20 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>
)
}

View File

@@ -0,0 +1,141 @@
import type { Metadata } from "next"
import type { JSX } 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 { getParam, type SearchParams } from "@/shared/lib/search-params"
import { getTeacherIdForMutations } from "@/modules/classes/data-access"
import { getGradesForStaff } from "@/modules/school/data-access"
import { GradeInsightsFilters } from "@/modules/school/components/grade-insights-filters"
import {
getGradePracticeOverview,
getGradeClassPracticeComparison,
getPracticeTypeBreakdown,
} from "@/modules/adaptive-practice/data-access-analytics"
import { getUserIdsByGradeId } from "@/modules/users/data-access"
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"
export const dynamic = "force-dynamic"
export async function generateMetadata(): Promise<Metadata> {
const t = await getTranslations("practice")
return {
title: `${t("grade.title")} - Next_Edu`,
description: t("grade.description"),
}
}
export default async function GradePracticePage({
searchParams,
}: {
searchParams: Promise<SearchParams>
}): Promise<JSX.Element> {
await requirePermission(Permissions.ADAPTIVE_PRACTICE_READ)
const t = await getTranslations("practice")
const params = await searchParams
const gradeId = getParam(params, "gradeId")
const teacherId = await getTeacherIdForMutations()
const grades = await getGradesForStaff(teacherId)
const allowedIds = new Set(grades.map((g) => g.id))
const selected = gradeId && gradeId !== "all" && allowedIds.has(gradeId) ? gradeId : ""
const buildHref = (gId: string): string => {
const p = new URLSearchParams()
if (gId && gId !== "all") p.set("gradeId", gId)
const qs = p.toString()
return qs ? `/management/grade/practice?${qs}` : "/management/grade/practice"
}
if (grades.length === 0) {
return (
<div className="flex h-full flex-col space-y-8 p-8">
<div className="space-y-1">
<h2 className="text-2xl font-bold tracking-tight">{t("grade.title")}</h2>
<p className="text-muted-foreground">{t("grade.description")}</p>
</div>
<EmptyState
icon={BarChart3}
title={t("grade.noGrade")}
description={t("grade.noGradeDescription")}
className="h-[360px] bg-card"
/>
</div>
)
}
// 仅在选中年级时查询数据
let overview: Awaited<ReturnType<typeof getGradePracticeOverview>> = null
let classComparison: Awaited<ReturnType<typeof getGradeClassPracticeComparison>> = []
let typeBreakdown: Awaited<ReturnType<typeof getPracticeTypeBreakdown>> = []
if (selected) {
const studentIds = await getUserIdsByGradeId(selected)
const [ov, cmp, breakdown] = await Promise.all([
getGradePracticeOverview(selected),
getGradeClassPracticeComparison(selected),
getPracticeTypeBreakdown(studentIds),
])
overview = ov
classComparison = cmp
typeBreakdown = breakdown
}
return (
<div className="flex h-full flex-col space-y-8 p-8">
<div className="space-y-1">
<h2 className="text-2xl font-bold tracking-tight">{t("grade.title")}</h2>
<p className="text-muted-foreground">{t("grade.description")}</p>
</div>
<GradeInsightsFilters
grades={grades.map((g) => ({ id: g.id, name: g.name, schoolName: g.school.name }))}
currentGradeId={selected || "all"}
buildHref={buildHref}
/>
{!selected ? (
<EmptyState
icon={BarChart3}
title={t("grade.noGrade")}
description={t("grade.noGradeDescription")}
className="h-[360px] bg-card"
/>
) : !overview ? (
<EmptyState
icon={BarChart3}
title={t("teacher.noData")}
description={t("teacher.noDataDescription")}
className="h-[360px] bg-card"
/>
) : (
<div className="space-y-6">
{/* 年级整体统计卡片 */}
<PracticeOverviewStatsCards
totalClasses={overview.totalClasses}
totalSessions={overview.totalSessions}
totalAnswered={overview.totalQuestionsAnswered}
averageAccuracy={overview.averageAccuracy}
participationRate={overview.participationRate}
/>
{/* 各班级练习对比表 */}
{classComparison.length > 0 ? (
<ClassPracticeComparisonTable data={classComparison} />
) : null}
{/* 练习类型分布图 */}
{typeBreakdown.length > 0 ? (
<PracticeTypeBreakdownChart data={typeBreakdown} />
) : null}
</div>
)}
</div>
)
}

View File

@@ -14,6 +14,7 @@ import {
} from "@/modules/parent/components/child-detail-panel"
import { EmptyState } from "@/shared/components/ui/empty-state"
import { ShieldAlert } from "lucide-react"
import { getTranslations } from "next-intl/server"
export const dynamic = "force-dynamic"
@@ -27,6 +28,7 @@ export default async function ChildDetailPage({
const { studentId } = await params
const sp = await searchParams
const ctx = await requireAuth()
const t = await getTranslations("common")
// 校验当前家长与该子女存在关系(同时按 parentId + studentId 过滤,防止跨家庭信息泄露)
const relation = await verifyParentChildRelation(studentId, ctx.userId)
@@ -41,8 +43,8 @@ export default async function ChildDetailPage({
<div className="p-6 md:p-8">
<EmptyState
icon={ShieldAlert}
title="Access denied"
description="This student is not linked to your account. Please contact the school administrator if you believe this is an error."
title={t("accessDenied")}
description={t("accessDeniedDesc")}
className="border-none shadow-none"
/>
</div>

View File

@@ -11,6 +11,7 @@ import {
} from "@/modules/parent/components/parent-children-data-page"
import { getUserNamesByIds } from "@/modules/users/data-access"
import { Card, CardContent } from "@/shared/components/ui/card"
import { getTranslations } from "next-intl/server"
export const dynamic = "force-dynamic"
@@ -34,15 +35,16 @@ type ChildDiagnosticItem = ChildDiagnosticSuccessItem | ChildDiagnosticErrorItem
export default async function ParentDiagnosticPage() {
const ctx = await requirePermission(Permissions.DIAGNOSTIC_READ)
const t = await getTranslations("diagnostic")
if (ctx.dataScope.type !== "children" || ctx.dataScope.childrenIds.length === 0) {
return (
<ParentNoChildrenPage
title="Children Diagnostic"
description="View your children's knowledge point mastery and diagnostic reports."
title={t("parent.title")}
description={t("parent.description")}
icon={Stethoscope}
emptyTitle="No children linked"
emptyDescription="Your account is not linked to any student accounts yet. Please contact the school administrator."
emptyTitle={t("parent.noChildren")}
emptyDescription={t("parent.noChildrenDesc")}
/>
)
}
@@ -68,7 +70,7 @@ export default async function ParentDiagnosticPage() {
const items: ChildDiagnosticItem[] = results.map((r, idx) => {
const studentId = childrenIds[idx]
const studentName = nameMap.get(studentId)?.name ?? "Unknown student"
const studentName = nameMap.get(studentId)?.name ?? t("parent.selectChild")
if (r.status === "fulfilled") {
return {
studentId,
@@ -88,11 +90,11 @@ export default async function ParentDiagnosticPage() {
return (
<ParentChildrenDataPage
title="Children Diagnostic"
description="View knowledge point mastery and diagnostic reports for all your children."
title={t("parent.title")}
description={t("parent.description")}
icon={Stethoscope}
noRecordsTitle="No diagnostic data"
noRecordsDescription="Your children don't have any diagnostic data yet."
noRecordsTitle={t("parent.noReports")}
noRecordsDescription={t("parent.noReports")}
items={items}
renderItem={(item) => (
<>
@@ -111,10 +113,10 @@ export default async function ParentDiagnosticPage() {
<CardContent className="flex flex-col items-center gap-3 py-8 text-center">
<AlertCircle className="h-8 w-8 text-destructive" aria-hidden="true" />
<p className="text-sm font-medium text-destructive">
Failed to load diagnostic data for {item.studentName}.
{t("error.loadFailed")} for {item.studentName}.
</p>
<p className="text-xs text-muted-foreground">
Please refresh the page or contact the school administrator if the problem persists.
{t("error.loadFailed")}. Please refresh the page or contact the school administrator if the problem persists.
</p>
</CardContent>
</Card>

View File

@@ -17,23 +17,25 @@ import {
} 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"
import { getTranslations } from "next-intl/server"
export const dynamic = "force-dynamic"
export default async function ParentErrorBookPage(): Promise<JSX.Element> {
const ctx = await requirePermission(Permissions.ERROR_BOOK_READ)
const t = await getTranslations("errorBook")
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>
<h1 className="text-2xl font-bold tracking-tight">{t("parent.title")}</h1>
<p className="text-muted-foreground">{t("parent.description")}</p>
</div>
<EmptyState
icon={Users}
title="暂无子女关联"
description="您的账号尚未关联子女,请联系学校管理员进行关联。"
title={t("parent.noChild")}
description={t("parent.noChildDesc")}
className="h-[360px] bg-card"
/>
</div>
@@ -56,8 +58,8 @@ export default async function ParentErrorBookPage(): Promise<JSX.Element> {
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>
<h1 className="text-2xl font-bold tracking-tight">{t("parent.title")}</h1>
<p className="text-muted-foreground">{t("parent.description")}</p>
</div>
{childrenIds.length === 1 ? (
@@ -68,35 +70,35 @@ export default async function ParentErrorBookPage(): Promise<JSX.Element> {
<div className="grid gap-4 md:grid-cols-2">
{childrenIds.map((childId, idx) => {
const stats = childStatsList[idx]
const name = nameMap.get(childId) ?? "未知"
const name = nameMap.get(childId) ?? t("parent.unknown")
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)}%
{t("parent.mastery", { rate: 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-muted-foreground">{t("parent.totalErrors")}</div>
<div className="text-lg font-bold">{stats.totalCount}</div>
</div>
<div>
<div className="text-muted-foreground"></div>
<div className="text-muted-foreground">{t("parent.dueReview")}</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="text-muted-foreground">{t("parent.newItems")}</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="text-muted-foreground">{t("parent.mastered")}</div>
<div className="font-medium text-emerald-600 dark:text-emerald-400">{stats.masteredCount}</div>
</div>
</div>
@@ -112,7 +114,7 @@ export default async function ParentErrorBookPage(): Promise<JSX.Element> {
{weakKps.length > 0 ? (
<Card>
<CardHeader>
<CardTitle className="text-base"></CardTitle>
<CardTitle className="text-base">{t("parent.weakPoints")}</CardTitle>
</CardHeader>
<CardContent>
<div className="space-y-3">
@@ -121,7 +123,7 @@ export default async function ParentErrorBookPage(): Promise<JSX.Element> {
<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)}%
{t("parent.errorsAndMastery", { count: kp.errorCount, rate: formatNumber(kp.masteryRate * 100, 0) })}
</span>
</div>
<Progress value={kp.masteryRate * 100} className="h-1.5" />

View File

@@ -2,6 +2,7 @@
import { EmptyState } from "@/shared/components/ui/empty-state"
import { AlertTriangle } from "lucide-react"
import { useTranslations } from "next-intl"
export default function ParentError({
error,
@@ -10,13 +11,15 @@ export default function ParentError({
error: Error & { digest?: string }
reset: () => void
}) {
const t = useTranslations("common")
return (
<div className="p-6 md:p-8">
<EmptyState
icon={AlertTriangle}
title="Something went wrong"
title={t("somethingWentWrong")}
description={error.message || "An unexpected error occurred. Please try again."}
action={{ label: "Try again", onClick: reset }}
action={{ label: t("tryAgain"), onClick: reset }}
/>
</div>
)

View File

@@ -11,6 +11,7 @@ import {
import { ParentExportButton } from "@/modules/parent/components/parent-export-button"
import { GraduationCap } from "lucide-react"
import type { ClassAverageTrendResult } from "@/modules/grades/types"
import { getTranslations } from "next-intl/server"
export const dynamic = "force-dynamic"
@@ -22,15 +23,16 @@ interface ChildGradeItem {
export default async function ParentGradesPage() {
const ctx = await requirePermission(Permissions.GRADE_RECORD_READ)
const t = await getTranslations("grades")
if (ctx.dataScope.type !== "children" || ctx.dataScope.childrenIds.length === 0) {
return (
<ParentNoChildrenPage
title="Children Grades"
description="View your children's grade records."
title={t("parent.title")}
description={t("parent.description")}
icon={GraduationCap}
emptyTitle="No children linked"
emptyDescription="Your account is not linked to any student accounts yet. Please contact the school administrator."
emptyTitle={t("parent.noChildren")}
emptyDescription={t("parent.noChildrenDesc")}
/>
)
}
@@ -64,11 +66,11 @@ export default async function ParentGradesPage() {
return (
<ParentChildrenDataPage
title="Children Grades"
description="Compare grades across all your children. For single-child analysis, open the child's detail page."
title={t("parent.title")}
description={t("parent.description")}
icon={GraduationCap}
noRecordsTitle="No grade records"
noRecordsDescription="Your children don't have any grade records yet."
noRecordsTitle={t("parent.noGrades")}
noRecordsDescription={t("parent.noGradesDesc")}
items={validItems}
renderItem={({ studentId, summary, classAverageTrend }) => (
<>

View File

@@ -4,23 +4,26 @@ import { CalendarDays, ArrowLeft, Phone, Mail } from "lucide-react"
import { Button } from "@/shared/components/ui/button"
import { Card, CardContent, CardHeader, CardTitle } from "@/shared/components/ui/card"
import { EmptyState } from "@/shared/components/ui/empty-state"
import { getTranslations } from "next-intl/server"
export const dynamic = "force-dynamic"
export default async function ParentLeavePage() {
const t = await getTranslations("leave")
return (
<div className="p-6 md:p-8 space-y-6">
<div className="space-y-1">
<h1 className="text-2xl font-bold tracking-tight">Leave Request</h1>
<h1 className="text-2xl font-bold tracking-tight">{t("title")}</h1>
<p className="text-sm text-muted-foreground">
Submit a leave request for your child.
{t("description")}
</p>
</div>
<Button asChild variant="ghost" size="sm" className="gap-2 -ml-2">
<Link href="/parent/dashboard" aria-label="Back to Dashboard">
<Link href="/parent/dashboard" aria-label={t("backToDashboard")}>
<ArrowLeft className="h-4 w-4" />
Back to Dashboard
{t("backToDashboard")}
</Link>
</Button>
@@ -28,33 +31,33 @@ export default async function ParentLeavePage() {
<CardHeader>
<CardTitle className="flex items-center gap-2 text-base">
<CalendarDays className="h-4 w-4 text-muted-foreground" aria-hidden />
Online Leave Request
{t("onlineLeave")}
</CardTitle>
</CardHeader>
<CardContent className="space-y-4">
<EmptyState
icon={CalendarDays}
title="Coming soon"
description="The online leave request feature is being developed and will be available soon. For now, please contact the homeroom teacher or school office directly."
title={t("comingSoon")}
description={t("comingSoonDesc")}
className="border-none shadow-none"
/>
<div className="rounded-md border bg-muted/30 p-4 space-y-2">
<div className="text-sm font-medium">Contact options</div>
<div className="text-sm font-medium">{t("contactOptions")}</div>
<ul className="space-y-2 text-sm text-muted-foreground">
<li className="flex items-center gap-2">
<Phone className="h-4 w-4" aria-hidden />
<span>Call the school office during working hours</span>
<span>{t("callOffice")}</span>
</li>
<li className="flex items-center gap-2">
<Mail className="h-4 w-4" aria-hidden />
<span>Send a message to the homeroom teacher via the Messages page</span>
<span>{t("sendMessage")}</span>
</li>
<li>
<Link
href="/messages"
className="inline-flex h-9 items-center rounded-md bg-primary px-3 text-sm font-medium text-primary-foreground hover:bg-primary/90 transition-colors mt-2 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2"
>
Go to Messages
{t("goToMessages")}
</Link>
</li>
</ul>

View 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 ParentLessonPlanViewError() {
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>
)
}

View File

@@ -0,0 +1,11 @@
import { Skeleton } from "@/shared/components/ui/skeleton"
export default function ParentLessonPlanViewLoading() {
return (
<div className="h-[calc(100vh-4rem)]">
<div className="flex h-full items-center justify-center">
<Skeleton className="h-[80%] w-[80%]" />
</div>
</div>
)
}

View File

@@ -0,0 +1,81 @@
import type { JSX } from "react"
import { Suspense } from "react"
import { getTranslations } from "next-intl/server"
import { getAuthContext } from "@/shared/lib/auth-guard"
import { getLessonPlanById } from "@/modules/lesson-preparation/data-access"
import { getTextbookById, getChaptersByTextbookId } from "@/modules/textbooks/data-access"
import { LessonPlanReadonlyView } from "@/modules/lesson-preparation/components/lesson-plan-readonly-view"
import { Skeleton } from "@/shared/components/ui/skeleton"
export const dynamic = "force-dynamic"
export default async function ParentLessonPlanViewPage({
params,
}: {
params: Promise<{ planId: string }>
}): Promise<JSX.Element> {
const { planId } = await params
const t = await getTranslations("lessonPreparation")
const ctx = await getAuthContext()
const plan = await getLessonPlanById(planId, ctx.userId)
if (!plan) {
return (
<div className="p-6">
<div className="rounded-md border border-outline-variant bg-surface-container-low p-4 text-on-surface-variant">
{t("readonly.notFound")}
</div>
</div>
)
}
if (plan.status !== "published") {
return (
<div className="p-6">
<div className="rounded-md border border-outline-variant bg-surface-container-low p-4 text-on-surface-variant">
{t("readonly.notPublished")}
</div>
</div>
)
}
let textbookTitle: string | undefined
let chapterTitle: string | undefined
if (plan.textbookId) {
const textbook = await getTextbookById(plan.textbookId)
textbookTitle = textbook?.title
if (plan.chapterId) {
const chapters = await getChaptersByTextbookId(plan.textbookId)
const findChapter = (list: typeof chapters): typeof chapters[number] | undefined => {
for (const ch of list) {
if (ch.id === plan.chapterId) return ch
if (ch.children && ch.children.length > 0) {
const found = findChapter(ch.children as typeof chapters)
if (found) return found
}
}
return undefined
}
const chapter = findChapter(chapters)
chapterTitle = chapter?.title
}
}
return (
<div className="h-[calc(100vh-4rem)]">
<Suspense
fallback={
<div className="flex h-full items-center justify-center">
<Skeleton className="h-[80%] w-[80%]" />
</div>
}
>
<LessonPlanReadonlyView
doc={plan.content}
textbookTitle={textbookTitle}
chapterTitle={chapterTitle}
/>
</Suspense>
</div>
)
}

View 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 ParentLessonPlansError() {
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>
)
}

View File

@@ -0,0 +1,17 @@
import { Skeleton } from "@/shared/components/ui/skeleton"
export default function ParentLessonPlansLoading() {
return (
<div className="p-6 space-y-4">
<div className="space-y-2">
<Skeleton className="h-8 w-[180px]" />
<Skeleton className="h-4 w-[300px]" />
</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>
)
}

View File

@@ -0,0 +1,44 @@
import type { JSX } from "react"
import { Suspense } from "react"
import { getTranslations } from "next-intl/server"
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 { Skeleton } from "@/shared/components/ui/skeleton"
export const dynamic = "force-dynamic"
export default async function ParentLessonPlansPage(): Promise<JSX.Element> {
const t = await getTranslations("lessonPreparation")
const ctx = await getAuthContext()
const [items, subjects] = await Promise.all([
getLessonPlans({ status: "published" }, ctx.dataScope, ctx.userId),
getSubjectOptions(),
])
return (
<div className="p-6 space-y-4">
<div>
<h1 className="text-2xl font-bold tracking-tight">{t("parent.title")}</h1>
<p className="text-muted-foreground">{t("parent.description")}</p>
</div>
<Suspense
fallback={
<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>
}
>
<LessonPlanList
initialItems={items}
subjects={subjects}
viewMode="parent"
/>
</Suspense>
</div>
)
}

View File

@@ -14,7 +14,7 @@ export default function StudentAttendanceError({ reset }: { error: Error & { dig
title={t("errors.unexpected")}
description={t("errors.unexpected")}
action={{
label: t("actions.save"),
label: t("actions.retry"),
onClick: () => reset(),
}}
className="border-none shadow-none h-auto"

View File

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

View File

@@ -1,4 +1,6 @@
import { Stethoscope } from "lucide-react"
import { getTranslations } from "next-intl/server"
import { requirePermission } from "@/shared/lib/auth-guard"
import { Permissions } from "@/shared/types/permissions"
import { getStudentMasterySummary } from "@/modules/diagnostic/data-access"
@@ -9,6 +11,7 @@ export const dynamic = "force-dynamic"
export default async function StudentDiagnosticPage() {
const ctx = await requirePermission(Permissions.DIAGNOSTIC_READ)
const t = await getTranslations("student")
const [summary, reportsResult] = await Promise.all([
getStudentMasterySummary(ctx.userId),
@@ -25,10 +28,10 @@ export default async function StudentDiagnosticPage() {
<div>
<h2 className="flex items-center gap-2 text-2xl font-bold tracking-tight">
<Stethoscope className="h-6 w-6" />
My Diagnostic
{t("diagnostic.title")}
</h2>
<p className="text-muted-foreground">
Your knowledge point mastery analysis and diagnostic reports.
{t("diagnostic.description")}
</p>
</div>
<StudentDiagnosticView summary={summary} reports={reports} />

View File

@@ -14,7 +14,7 @@ export default function StudentElectiveError({ reset }: { error: Error & { diges
title={t("errors.unexpected")}
description={t("errors.unexpected")}
action={{
label: t("actions.save"),
label: t("actions.retry"),
onClick: () => reset(),
}}
className="border-none shadow-none h-auto"

View File

@@ -1,17 +1,19 @@
"use client"
import { BookX } from "lucide-react"
import { useTranslations } from "next-intl"
import { EmptyState } from "@/shared/components/ui/empty-state"
export default function StudentErrorBookError() {
const t = useTranslations("student")
return (
<div className="p-8">
<EmptyState
icon={BookX}
title="加载错题本失败"
description="发生了一些错误,请刷新页面重试。如果问题持续,请联系管理员。"
action={{ label: "刷新页面", onClick: () => window.location.reload() }}
title={t("error.title")}
description={t("error.description")}
action={{ label: t("error.retry"), onClick: () => window.location.reload() }}
className="border-none shadow-none"
/>
</div>

View File

@@ -1,5 +1,6 @@
import type { JSX } from "react"
import { Suspense } from "react"
import { getTranslations } from "next-intl/server"
import { requirePermission } from "@/shared/lib/auth-guard"
import { Permissions } from "@/shared/types/permissions"
@@ -92,6 +93,7 @@ export default async function StudentErrorBookPage({
searchParams: Promise<SearchParams>
}): Promise<JSX.Element> {
const ctx = await requirePermission(Permissions.ERROR_BOOK_READ)
const t = await getTranslations("student")
const stats = await getErrorBookStats(ctx.userId)
const aiClientService = createAiClientService()
@@ -100,9 +102,9 @@ export default async function StudentErrorBookPage({
<div className="flex h-full flex-col space-y-8 p-8">
<div className="flex flex-col justify-between space-y-4 md:flex-row md:items-center md:space-y-0">
<div>
<h1 className="text-2xl font-bold tracking-tight"></h1>
<h1 className="text-2xl font-bold tracking-tight">{t("errorBook.title")}</h1>
<p className="text-muted-foreground">
{t("errorBook.description")}
</p>
</div>
<div className="flex items-center gap-2">

View File

@@ -1,7 +1,9 @@
"use client"
import { EmptyState } from "@/shared/components/ui/empty-state"
import { AlertTriangle } from "lucide-react"
import { useTranslations } from "next-intl"
import { EmptyState } from "@/shared/components/ui/empty-state"
export default function StudentError({
error,
@@ -10,12 +12,13 @@ export default function StudentError({
error: Error & { digest?: string }
reset: () => void
}) {
const t = useTranslations("student")
return (
<EmptyState
icon={AlertTriangle}
title="Something went wrong"
description={error.message || "An unexpected error occurred. Please try again."}
action={{ label: "Try again", onClick: reset }}
title={t("error.title")}
description={error.message || t("error.description")}
action={{ label: t("error.retry"), onClick: reset }}
/>
)
}

View File

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

View File

@@ -20,6 +20,7 @@ export default async function StudentGradesPage({
searchParams: Promise<SearchParams>
}) {
const ctx = await requirePermission(Permissions.GRADE_RECORD_READ)
const t = await getTranslations("grades")
const [sp, summary, rankingTrend, classAverageTrend, subjectOptions] = await Promise.all([
searchParams,
getStudentGradeSummary(ctx.userId, ctx.dataScope),
@@ -32,7 +33,6 @@ export default async function StudentGradesPage({
])
if (!summary) {
const t = await getTranslations("grades")
return (
<div className="space-y-8">
<div>
@@ -73,7 +73,7 @@ export default async function StudentGradesPage({
<div className="space-y-8">
<div>
<h2 className="text-2xl font-bold tracking-tight">{summary.studentName}</h2>
<p className="text-muted-foreground">{summary.records.length} </p>
<p className="text-muted-foreground">{t("summary.recordCount", { count: summary.records.length })}</p>
</div>
<GradeFilters subjects={subjectOptions.map((s) => ({ id: s.id, name: s.name }))} />
{filteredSummary.records.length > 0 && (

View File

@@ -1,4 +1,5 @@
import { notFound } from "next/navigation"
import { getTranslations } from "next-intl/server"
import { getStudentHomeworkTakeData } from "@/modules/homework/data-access"
import { getCurrentStudentUser } from "@/modules/users/data-access"
@@ -17,6 +18,8 @@ export default async function StudentAssignmentTakePage({
const student = await getCurrentStudentUser()
if (!student) return notFound()
const t = await getTranslations("student")
const data = await getStudentHomeworkTakeData(assignmentId, student.id)
if (!data) return notFound()
@@ -28,7 +31,7 @@ export default async function StudentAssignmentTakePage({
<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">
<span>Due: {data.assignment.dueAt ? formatDate(data.assignment.dueAt) : "-"}</span>
<span>{t("assignment.due", { date: data.assignment.dueAt ? formatDate(data.assignment.dueAt) : "-" })}</span>
</div>
</div>
@@ -42,9 +45,9 @@ export default async function StudentAssignmentTakePage({
<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">
<span>Due: {data.assignment.dueAt ? formatDate(data.assignment.dueAt) : "-"}</span>
<span>{t("assignment.due", { date: data.assignment.dueAt ? formatDate(data.assignment.dueAt) : "-" })}</span>
<span className="mx-2" aria-hidden="true"></span>
<span>Max Attempts: {data.assignment.maxAttempts}</span>
<span>{t("assignment.maxAttempts", { count: data.assignment.maxAttempts })}</span>
</div>
</div>

View File

@@ -10,6 +10,7 @@ import {
School,
User,
} from "lucide-react"
import { getTranslations } from "next-intl/server"
import { getStudentClassById, getStudentSchedule } from "@/modules/classes/data-access"
import { getCurrentStudentUser } from "@/modules/users/data-access"
@@ -20,14 +21,14 @@ import { EmptyState } from "@/shared/components/ui/empty-state"
export const dynamic = "force-dynamic"
const WEEKDAYS: Record<number, string> = {
1: "Mon",
2: "Tue",
3: "Wed",
4: "Thu",
5: "Fri",
6: "Sat",
7: "Sun",
const WEEKDAY_KEYS: Record<number, string> = {
1: "mon",
2: "tue",
3: "wed",
4: "thu",
5: "fri",
6: "sat",
7: "sun",
}
export default async function StudentClassDetailPage({
@@ -39,6 +40,8 @@ export default async function StudentClassDetailPage({
const student = await getCurrentStudentUser()
if (!student) return notFound()
const t = await getTranslations("student")
const [classInfo, schedule] = await Promise.all([
getStudentClassById(student.id, classId),
getStudentSchedule(student.id),
@@ -58,14 +61,14 @@ export default async function StudentClassDetailPage({
<Button asChild variant="ghost" size="sm" className="-ml-2 mb-1">
<Link href="/student/learning/courses">
<ChevronLeft className="mr-1 h-4 w-4" />
Back to Courses
{t("classDetail.backToCourses")}
</Link>
</Button>
<h2 className="text-2xl font-bold tracking-tight">{classInfo.name}</h2>
<div className="flex flex-wrap items-center gap-2 text-sm text-muted-foreground">
<span className="flex items-center gap-1">
<BookOpen className="h-4 w-4" />
Grade {classInfo.grade}
{t("classDetail.grade", { grade: classInfo.grade })}
</span>
{classInfo.homeroom && (
<>
@@ -78,24 +81,24 @@ export default async function StudentClassDetailPage({
<span aria-hidden="true"></span>
<span className="flex items-center gap-1">
<Building2 className="h-4 w-4" />
Room {classInfo.room}
{t("classDetail.room", { room: classInfo.room })}
</span>
</>
)}
<Badge variant="secondary">Active</Badge>
<Badge variant="secondary">{t("classDetail.active")}</Badge>
</div>
</div>
<div className="flex gap-2">
<Button asChild variant="outline" size="sm">
<Link href={`/student/schedule?classId=${encodeURIComponent(classInfo.id)}`}>
<CalendarDays className="mr-2 h-4 w-4" />
Full Schedule
{t("classDetail.fullSchedule")}
</Link>
</Button>
<Button asChild size="sm">
<Link href="/student/learning/assignments">
<PenTool className="mr-2 h-4 w-4" />
Assignments
{t("classDetail.assignments")}
</Link>
</Button>
</div>
@@ -107,7 +110,7 @@ export default async function StudentClassDetailPage({
<CardHeader className="pb-3">
<CardTitle className="flex items-center gap-2 text-sm font-medium">
<User className="h-4 w-4" />
Teacher
{t("classDetail.teacher")}
</CardTitle>
</CardHeader>
<CardContent className="space-y-3 text-sm">
@@ -117,7 +120,7 @@ export default async function StudentClassDetailPage({
<span className="font-medium">{classInfo.teacherName}</span>
</div>
) : (
<p className="text-muted-foreground">No teacher assigned.</p>
<p className="text-muted-foreground">{t("classDetail.noTeacher")}</p>
)}
{classInfo.teacherEmail && (
<div className="flex items-center gap-2">
@@ -138,7 +141,7 @@ export default async function StudentClassDetailPage({
<CardHeader className="pb-3">
<CardTitle className="flex items-center gap-2 text-sm font-medium">
<School className="h-4 w-4" />
School
{t("classDetail.school")}
</CardTitle>
</CardHeader>
<CardContent className="space-y-3 text-sm">
@@ -148,12 +151,12 @@ export default async function StudentClassDetailPage({
<span className="font-medium">{classInfo.schoolName}</span>
</div>
) : (
<p className="text-muted-foreground">School info not available.</p>
<p className="text-muted-foreground">{t("classDetail.schoolNotAvailable")}</p>
)}
{classInfo.grade && (
<div className="flex items-center gap-2">
<BookOpen className="h-4 w-4 text-muted-foreground" />
<span>Grade {classInfo.grade}</span>
<span>{t("classDetail.grade", { grade: classInfo.grade })}</span>
</div>
)}
</CardContent>
@@ -164,22 +167,22 @@ export default async function StudentClassDetailPage({
<CardHeader className="pb-3">
<CardTitle className="flex items-center gap-2 text-sm font-medium">
<Building2 className="h-4 w-4" />
Classroom
{t("classDetail.classroom")}
</CardTitle>
</CardHeader>
<CardContent className="space-y-3 text-sm">
{classInfo.room ? (
<div className="flex items-center gap-2">
<Building2 className="h-4 w-4 text-muted-foreground" />
<span className="font-medium">Room {classInfo.room}</span>
<span className="font-medium">{t("classDetail.room", { room: classInfo.room })}</span>
</div>
) : (
<p className="text-muted-foreground">Room not assigned.</p>
<p className="text-muted-foreground">{t("classDetail.roomNotAssigned")}</p>
)}
{classInfo.homeroom && (
<div className="flex items-center gap-2">
<User className="h-4 w-4 text-muted-foreground" />
<span>Homeroom: {classInfo.homeroom}</span>
<span>{t("classDetail.homeroom", { homeroom: classInfo.homeroom })}</span>
</div>
)}
</CardContent>
@@ -191,15 +194,15 @@ export default async function StudentClassDetailPage({
<CardHeader>
<CardTitle className="flex items-center gap-2">
<CalendarDays className="h-5 w-5" />
Class Schedule
{t("classDetail.classSchedule")}
</CardTitle>
</CardHeader>
<CardContent>
{classSchedule.length === 0 ? (
<EmptyState
icon={CalendarDays}
title="No schedule"
description="No timetable entries found for this class."
title={t("classDetail.noSchedule")}
description={t("classDetail.noScheduleDesc")}
className="border-none shadow-none"
/>
) : (
@@ -211,7 +214,7 @@ export default async function StudentClassDetailPage({
>
<div className="flex items-center gap-3">
<Badge variant="outline" className="w-12 justify-center">
{WEEKDAYS[s.weekday]}
{t(`weekdays.${WEEKDAY_KEYS[s.weekday]}`)}
</Badge>
<div>
<p className="font-medium">{s.course}</p>

View File

@@ -1,4 +1,5 @@
import { UserX } from "lucide-react"
import { getTranslations } from "next-intl/server"
import { getStudentClasses } from "@/modules/classes/data-access"
import { getCurrentStudentUser } from "@/modules/users/data-access"
@@ -14,17 +15,18 @@ export default async function StudentCoursesPage({
}: {
searchParams: Promise<SearchParams>
}) {
const t = await getTranslations("student")
const student = await getCurrentStudentUser()
if (!student) {
return (
<div className="space-y-8">
<div>
<h2 className="text-2xl font-bold tracking-tight">Courses</h2>
<p className="text-muted-foreground">Your enrolled classes.</p>
<h2 className="text-2xl font-bold tracking-tight">{t("courses.title")}</h2>
<p className="text-muted-foreground">{t("courses.description")}</p>
</div>
<EmptyState
title="No user found"
description="Create a student user to see courses."
title={t("courses.noUser")}
description={t("courses.noUserDesc")}
icon={UserX}
/>
</div>
@@ -51,8 +53,8 @@ export default async function StudentCoursesPage({
return (
<div className="space-y-8">
<div>
<h2 className="text-2xl font-bold tracking-tight">Courses</h2>
<p className="text-muted-foreground">Your enrolled classes.</p>
<h2 className="text-2xl font-bold tracking-tight">{t("courses.title")}</h2>
<p className="text-muted-foreground">{t("courses.description")}</p>
</div>
{classes.length > 0 && <CourseFilters />}
<StudentCoursesView classes={filteredClasses} />

View File

@@ -1,5 +1,6 @@
import Link from "next/link"
import { BookOpen, PenTool, Library, ArrowRight } from "lucide-react"
import { BookOpen, PenTool, Library, ArrowRight, UserX } from "lucide-react"
import { getTranslations } from "next-intl/server"
import { getStudentClasses } from "@/modules/classes/data-access"
import { getStudentHomeworkAssignments } from "@/modules/homework/data-access"
@@ -7,16 +8,16 @@ 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 t = await getTranslations("student")
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} />
<EmptyState title={t("learning.noUser")} description={t("learning.noUserDesc")} icon={UserX} />
</div>
)
}
@@ -40,33 +41,33 @@ export default async function StudentLearningPage() {
const cards = [
{
title: "Courses",
description: "Your enrolled classes.",
title: t("learning.courses"),
description: t("learning.coursesDesc"),
icon: BookOpen,
href: "/student/learning/courses",
stat: `${classes.length} enrolled`,
stat: t("learning.enrolled", { count: classes.length }),
},
{
title: "Assignments",
description: "Homework and practice.",
title: t("learning.assignments"),
description: t("learning.assignmentsDesc"),
icon: PenTool,
href: "/student/learning/assignments",
stat: `${pendingCount} pending${dueSoonCount > 0 ? ` · ${dueSoonCount} due soon` : ""}`,
stat: t("learning.pending", { count: pendingCount }) + (dueSoonCount > 0 ? t("learning.dueSoon", { count: dueSoonCount }) : ""),
},
{
title: "Textbooks",
description: "Browse course materials.",
title: t("learning.textbooks"),
description: t("learning.textbooksDesc"),
icon: Library,
href: "/student/learning/textbooks",
stat: `${textbooks.length} available`,
stat: t("learning.available", { count: textbooks.length }),
},
]
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>
<h2 className="text-2xl font-bold tracking-tight">{t("learning.title")}</h2>
<p className="text-muted-foreground">{t("learning.description")}</p>
</div>
<div className="grid gap-6 md:grid-cols-2 lg:grid-cols-3">

View 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 StudentLessonPlanViewError() {
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>
)
}

View File

@@ -0,0 +1,11 @@
import { Skeleton } from "@/shared/components/ui/skeleton"
export default function StudentLessonPlanViewLoading() {
return (
<div className="h-[calc(100vh-4rem)]">
<div className="flex h-full items-center justify-center">
<Skeleton className="h-[80%] w-[80%]" />
</div>
</div>
)
}

View File

@@ -0,0 +1,83 @@
import type { JSX } from "react"
import { Suspense } from "react"
import { getTranslations } from "next-intl/server"
import { getAuthContext } from "@/shared/lib/auth-guard"
import { getLessonPlanById } from "@/modules/lesson-preparation/data-access"
import { getTextbookById, getChaptersByTextbookId } from "@/modules/textbooks/data-access"
import { LessonPlanReadonlyView } from "@/modules/lesson-preparation/components/lesson-plan-readonly-view"
import { Skeleton } from "@/shared/components/ui/skeleton"
export const dynamic = "force-dynamic"
export default async function StudentLessonPlanViewPage({
params,
}: {
params: Promise<{ planId: string }>
}): Promise<JSX.Element> {
const { planId } = await params
const t = await getTranslations("lessonPreparation")
const ctx = await getAuthContext()
const plan = await getLessonPlanById(planId, ctx.userId)
if (!plan) {
return (
<div className="p-6">
<div className="rounded-md border border-outline-variant bg-surface-container-low p-4 text-on-surface-variant">
{t("readonly.notFound")}
</div>
</div>
)
}
// 学生只能查看已发布的课案
if (plan.status !== "published") {
return (
<div className="p-6">
<div className="rounded-md border border-outline-variant bg-surface-container-low p-4 text-on-surface-variant">
{t("readonly.notPublished")}
</div>
</div>
)
}
// 拉取教材/章节标题
let textbookTitle: string | undefined
let chapterTitle: string | undefined
if (plan.textbookId) {
const textbook = await getTextbookById(plan.textbookId)
textbookTitle = textbook?.title
if (plan.chapterId) {
const chapters = await getChaptersByTextbookId(plan.textbookId)
const findChapter = (list: typeof chapters): typeof chapters[number] | undefined => {
for (const ch of list) {
if (ch.id === plan.chapterId) return ch
if (ch.children && ch.children.length > 0) {
const found = findChapter(ch.children as typeof chapters)
if (found) return found
}
}
return undefined
}
const chapter = findChapter(chapters)
chapterTitle = chapter?.title
}
}
return (
<div className="h-[calc(100vh-4rem)]">
<Suspense
fallback={
<div className="flex h-full items-center justify-center">
<Skeleton className="h-[80%] w-[80%]" />
</div>
}
>
<LessonPlanReadonlyView
doc={plan.content}
textbookTitle={textbookTitle}
chapterTitle={chapterTitle}
/>
</Suspense>
</div>
)
}

View 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 StudentLessonPlansError() {
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>
)
}

View File

@@ -0,0 +1,17 @@
import { Skeleton } from "@/shared/components/ui/skeleton"
export default function StudentLessonPlansLoading() {
return (
<div className="p-6 space-y-4">
<div className="space-y-2">
<Skeleton className="h-8 w-[180px]" />
<Skeleton className="h-4 w-[300px]" />
</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>
)
}

View File

@@ -0,0 +1,44 @@
import type { JSX } from "react"
import { Suspense } from "react"
import { getTranslations } from "next-intl/server"
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 { Skeleton } from "@/shared/components/ui/skeleton"
export const dynamic = "force-dynamic"
export default async function StudentLessonPlansPage(): Promise<JSX.Element> {
const t = await getTranslations("lessonPreparation")
const ctx = await getAuthContext()
const [items, subjects] = await Promise.all([
getLessonPlans({ status: "published" }, ctx.dataScope, ctx.userId),
getSubjectOptions(),
])
return (
<div className="p-6 space-y-4">
<div>
<h1 className="text-2xl font-bold tracking-tight">{t("student.title")}</h1>
<p className="text-muted-foreground">{t("student.description")}</p>
</div>
<Suspense
fallback={
<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>
}
>
<LessonPlanList
initialItems={items}
subjects={subjects}
viewMode="student"
/>
</Suspense>
</div>
)
}

View File

@@ -0,0 +1,32 @@
"use client"
import { useEffect } from "react"
import Link from "next/link"
import { useTranslations } from "next-intl"
import { Button } from "@/shared/components/ui/button"
export default function PracticeSessionError({
error,
reset,
}: {
error: Error & { digest?: string }
reset: () => void
}): React.ReactNode {
const t = useTranslations("student")
useEffect(() => {
console.error("Practice session error:", error)
}, [error])
return (
<div className="flex h-full flex-col items-center justify-center space-y-4 p-8">
<h2 className="text-xl font-semibold">{t("error.title")}</h2>
<p className="text-sm text-muted-foreground">{error.message}</p>
<div className="flex gap-2">
<Button onClick={reset}>{t("error.retry")}</Button>
<Button variant="outline" asChild>
<Link href="/student/practice">{t("classDetail.backToCourses")}</Link>
</Button>
</div>
</div>
)
}

View File

@@ -0,0 +1,14 @@
import { Skeleton } from "@/shared/components/ui/skeleton"
export default function PracticeSessionLoading(): React.ReactNode {
return (
<div className="flex h-full flex-col space-y-6 p-8">
<Skeleton className="h-20 w-full rounded-md" />
<Skeleton className="h-96 w-full rounded-md" />
<div className="flex justify-between">
<Skeleton className="h-10 w-24 rounded-md" />
<Skeleton className="h-10 w-24 rounded-md" />
</div>
</div>
)
}

View File

@@ -0,0 +1,31 @@
import type { JSX } from "react"
import { notFound } from "next/navigation"
import { requirePermission } from "@/shared/lib/auth-guard"
import { Permissions } from "@/shared/types/permissions"
import { getPracticeSessionById } from "@/modules/adaptive-practice/data-access"
import { PracticeSessionView } from "@/modules/adaptive-practice/components/practice-session-view"
export const dynamic = "force-dynamic"
export default async function PracticeSessionPage({
params,
}: {
params: Promise<{ sessionId: string }>
}): Promise<JSX.Element> {
const ctx = await requirePermission(Permissions.ADAPTIVE_PRACTICE_READ)
const { sessionId } = await params
const session = await getPracticeSessionById(sessionId, ctx.userId)
if (!session) {
notFound()
}
return (
<div className="flex h-full flex-col space-y-6 p-8">
<PracticeSessionView session={session} />
</div>
)
}

View File

@@ -0,0 +1,26 @@
"use client"
import { useEffect } from "react"
import { useTranslations } from "next-intl"
import { Button } from "@/shared/components/ui/button"
export default function PracticeError({
error,
reset,
}: {
error: Error & { digest?: string }
reset: () => void
}): React.ReactNode {
const t = useTranslations("student")
useEffect(() => {
console.error("Practice page error:", error)
}, [error])
return (
<div className="flex h-full flex-col items-center justify-center space-y-4 p-8">
<h2 className="text-xl font-semibold">{t("error.title")}</h2>
<p className="text-sm text-muted-foreground">{error.message}</p>
<Button onClick={reset}>{t("error.retry")}</Button>
</div>
)
}

View File

@@ -0,0 +1,25 @@
import { Skeleton } from "@/shared/components/ui/skeleton"
export default function PracticeLoading(): React.ReactNode {
return (
<div className="flex h-full flex-col space-y-8 p-8">
<div className="space-y-2">
<Skeleton className="h-8 w-48" />
<Skeleton className="h-4 w-72" />
</div>
<div className="grid gap-4 md:grid-cols-4">
{Array.from({ length: 4 }).map((_, i) => (
<Skeleton key={i} className="h-24 w-full rounded-md" />
))}
</div>
<div className="grid gap-6 lg:grid-cols-3">
<Skeleton className="h-96 w-full rounded-md" />
<div className="space-y-3 lg:col-span-2">
{Array.from({ length: 5 }).map((_, i) => (
<Skeleton key={i} className="h-20 w-full rounded-md" />
))}
</div>
</div>
</div>
)
}

View File

@@ -0,0 +1,45 @@
import type { JSX } from "react"
import { getTranslations } from "next-intl/server"
import { requirePermission } from "@/shared/lib/auth-guard"
import { Permissions } from "@/shared/types/permissions"
import { getPracticeSessions, getPracticeStats } from "@/modules/adaptive-practice/data-access"
import { PracticeStarter } from "@/modules/adaptive-practice/components/practice-starter"
import { PracticeHistory } from "@/modules/adaptive-practice/components/practice-history"
import { PracticeStatsCards } from "@/modules/adaptive-practice/components/practice-stats-cards"
import { getKnowledgePointOptions } from "@/modules/questions/data-access"
export const dynamic = "force-dynamic"
export default async function StudentPracticePage(): Promise<JSX.Element> {
const ctx = await requirePermission(Permissions.ADAPTIVE_PRACTICE_READ)
const t = await getTranslations("practice")
const [stats, sessionsResult, knowledgePoints] = await Promise.all([
getPracticeStats(ctx.userId),
getPracticeSessions(ctx.userId, { pageSize: 20 }),
getKnowledgePointOptions(),
])
return (
<div className="flex h-full flex-col space-y-8 p-8">
<div>
<h1 className="text-2xl font-bold tracking-tight">{t("page.title")}</h1>
<p className="text-muted-foreground">{t("page.description")}</p>
</div>
<PracticeStatsCards stats={stats} />
<div className="grid gap-6 lg:grid-cols-3">
<div className="lg:col-span-1">
<PracticeStarter knowledgePoints={knowledgePoints} />
</div>
<div className="lg:col-span-2 space-y-4">
<h2 className="text-lg font-semibold">{t("history.title")}</h2>
<PracticeHistory sessions={sessionsResult.data} />
</div>
</div>
</div>
)
}

View File

@@ -1,4 +1,5 @@
import { UserX } from "lucide-react"
import { getTranslations } from "next-intl/server"
import { getStudentClasses, getStudentSchedule } from "@/modules/classes/data-access"
import { getCurrentStudentUser } from "@/modules/users/data-access"
@@ -14,15 +15,20 @@ export default async function StudentSchedulePage({
}: {
searchParams: Promise<SearchParams>
}) {
const t = await getTranslations("student")
const student = await getCurrentStudentUser()
if (!student) {
return (
<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>
<h2 className="text-2xl font-bold tracking-tight">{t("schedule.title")}</h2>
<p className="text-muted-foreground">{t("schedule.description")}</p>
</div>
<EmptyState title="No user found" description="Create a student user to see schedule." icon={UserX} />
<EmptyState
title={t("schedule.noUser")}
description={t("schedule.noUserDesc")}
icon={UserX}
/>
</div>
)
}
@@ -41,8 +47,8 @@ export default async function StudentSchedulePage({
<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>
<p className="text-muted-foreground">Your weekly timetable.</p>
<h2 className="text-2xl font-bold tracking-tight">{t("schedule.title")}</h2>
<p className="text-muted-foreground">{t("schedule.description")}</p>
</div>
<StudentScheduleFilters classes={classes} />
</div>

View File

@@ -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>
)
}

View File

@@ -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>
)
}

View 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 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>
)
}

View File

@@ -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>
)
}

View File

@@ -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>
)
}

View 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>
)
}

View 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>
)
}

View 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>
)
}

View 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>
)
}

View File

@@ -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>
)
}

View File

@@ -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>
)
}

View 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>
)
}

View 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>
)
}

View 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>
)
}

View File

@@ -149,6 +149,21 @@
--color-sidebar-border: hsl(var(--sidebar-border));
--color-sidebar-ring: hsl(var(--sidebar-ring));
/* Material Design 3 Surface 令牌映射(备课模块使用)*/
--color-surface: hsl(var(--card));
--color-on-surface: hsl(var(--foreground));
--color-on-surface-variant: hsl(var(--muted-foreground));
--color-surface-container-lowest: hsl(var(--background));
--color-surface-container-low: hsl(var(--muted));
--color-surface-container: hsl(var(--secondary));
--color-surface-container-high: hsl(var(--accent));
--color-surface-container-highest: hsl(var(--muted-foreground));
--color-outline-variant: hsl(var(--border));
--color-outline: hsl(var(--border));
--color-error: hsl(var(--destructive));
--color-tertiary: hsl(var(--chart-3));
--color-tertiary-container: hsl(var(--chart-3));
--radius-lg: var(--radius);
--radius-md: calc(var(--radius) - 2px);
--radius-sm: calc(var(--radius) - 4px);
@@ -241,3 +256,9 @@
.anchor-edge.active {
opacity: 1;
}
/* 正文节点光标指示器闪烁 */
@keyframes cursor-blink {
0%, 50% { opacity: 1; }
51%, 100% { opacity: 0; }
}