Notification模块

Vue项目通知模块设计

#tech / dev / pm #type / howto #status / seed

[!info] related notes


Notification模块思路

Overview

  • 基础设施?
  • 一个独立的 提醒模块,用于弹窗、发出声音、发邮件等提醒功能。

服务

基础

  • 主要是和 schedule 模块联动,goal、task 等模块的提醒任务触发后弹窗提醒
  • desktop端使用系统级的弹窗,桌面右下角的弹窗

进阶

  • 实现自定义的前端弹窗套件:windows 系统弹窗容易被关闭,可以实现自定义的,功能更丰富

领域实体对象

聚合根 A:Notification (通知单体)

  • 职责:代表一条发送出去的消息。
  • 状态title, content, readStatus (UNREAD/READ), channel (EMAIL/APP).
  • 行为markAsRead(), archive().

聚合根 B:NotificationPreferences (用户配置)

  • 职责:管理用户设置(比如:晚上 10 点后不接收 Push,只接收 Email)。
  • 状态userId, doNotDisturbPeriod (VO), channelConfig.
  • 行为shouldSend(channel, time) (判断某条消息是否应该发送).

Prisma Model (Infrastructure):

代码段

model Notification {
  id        String   @id
  userId    String
  title     String
  isRead    Boolean  @default(false)
  sentAt    DateTime @default(now())
  // ...
}

总结建议

  1. 前端模型

    • 不要照搬后端聚合根。
    • 前端模型 = 后端 DTO 数据 + UI 状态 (Select/Expand/Loading) + UI 计算逻辑 (Color/Format)
  2. 基础设施模块

    • Schedule 模块的核心聚合根是 ScheduleJob。它负责管理“任务队列对象”的生命周期。
    • Notification 模块的核心聚合根是 Notification (消息本身) 和 UserPreference (配置)。
创建于 2025/1/1 更新于 2026/5/27