演示

NotificationService

向用户或角色发送应用内与推送通知。/app/ 页面已接入实时送达。

注入

TSXinject
1import { 2 ContainerRegistryManager, 3 NotificationService, 4 Inject, 5 Service, 6} from "@quan-erp/shared-backend-core"; 7 8@Service() 9export class MyPluginService { 10 @Inject(NotificationService, ContainerRegistryManager.BUILTIN_PLUGIN) 11 private notificationService: NotificationService; 12}

send(props: CreateNotificationDto)

写入通知并触发推送。userIds → 指定用户;roleIds → 指定角色;两者都省略 → 全体。

  • title / subtitle / body — 必填
  • pluginName — 通常为 metadata.name
  • topic — 事件键
  • userIds? / roleIds? — 目标
  • url? / data? — 深链与额外载荷
TSXsend
1import { 2 ContainerRegistryManager, 3 Inject, 4 NotificationService, 5 Service, 6} from "@quan-erp/shared-backend-core"; 7import metadata from "../../module.metadata.json" with { type: "json" }; 8 9@Service() 10export class ProjectNotifyService { 11 @Inject(NotificationService, ContainerRegistryManager.BUILTIN_PLUGIN) 12 private notificationService: NotificationService; 13 14 async notifyUpdate() { 15 await this.notificationService.send({ 16 userIds: [1, 2], 17 // roleIds: [1], 18 title: "Project Updated", 19 subtitle: "Status change", 20 body: "Status changed to Completed.", 21 pluginName: metadata.name, 22 topic: "project-update", 23 url: "/app/projects/12", 24 data: { projectId: 12 }, 25 }); 26 } 27}

收件箱方法

  • get({ userId, roleId, skip, limit }) — 用户可见通知列表
  • getUnreadNotiCount({ userId, roleId }) — 未读数
  • markRead({ id, userId }) — 标为已读
TSXinbox
1import { 2 ContainerRegistryManager, 3 Inject, 4 NotificationService, 5 Service, 6} from "@quan-erp/shared-backend-core"; 7 8@Service() 9export class InboxService { 10 @Inject(NotificationService, ContainerRegistryManager.BUILTIN_PLUGIN) 11 private notificationService: NotificationService; 12 13 async list(userId: number, roleId: number) { 14 const unread = await this.notificationService.getUnreadNotiCount({ 15 userId, 16 roleId, 17 }); 18 const items = await this.notificationService.get({ 19 userId, 20 roleId, 21 skip: 0, 22 limit: 20, 23 }); 24 return { unread, items }; 25 } 26 27 async read(id: number, userId: number) { 28 await this.notificationService.markRead({ id, userId }); 29 } 30}