Browse Source

feat(notifications): add new NotificationType

pull/783/head
cKey 3 years ago
parent
commit
f8794d835d
  1. 1
      apps/vue/src/api/messages/model/notificationsModel.ts
  2. 2
      apps/vue/src/enums/imEnum.ts
  3. 2
      apps/vue/src/layouts/default/header/components/notify/useMessages.ts
  4. 68
      apps/vue/src/layouts/default/header/components/notify/useNotifications.ts
  5. 2
      apps/vue/types/abp.d.ts
  6. 6
      aspnet-core/modules/common/LINGYUN.Abp.Notifications.Core/LINGYUN/Abp/Notifications/NotificationType.cs

1
apps/vue/src/api/messages/model/notificationsModel.ts

@ -7,6 +7,7 @@ export enum NotificationType {
Application = 0, Application = 0,
System = 10, System = 10,
User = 20, User = 20,
ServiceCallback = 30,
} }
export enum NotificationSeverity { export enum NotificationSeverity {

2
apps/vue/src/enums/imEnum.ts

@ -26,4 +26,6 @@ export enum NotifyEventEnum {
NOTIFICATIONS_RECEVIED = 'notifications:recevied', NOTIFICATIONS_RECEVIED = 'notifications:recevied',
/** 通知已读 */ /** 通知已读 */
NOTIFICATIONS_READ = 'notifications:read', NOTIFICATIONS_READ = 'notifications:read',
/** 服务端回调 */
NOTIFICATIONS_SERVICE_CALLBACK = 'notifications:service_callback',
} }

2
apps/vue/src/layouts/default/header/components/notify/useMessages.ts

@ -69,7 +69,7 @@ export function useMessages() {
function onMessageReceived(message: ChatMessage) { 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.content = t(
message.extraProperties.content.ResourceName + '.' + message.extraProperties.content.Name, message.extraProperties.content.ResourceName + '.' + message.extraProperties.content.Name,
message.extraProperties.content.Values as Recordable, message.extraProperties.content.Values as Recordable,

68
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 { notification } from 'ant-design-vue';
import { getList } from '/@/api/messages/notifications'; import { getList } from '/@/api/messages/notifications';
import { import {
NotificationType,
NotificationInfo, NotificationInfo,
NotificationSeverity, NotificationSeverity,
NotificationReadState, NotificationReadState,
} from '/@/api/messages/model/notificationsModel'; } from '/@/api/messages/model/notificationsModel';
import { formatToDateTime } from '/@/utils/dateUtil'; 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 { formatPagedRequest } from '/@/utils/http/abp/helper';
import { NotifyEventEnum } from '/@/enums/imEnum'; import { NotifyEventEnum } from '/@/enums/imEnum';
import { useSignalR } from '/@/hooks/web/useSignalR'; import { useSignalR } from '/@/hooks/web/useSignalR';
@ -49,7 +50,7 @@ export function useNotifications() {
if (!data.extraProperties) { if (!data.extraProperties) {
return; return;
} }
if (data.extraProperties.L === true) { if (data.extraProperties.L === true || data.extraProperties.L === 'true') {
// TODO: 后端统一序列化格式 // TODO: 后端统一序列化格式
const { L } = useLocalization( const { L } = useLocalization(
[data.extraProperties.title.resourceName ?? data.extraProperties.title.ResourceName, [data.extraProperties.title.resourceName ?? data.extraProperties.title.ResourceName,
@ -70,7 +71,7 @@ export function useNotifications() {
); );
} }
} }
const notifier: ListItem = { const notifier: Notification = {
id: notificationInfo.id, id: notificationInfo.id,
avatar: data.extraProperties.avatar, avatar: data.extraProperties.avatar,
title: title, title: title,
@ -79,51 +80,56 @@ export function useNotifications() {
datetime: formatToDateTime(notificationInfo.creationTime, 'YYYY-MM-DD HH:mm:ss'), datetime: formatToDateTime(notificationInfo.creationTime, 'YYYY-MM-DD HH:mm:ss'),
type: String(notificationInfo.type), 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.Error:
case NotificationSeverity.Fatal: case NotificationSeverity.Fatal:
notifier.color = 'red'; notifier.color = 'red';
notifier.avatar = errorAvatar; notifier.avatar = errorAvatar;
if (notifer) { notification['error']({
notification['error']({ message: notifier.title,
message: notifier.title, description: notifier.description,
description: notifier.description, });
});
}
break; break;
case NotificationSeverity.Warn: case NotificationSeverity.Warn:
notifier.color = 'gold'; notifier.color = 'gold';
notifier.avatar = warningAvatar; notifier.avatar = warningAvatar;
if (notifer) { notification['warning']({
notification['warning']({ message: notifier.title,
message: notifier.title, description: notifier.description,
description: notifier.description, });
});
}
break; break;
case NotificationSeverity.Info: case NotificationSeverity.Info:
notifier.color = 'gold'; notifier.color = 'gold';
notifier.avatar = infoAvatar; notifier.avatar = infoAvatar;
if (notifer) { notification['info']({
notification['info']({ message: notifier.title,
message: notifier.title, description: notifier.description,
description: notifier.description, });
});
}
break; break;
case NotificationSeverity.Success: case NotificationSeverity.Success:
notifier.color = 'green'; notifier.color = 'green';
notifier.avatar = successAvatar; notifier.avatar = successAvatar;
if (notifer) { notification['success']({
notification['success']({ message: notifier.title,
message: notifier.title, description: notifier.description,
description: notifier.description, });
});
}
break; break;
} }
emitter.emit(NotifyEventEnum.NOTIFICATIONS_RECEVIED, notificationInfo);
notifierRef.value.list.push(notifier);
} }
function refreshNotifer(page = 1, pageSize = 10) { 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(() => { signalR.invoke('change-state', notifier.id, NotificationReadState.Read).then(() => {
notifierRef.value.list = []; notifierRef.value.list = [];
refreshNotifer(); refreshNotifer();

2
apps/vue/types/abp.d.ts

@ -3,7 +3,7 @@ declare interface LocalizableStringInfo {
name: string; name: string;
} }
declare type ExtraPropertyDictionary = Dictionary<string, any>; declare type ExtraPropertyDictionary = { [key: string]: any };
declare interface IHasConcurrencyStamp { declare interface IHasConcurrencyStamp {
concurrencyStamp: string; concurrencyStamp: string;

6
aspnet-core/modules/common/LINGYUN.Abp.Notifications.Core/LINGYUN/Abp/Notifications/NotificationType.cs

@ -16,6 +16,10 @@
/// <summary> /// <summary>
/// 用户(对应用户,受租户控制) /// 用户(对应用户,受租户控制)
/// </summary> /// </summary>
User = 20 User = 20,
/// <summary>
/// 服务端回调,用户不应进行处理
/// </summary>
ServiceCallback = 30,
} }
} }

Loading…
Cancel
Save