P0-1: 10 个页面补充 requirePermission 权限校验 P0-2: diagnostic/data-access-reports.ts 移除直查 users 表,改用 getUserNamesByIds P0-3: 新增 grade/grades/diagnostic 三组 i18n 翻译文件(zh-CN/en) P0-4: 新增 /management/grade 重定向页面 P1-2: 抽取 toNumber/normalize/buildScopeClassFilter 到 lib/grade-utils.ts P1-3: 为 12 个 Action 新增 Zod safeParse 校验(schema.ts +12 查询 schema) P1-4: 修复 as 断言违规,改用类型守卫函数 P2-2: 移除 diagnostic 组件中 Tailwind 任意值 同步更新架构图文档 004 和 005
65 lines
2.1 KiB
TypeScript
65 lines
2.1 KiB
TypeScript
import type { JSX } from "react"
|
|
import { requirePermission } from "@/shared/lib/auth-guard"
|
|
import { Permissions } from "@/shared/types/permissions"
|
|
import { getParam, type SearchParams } from "@/shared/lib/search-params"
|
|
import { getDiagnosticReports } from "@/modules/diagnostic/data-access-reports"
|
|
import { ReportList } from "@/modules/diagnostic/components/report-list"
|
|
import type { DiagnosticReportType, DiagnosticReportStatus } from "@/modules/diagnostic/types"
|
|
|
|
export const dynamic = "force-dynamic"
|
|
|
|
const VALID_REPORT_TYPES: ReadonlySet<string> = new Set([
|
|
"individual",
|
|
"class",
|
|
"grade",
|
|
])
|
|
|
|
const VALID_REPORT_STATUSES: ReadonlySet<string> = new Set([
|
|
"draft",
|
|
"published",
|
|
"archived",
|
|
])
|
|
|
|
function parseReportType(v?: string): DiagnosticReportType | undefined {
|
|
return v && VALID_REPORT_TYPES.has(v) ? (v as DiagnosticReportType) : undefined
|
|
}
|
|
|
|
function parseReportStatus(v?: string): DiagnosticReportStatus | undefined {
|
|
return v && VALID_REPORT_STATUSES.has(v) ? (v as DiagnosticReportStatus) : undefined
|
|
}
|
|
|
|
export default async function TeacherDiagnosticPage({
|
|
searchParams,
|
|
}: {
|
|
searchParams: Promise<SearchParams>
|
|
}): Promise<JSX.Element> {
|
|
const sp = await searchParams
|
|
const ctx = await requirePermission(Permissions.DIAGNOSTIC_READ)
|
|
|
|
const reportType = getParam(sp, "reportType")
|
|
const status = getParam(sp, "status")
|
|
|
|
const reports = await getDiagnosticReports({
|
|
reportType: reportType && reportType !== "all" ? parseReportType(reportType) : undefined,
|
|
status: status && status !== "all" ? parseReportStatus(status) : undefined,
|
|
})
|
|
|
|
// 学生角色仅查看自己的报告;其他角色查看全部
|
|
const visibleReports =
|
|
ctx.dataScope.type === "class_members"
|
|
? reports.filter((r) => r.studentId === ctx.userId)
|
|
: reports
|
|
|
|
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">Learning Diagnostic</h1>
|
|
<p className="text-muted-foreground">
|
|
View and manage diagnostic reports based on knowledge point mastery.
|
|
</p>
|
|
</div>
|
|
<ReportList reports={visibleReports} />
|
|
</div>
|
|
)
|
|
}
|