feat(app): add error/loading boundaries across all dashboard routes and new routes
- Add error.tsx and loading.tsx boundaries for admin, parent, student, teacher routes - Add admin announcements edit, audit-logs overview, curriculum-map, invitation-codes, permissions, questions, roles routes - Add admin elective detail and components, files, course-plans, users, scheduling boundaries - Add messages group-compose route - Add parent course-plans, elective, grades report-card, practice routes - Add student course-plans, elective detail, error-book dialogs, grades report-card, learning study-path, leave, schedule boundaries - Add teacher attendance report, classes boundaries, course-plans boundaries, elective, exams analytics/edit-rich/all/create/new, grades report-card, homework boundaries, leave, lesson-plans calendar - Add auth loading, onboarding loading, api cron
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
"use client";
|
||||
|
||||
import { AiLessonContentGenerator } from "@/modules/ai/components/ai-lesson-content-generator";
|
||||
import { useAiClientOptional } from "@/modules/ai/context/ai-client-provider";
|
||||
import type { AiContentGeneratorSlotProps } from "@/modules/lesson-preparation/components/node-edit-panel";
|
||||
|
||||
/**
|
||||
* P0-11 修复:AI 内容生成器 slot 实现。
|
||||
* 此组件在 app 层组合 @/modules/ai 的具体实现,
|
||||
* 通过 props 注入到 lesson-preparation 模块的 NodeEditPanel,
|
||||
* 避免备课模块直接依赖 @/modules/ai。
|
||||
*/
|
||||
export function AiContentGeneratorSlot({
|
||||
topic,
|
||||
textbookId,
|
||||
chapterId,
|
||||
}: AiContentGeneratorSlotProps) {
|
||||
const aiClient = useAiClientOptional();
|
||||
if (!aiClient) return null;
|
||||
return (
|
||||
<AiLessonContentGenerator
|
||||
topic={topic}
|
||||
textbookId={textbookId}
|
||||
chapterId={chapterId}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -5,48 +5,25 @@ 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"
|
||||
import { getTextbookById, getChaptersByTextbookId, findChapterById } from "@/modules/textbooks/data-access"
|
||||
import { requirePermission } from "@/shared/lib/auth-guard"
|
||||
import { Permissions } from "@/shared/types/permissions"
|
||||
import { Skeleton } from "@/shared/components/ui/skeleton"
|
||||
import {
|
||||
AiClientProvider,
|
||||
type AiClientService,
|
||||
} from "@/modules/ai/context/ai-client-provider"
|
||||
import {
|
||||
aiChatAction,
|
||||
suggestSimilarQuestionsAction,
|
||||
suggestGradingAction,
|
||||
generateLessonContentAction,
|
||||
generateQuestionVariantAction,
|
||||
analyzeWeaknessAction,
|
||||
} from "@/modules/ai/actions"
|
||||
import { AiClientProvider } from "@/modules/ai/context/ai-client-provider"
|
||||
import { createCoreAiClientService } from "@/modules/ai/context/create-ai-client-service"
|
||||
// P0-11 修复:通过 slot 组件注入 AI 功能,避免备课模块直接 import @/modules/ai
|
||||
import { AiContentGeneratorSlot } from "./ai-content-generator-slot"
|
||||
|
||||
export const dynamic = "force-dynamic"
|
||||
|
||||
/**
|
||||
* 构建 AI 客户端服务(Server Action 引用集合)
|
||||
*
|
||||
* 通过 React Context 注入,客户端组件不直接 import actions,
|
||||
* 遵循依赖注入模式,便于测试时替换为 mock。
|
||||
*/
|
||||
function createAiClientService(): AiClientService {
|
||||
return {
|
||||
chat: aiChatAction,
|
||||
suggestSimilarQuestions: suggestSimilarQuestionsAction,
|
||||
suggestGrading: suggestGradingAction,
|
||||
generateLessonContent: generateLessonContentAction,
|
||||
generateQuestionVariant: generateQuestionVariantAction,
|
||||
analyzeWeakness: analyzeWeaknessAction,
|
||||
}
|
||||
}
|
||||
|
||||
export default async function EditLessonPlanPage({
|
||||
params,
|
||||
}: {
|
||||
params: Promise<{ planId: string }>
|
||||
}): Promise<JSX.Element> {
|
||||
const { planId } = await params
|
||||
const ctx = await getAuthContext()
|
||||
// V4 P0-2 修复:页面层补齐 requirePermission 权限校验
|
||||
const ctx = await requirePermission(Permissions.LESSON_PLAN_READ)
|
||||
|
||||
const [plan, teacherClasses] = await Promise.all([
|
||||
getLessonPlanById(planId, ctx.userId),
|
||||
@@ -64,22 +41,13 @@ export default async function EditLessonPlanPage({
|
||||
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)
|
||||
// P1-6 修复:使用共享工具 findChapterById 替代页面内重复的递归函数
|
||||
const chapter = findChapterById(chapters, plan.chapterId)
|
||||
chapterTitle = chapter?.title
|
||||
}
|
||||
}
|
||||
|
||||
const aiClientService = createAiClientService()
|
||||
const aiClientService = createCoreAiClientService()
|
||||
|
||||
return (
|
||||
<AiClientProvider service={aiClientService}>
|
||||
@@ -102,6 +70,7 @@ export default async function EditLessonPlanPage({
|
||||
textbookTitle={textbookTitle}
|
||||
chapterTitle={chapterTitle}
|
||||
classes={classes}
|
||||
aiContentGenerator={AiContentGeneratorSlot}
|
||||
/>
|
||||
</Suspense>
|
||||
</div>
|
||||
|
||||
20
src/app/(dashboard)/teacher/lesson-plans/calendar/error.tsx
Normal file
20
src/app/(dashboard)/teacher/lesson-plans/calendar/error.tsx
Normal file
@@ -0,0 +1,20 @@
|
||||
"use client";
|
||||
|
||||
import { useTranslations } from "next-intl";
|
||||
import { Calendar } from "lucide-react";
|
||||
import { EmptyState } from "@/shared/components/ui/empty-state";
|
||||
|
||||
export default function CalendarError() {
|
||||
const t = useTranslations("lessonPreparation");
|
||||
return (
|
||||
<div className="p-8">
|
||||
<EmptyState
|
||||
icon={Calendar}
|
||||
title={t("calendar.loadFailed")}
|
||||
description={t("error.loadFailedDesc")}
|
||||
action={{ label: t("error.retry"), onClick: () => window.location.reload() }}
|
||||
className="border-none shadow-none"
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
import { Skeleton } from "@/shared/components/ui/skeleton";
|
||||
|
||||
export default function CalendarLoading() {
|
||||
return (
|
||||
<div className="p-6 space-y-4">
|
||||
<div className="flex items-center justify-between">
|
||||
<div className="space-y-2">
|
||||
<Skeleton className="h-8 w-[180px]" />
|
||||
<Skeleton className="h-4 w-[260px]" />
|
||||
</div>
|
||||
<Skeleton className="h-9 w-[120px]" />
|
||||
</div>
|
||||
<div className="flex items-center justify-between">
|
||||
<div className="flex items-center gap-2">
|
||||
<Skeleton className="h-9 w-9" />
|
||||
<Skeleton className="h-9 w-9" />
|
||||
<Skeleton className="h-9 w-[80px]" />
|
||||
<Skeleton className="h-4 w-[200px] ml-2" />
|
||||
</div>
|
||||
<Skeleton className="h-9 w-[160px]" />
|
||||
</div>
|
||||
<div className="grid grid-cols-7 gap-2">
|
||||
{Array.from({ length: 7 }).map((_, i) => (
|
||||
<div key={i} className="flex flex-col">
|
||||
<Skeleton className="h-6 w-full" />
|
||||
<div className="flex-1 min-h-[200px] space-y-1 pt-1">
|
||||
<Skeleton className="h-8 w-full" />
|
||||
<Skeleton className="h-8 w-full" />
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
34
src/app/(dashboard)/teacher/lesson-plans/calendar/page.tsx
Normal file
34
src/app/(dashboard)/teacher/lesson-plans/calendar/page.tsx
Normal file
@@ -0,0 +1,34 @@
|
||||
import type { JSX } from "react";
|
||||
import Link from "next/link";
|
||||
import { ArrowLeft } from "lucide-react";
|
||||
import { getTranslations } from "next-intl/server";
|
||||
import { requirePermission } from "@/shared/lib/auth-guard";
|
||||
import { Permissions } from "@/shared/types/permissions";
|
||||
import { Button } from "@/shared/components/ui/button";
|
||||
import { CalendarView } from "@/modules/lesson-preparation/components/calendar-view";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
export default async function CalendarPage(): Promise<JSX.Element> {
|
||||
const t = await getTranslations("lessonPreparation");
|
||||
// V4 P0-2 修复:页面层补齐 requirePermission 权限校验
|
||||
const ctx = await requirePermission(Permissions.LESSON_PLAN_READ);
|
||||
|
||||
return (
|
||||
<div className="p-6 space-y-4">
|
||||
<div className="flex items-center justify-between">
|
||||
<div>
|
||||
<h1 className="text-2xl font-bold tracking-tight">{t("calendar.title")}</h1>
|
||||
<p className="text-muted-foreground">{t("calendar.description")}</p>
|
||||
</div>
|
||||
<Button asChild variant="outline" size="sm">
|
||||
<Link href="/teacher/lesson-plans">
|
||||
<ArrowLeft className="h-4 w-4 mr-2" aria-hidden="true" />
|
||||
{t("action.back")}
|
||||
</Link>
|
||||
</Button>
|
||||
</div>
|
||||
<CalendarView initialTeacherId={ctx.userId} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -5,6 +5,8 @@ import { ArrowLeft } from "lucide-react"
|
||||
import { getTranslations } from "next-intl/server"
|
||||
import { Button } from "@/shared/components/ui/button"
|
||||
import { Skeleton } from "@/shared/components/ui/skeleton"
|
||||
import { requirePermission } from "@/shared/lib/auth-guard"
|
||||
import { Permissions } from "@/shared/types/permissions"
|
||||
import { TemplatePicker } from "@/modules/lesson-preparation/components/template-picker"
|
||||
import { LessonPlanProviderSetup } from "@/modules/lesson-preparation/providers/lesson-plan-provider-setup"
|
||||
|
||||
@@ -12,6 +14,8 @@ export const dynamic = "force-dynamic"
|
||||
|
||||
export default async function NewLessonPlanPage(): Promise<JSX.Element> {
|
||||
const t = await getTranslations("lessonPreparation")
|
||||
// V4 P0-2 修复:页面层补齐 requirePermission 权限校验
|
||||
await requirePermission(Permissions.LESSON_PLAN_READ)
|
||||
return (
|
||||
<div className="p-6">
|
||||
<div className="mb-6 flex items-center gap-4">
|
||||
|
||||
@@ -5,7 +5,8 @@ import { Plus } from "lucide-react"
|
||||
import { getTranslations } from "next-intl/server"
|
||||
import { Button } from "@/shared/components/ui/button"
|
||||
import { Skeleton } from "@/shared/components/ui/skeleton"
|
||||
import { getAuthContext } from "@/shared/lib/auth-guard"
|
||||
import { requirePermission } from "@/shared/lib/auth-guard"
|
||||
import { Permissions } from "@/shared/types/permissions"
|
||||
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"
|
||||
@@ -15,7 +16,8 @@ export const dynamic = "force-dynamic"
|
||||
|
||||
export default async function LessonPlansPage(): Promise<JSX.Element> {
|
||||
const t = await getTranslations("lessonPreparation")
|
||||
const ctx = await getAuthContext()
|
||||
// V4 P0-2 修复:页面层补齐 requirePermission 权限校验
|
||||
const ctx = await requirePermission(Permissions.LESSON_PLAN_READ)
|
||||
|
||||
const [items, subjects] = await Promise.all([
|
||||
getLessonPlans({}, ctx.dataScope, ctx.userId),
|
||||
|
||||
Reference in New Issue
Block a user