diff --git a/apps/vue/src/api/messages/model/notificationsModel.ts b/apps/vue/src/api/messages/model/notificationsModel.ts index 14c76b9ea..07a243b29 100644 --- a/apps/vue/src/api/messages/model/notificationsModel.ts +++ b/apps/vue/src/api/messages/model/notificationsModel.ts @@ -7,6 +7,7 @@ export enum NotificationType { Application = 0, System = 10, User = 20, + ServiceCallback = 30, } export enum NotificationSeverity { diff --git a/apps/vue/src/enums/imEnum.ts b/apps/vue/src/enums/imEnum.ts index 52fe203ce..647be597a 100644 --- a/apps/vue/src/enums/imEnum.ts +++ b/apps/vue/src/enums/imEnum.ts @@ -26,4 +26,6 @@ export enum NotifyEventEnum { NOTIFICATIONS_RECEVIED = 'notifications:recevied', /** 通知已读 */ NOTIFICATIONS_READ = 'notifications:read', + /** 服务端回调 */ + NOTIFICATIONS_SERVICE_CALLBACK = 'notifications:service_callback', } diff --git a/apps/vue/src/layouts/default/header/components/notify/useMessages.ts b/apps/vue/src/layouts/default/header/components/notify/useMessages.ts index 44258a0b8..ecdb920fa 100644 --- a/apps/vue/src/layouts/default/header/components/notify/useMessages.ts +++ b/apps/vue/src/layouts/default/header/components/notify/useMessages.ts @@ -69,7 +69,7 @@ export function useMessages() { function onMessageReceived(message: ChatMessage) { // 处理需要本地化的系统消息 - if (message.source === MessageSourceTye.System && message.extraProperties.L === true) { + if (message.source === MessageSourceTye.System && (message.extraProperties.L === true || message.extraProperties.L === 'true')) { message.content = t( message.extraProperties.content.ResourceName + '.' + message.extraProperties.content.Name, message.extraProperties.content.Values as Recordable, diff --git a/apps/vue/src/layouts/default/header/components/notify/useNotifications.ts b/apps/vue/src/layouts/default/header/components/notify/useNotifications.ts index 2f1386b40..6a940ba5a 100644 --- a/apps/vue/src/layouts/default/header/components/notify/useNotifications.ts +++ b/apps/vue/src/layouts/default/header/components/notify/useNotifications.ts @@ -2,12 +2,13 @@ import { onMounted, onUnmounted, ref } from 'vue'; import { notification } from 'ant-design-vue'; import { getList } from '/@/api/messages/notifications'; import { + NotificationType, NotificationInfo, NotificationSeverity, NotificationReadState, } from '/@/api/messages/model/notificationsModel'; import { formatToDateTime } from '/@/utils/dateUtil'; -import { TabItem, ListItem } from './data'; +import { TabItem, ListItem as Notification } from './data'; import { formatPagedRequest } from '/@/utils/http/abp/helper'; import { NotifyEventEnum } from '/@/enums/imEnum'; import { useSignalR } from '/@/hooks/web/useSignalR'; @@ -49,7 +50,7 @@ export function useNotifications() { if (!data.extraProperties) { return; } - if (data.extraProperties.L === true) { + if (data.extraProperties.L === true || data.extraProperties.L === 'true') { // TODO: 后端统一序列化格式 const { L } = useLocalization( [data.extraProperties.title.resourceName ?? data.extraProperties.title.ResourceName, @@ -70,7 +71,7 @@ export function useNotifications() { ); } } - const notifier: ListItem = { + const notifier: Notification = { id: notificationInfo.id, avatar: data.extraProperties.avatar, title: title, @@ -79,51 +80,56 @@ export function useNotifications() { datetime: formatToDateTime(notificationInfo.creationTime, 'YYYY-MM-DD HH:mm:ss'), type: String(notificationInfo.type), }; - switch (notificationInfo.severity) { + + if (notifer && notificationInfo.type !== NotificationType.ServiceCallback) { + _notification(notifier, notificationInfo.severity); + } + + if (notificationInfo.type === NotificationType.ServiceCallback) { + emitter.emit(NotifyEventEnum.NOTIFICATIONS_SERVICE_CALLBACK, notificationInfo); + } else { + emitter.emit(NotifyEventEnum.NOTIFICATIONS_RECEVIED, notificationInfo); + notifierRef.value.list.push(notifier); + } + } + + + function _notification(notifier: Notification, severity: NotificationSeverity) { + switch (severity) { case NotificationSeverity.Error: case NotificationSeverity.Fatal: notifier.color = 'red'; notifier.avatar = errorAvatar; - if (notifer) { - notification['error']({ - message: notifier.title, - description: notifier.description, - }); - } + notification['error']({ + message: notifier.title, + description: notifier.description, + }); break; case NotificationSeverity.Warn: notifier.color = 'gold'; notifier.avatar = warningAvatar; - if (notifer) { - notification['warning']({ - message: notifier.title, - description: notifier.description, - }); - } + notification['warning']({ + message: notifier.title, + description: notifier.description, + }); break; case NotificationSeverity.Info: notifier.color = 'gold'; notifier.avatar = infoAvatar; - if (notifer) { - notification['info']({ - message: notifier.title, - description: notifier.description, - }); - } + notification['info']({ + message: notifier.title, + description: notifier.description, + }); break; case NotificationSeverity.Success: notifier.color = 'green'; notifier.avatar = successAvatar; - if (notifer) { - notification['success']({ - message: notifier.title, - description: notifier.description, - }); - } + notification['success']({ + message: notifier.title, + description: notifier.description, + }); break; } - emitter.emit(NotifyEventEnum.NOTIFICATIONS_RECEVIED, notificationInfo); - notifierRef.value.list.push(notifier); } function refreshNotifer(page = 1, pageSize = 10) { @@ -145,7 +151,7 @@ export function useNotifications() { }); } - function readNotifer(notifier: ListItem) { + function readNotifer(notifier: Notification) { signalR.invoke('change-state', notifier.id, NotificationReadState.Read).then(() => { notifierRef.value.list = []; refreshNotifer(); diff --git a/apps/vue/types/abp.d.ts b/apps/vue/types/abp.d.ts index 076e0edfb..8100a927a 100644 --- a/apps/vue/types/abp.d.ts +++ b/apps/vue/types/abp.d.ts @@ -3,7 +3,7 @@ declare interface LocalizableStringInfo { name: string; } -declare type ExtraPropertyDictionary = Dictionary; +declare type ExtraPropertyDictionary = { [key: string]: any }; declare interface IHasConcurrencyStamp { concurrencyStamp: string; diff --git a/aspnet-core/modules/common/LINGYUN.Abp.Notifications.Core/LINGYUN/Abp/Notifications/NotificationType.cs b/aspnet-core/modules/common/LINGYUN.Abp.Notifications.Core/LINGYUN/Abp/Notifications/NotificationType.cs index d9ab166f7..0c112755a 100644 --- a/aspnet-core/modules/common/LINGYUN.Abp.Notifications.Core/LINGYUN/Abp/Notifications/NotificationType.cs +++ b/aspnet-core/modules/common/LINGYUN.Abp.Notifications.Core/LINGYUN/Abp/Notifications/NotificationType.cs @@ -16,6 +16,10 @@ /// /// 用户(对应用户,受租户控制) /// - User = 20 + User = 20, + /// + /// 服务端回调,用户不应进行处理 + /// + ServiceCallback = 30, } }