feat: 完成 P1 全部功能 + 修复 proxy 导出 + 切换 MySQL 端口至 14013

## P1 功能(20 项)
- 站内消息系统、家长仪表盘、学生考勤管理
- Excel 导入导出、用户批量导入、成绩导出
- 排课规则+自动排课+课表调整
- 成绩趋势+对比分析、密码安全策略、速率限制
- 数据变更日志、文件预览+存储策略、全文检索
- 依赖审计集成 CI、数据库定时备份、E2E 测试完善
- 通知偏好管理

## 基础设施修复
- src/proxy.ts: 将 middleware 导出重命名为 proxy(Next.js 16 要求)
- .env: MySQL 端口从 13002 切换至 14013
- scripts/create-db.ts: 新增数据库初始化脚本

## 架构文档同步
- 004_architecture_impact_map.md 和 005_architecture_data.json
  完整记录所有新增表、模块、路由、权限、依赖关系
This commit is contained in:
SpecialX
2026-06-17 13:44:37 +08:00
parent 125f7ec54c
commit 3b6272c99d
195 changed files with 27274 additions and 416 deletions

View File

@@ -0,0 +1,141 @@
"use client"
import { useState } from "react"
import Link from "next/link"
import { useRouter } from "next/navigation"
import { toast } from "sonner"
import { Bell, CheckCheck, MessageSquare, Megaphone, PenTool, GraduationCap } from "lucide-react"
import { Badge } from "@/shared/components/ui/badge"
import { Button } from "@/shared/components/ui/button"
import { Card, CardContent } from "@/shared/components/ui/card"
import { EmptyState } from "@/shared/components/ui/empty-state"
import { formatDate } from "@/shared/lib/utils"
import { markAllNotificationsAsReadAction, markNotificationAsReadAction } from "../actions"
import type { Notification, NotificationType } from "../types"
const TYPE_ICON: Record<NotificationType, typeof Bell> = {
message: MessageSquare,
announcement: Megaphone,
homework: PenTool,
grade: GraduationCap,
}
const TYPE_LABEL: Record<NotificationType, string> = {
message: "Message",
announcement: "Announcement",
homework: "Homework",
grade: "Grade",
}
export function NotificationList({ notifications }: { notifications: Notification[] }) {
const router = useRouter()
const [isWorking, setIsWorking] = useState(false)
const hasUnread = notifications.some((n) => !n.isRead)
const handleMarkAllRead = async () => {
setIsWorking(true)
try {
const res = await markAllNotificationsAsReadAction()
if (res.success) {
toast.success(res.message)
router.refresh()
} else {
toast.error(res.message || "Failed to mark all as read")
}
} catch {
toast.error("Failed to mark all as read")
} finally {
setIsWorking(false)
}
}
const handleMarkRead = async (id: string) => {
try {
const res = await markNotificationAsReadAction(id)
if (res.success) {
router.refresh()
}
} catch {
toast.error("Failed to mark as read")
}
}
return (
<div className="space-y-6">
<div className="flex flex-wrap items-center justify-between gap-3">
<div>
<h2 className="text-2xl font-bold tracking-tight">Notifications</h2>
<p className="text-muted-foreground text-sm">Stay updated on your latest activities.</p>
</div>
{hasUnread ? (
<Button onClick={handleMarkAllRead} disabled={isWorking} variant="outline">
<CheckCheck className="mr-2 h-4 w-4" />
Mark all as read
</Button>
) : null}
</div>
{notifications.length === 0 ? (
<EmptyState
title="No notifications"
description="You have no notifications yet."
icon={Bell}
className="h-auto border-none shadow-none"
/>
) : (
<div className="space-y-3">
{notifications.map((n) => {
const Icon = TYPE_ICON[n.type] ?? Bell
return (
<Card
key={n.id}
className={`transition-colors ${!n.isRead ? "border-primary/40 bg-primary/5" : ""}`}
>
<CardContent className="flex items-start gap-3 py-4">
<div className="bg-muted flex size-9 shrink-0 items-center justify-center rounded-full">
<Icon className="h-4 w-4" />
</div>
<div className="min-w-0 flex-1 space-y-1">
<div className="flex items-center gap-2">
<span className={`text-sm ${!n.isRead ? "font-semibold" : "font-medium"}`}>
{n.title}
</span>
{!n.isRead ? <Badge variant="default" className="text-xs">New</Badge> : null}
</div>
{n.content ? (
<p className="text-muted-foreground line-clamp-2 text-sm whitespace-pre-wrap">
{n.content}
</p>
) : null}
<div className="flex items-center gap-2 text-xs text-muted-foreground">
<Badge variant="outline" className="text-xs">
{TYPE_LABEL[n.type]}
</Badge>
<span>{formatDate(n.createdAt)}</span>
{!n.isRead ? (
<button
type="button"
onClick={() => handleMarkRead(n.id)}
className="text-primary hover:underline"
>
Mark as read
</button>
) : null}
{n.link ? (
<Link href={n.link} className="ml-auto text-primary hover:underline">
View
</Link>
) : null}
</div>
</div>
</CardContent>
</Card>
)
})}
</div>
)}
</div>
)
}