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,
System = 10,
User = 20,
ServiceCallback = 30,
}
export enum NotificationSeverity {

2
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',
}

2
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,

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 { 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();

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

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

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

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

Loading…
Cancel
Save