基于 dashboard-audit-report.md 审计结论,对仪表盘模块进行 P0/P1 级修复:
- 新增 4 个 dashboard 权限点(DASHBOARD_ADMIN/TEACHER/STUDENT/PARENT_READ),补充到 permissions.ts 和角色-权限映射
- 新建 actions.ts:4 个 Server Action 均调用 requirePermission() 校验权限,消除 admin 页面零鉴权、teacher/student/parent 仅 requireAuth 的安全隐患
- 根重定向页 /dashboard 改用 resolvePermissions() + 权限点判断,不再 role === xxx 硬编码
- 新建 lib/dashboard-utils.ts:抽取 toWeekday / countStudentAssignments / sortUpcomingAssignments / filterTodaySchedule / computeTeacherMetrics / getGreetingKey 纯函数,与 UI 分离,便于单测
- 新建 messages/{zh-CN,en}/dashboard.json 翻译文件,i18n request.ts 加载 dashboard 命名空间;所有视图组件接入 useTranslations / getTranslations,消除中英混杂硬编码
- 重构 4 个角色 page.tsx:通过 actions 获取数据,generateMetadata 使用 i18n
- 同步更新架构图 004 / 005 文档(dashboard exports / permissions / 文件清单)
44 lines
1.3 KiB
TypeScript
44 lines
1.3 KiB
TypeScript
import type { Metadata } from "next"
|
|
import type { JSX } from "react"
|
|
import { getTranslations } from "next-intl/server"
|
|
|
|
import { getParentDashboardAction } from "@/modules/dashboard/actions"
|
|
import { ParentDashboard } from "@/modules/parent/components/parent-dashboard"
|
|
import { ParentNoChildrenPage } from "@/modules/parent/components/parent-children-data-page"
|
|
import { Users } from "lucide-react"
|
|
|
|
export const dynamic = "force-dynamic"
|
|
|
|
export async function generateMetadata(): Promise<Metadata> {
|
|
const t = await getTranslations("dashboard")
|
|
return {
|
|
title: t("title.parent"),
|
|
description: t("description.parent"),
|
|
}
|
|
}
|
|
|
|
export default async function ParentDashboardPage(): Promise<JSX.Element> {
|
|
const t = await getTranslations("dashboard")
|
|
const { data, hasChildren } = await getParentDashboardAction()
|
|
|
|
if (!data || !hasChildren) {
|
|
return (
|
|
<div className="p-6 md:p-8">
|
|
<ParentNoChildrenPage
|
|
title={t("title.parent")}
|
|
description={t("description.parent")}
|
|
icon={Users}
|
|
emptyTitle={t("empty.noChildren")}
|
|
emptyDescription={t("empty.noChildrenDesc")}
|
|
/>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
return (
|
|
<div className="p-6 md:p-8">
|
|
<ParentDashboard data={data} />
|
|
</div>
|
|
)
|
|
}
|