diff --git a/apps/vben5/apps/app-antd/src/locales/langs/en-US/abp.json b/apps/vben5/apps/app-antd/src/locales/langs/en-US/abp.json index a90d36c70..7e50c1168 100644 --- a/apps/vben5/apps/app-antd/src/locales/langs/en-US/abp.json +++ b/apps/vben5/apps/app-antd/src/locales/langs/en-US/abp.json @@ -43,7 +43,8 @@ "notifications": { "title": "Notifications", "myNotifilers": "My Notifilers", - "groups": "Groups" + "groups": "Groups", + "definitions": "Definitions" } }, "openiddict": { diff --git a/apps/vben5/apps/app-antd/src/locales/langs/zh-CN/abp.json b/apps/vben5/apps/app-antd/src/locales/langs/zh-CN/abp.json index 04b5bf81c..7976ea8f7 100644 --- a/apps/vben5/apps/app-antd/src/locales/langs/zh-CN/abp.json +++ b/apps/vben5/apps/app-antd/src/locales/langs/zh-CN/abp.json @@ -43,7 +43,8 @@ "notifications": { "title": "通知管理", "myNotifilers": "我的通知", - "groups": "通知分组" + "groups": "通知分组", + "definitions": "通知定义" } }, "openiddict": { diff --git a/apps/vben5/apps/app-antd/src/router/routes/modules/abp.ts b/apps/vben5/apps/app-antd/src/router/routes/modules/abp.ts index 0693005c8..3504f198a 100644 --- a/apps/vben5/apps/app-antd/src/router/routes/modules/abp.ts +++ b/apps/vben5/apps/app-antd/src/router/routes/modules/abp.ts @@ -212,6 +212,16 @@ const routes: RouteRecordRaw[] = [ component: () => import('#/views/notifications/groups/index.vue'), }, + { + meta: { + title: $t('abp.manage.notifications.definitions'), + icon: 'nimbus:notification', + }, + name: 'NotificationDefinitions', + path: '/manage/notifications/definitions', + component: () => + import('#/views/notifications/definitions/index.vue'), + }, ], }, ], diff --git a/apps/vben5/apps/app-antd/src/views/notifications/definitions/index.vue b/apps/vben5/apps/app-antd/src/views/notifications/definitions/index.vue new file mode 100644 index 000000000..a42bc0e17 --- /dev/null +++ b/apps/vben5/apps/app-antd/src/views/notifications/definitions/index.vue @@ -0,0 +1,15 @@ + + + + + + + diff --git a/apps/vben5/packages/@abp/notifications/package.json b/apps/vben5/packages/@abp/notifications/package.json index 1fa83a136..caf1a3720 100644 --- a/apps/vben5/packages/@abp/notifications/package.json +++ b/apps/vben5/packages/@abp/notifications/package.json @@ -34,6 +34,7 @@ "@vben/locales": "workspace:*", "ant-design-vue": "catalog:", "dayjs": "catalog:", - "vue": "catalog:*" + "vue": "catalog:*", + "vxe-table": "catalog:" } } diff --git a/apps/vben5/packages/@abp/notifications/src/api/index.ts b/apps/vben5/packages/@abp/notifications/src/api/index.ts index 36c0581b9..8e7bebea4 100644 --- a/apps/vben5/packages/@abp/notifications/src/api/index.ts +++ b/apps/vben5/packages/@abp/notifications/src/api/index.ts @@ -1,4 +1,5 @@ export { useMyNotifilersApi } from './useMyNotifilersApi'; export { useMySubscribesApi } from './useMySubscribesApi'; +export { useNotificationDefinitionsApi } from './useNotificationDefinitionsApi'; export { useNotificationGroupDefinitionsApi } from './useNotificationGroupDefinitionsApi'; export { useNotificationsApi } from './useNotificationsApi'; diff --git a/apps/vben5/packages/@abp/notifications/src/api/useNotificationDefinitionsApi.ts b/apps/vben5/packages/@abp/notifications/src/api/useNotificationDefinitionsApi.ts new file mode 100644 index 000000000..839e8e2d3 --- /dev/null +++ b/apps/vben5/packages/@abp/notifications/src/api/useNotificationDefinitionsApi.ts @@ -0,0 +1,100 @@ +import type { ListResultDto } from '@abp/core'; + +import type { + NotificationDefinitionCreateDto, + NotificationDefinitionDto, + NotificationDefinitionGetListInput, + NotificationDefinitionUpdateDto, +} from '../types/definitions'; + +import { useRequest } from '@abp/request'; + +export function useNotificationDefinitionsApi() { + const { cancel, request } = useRequest(); + + /** + * 删除通知定义 + * @param name 通知名称 + */ + function deleteApi(name: string): Promise { + return request(`/api/notifications/definitions/notifications/${name}`, { + method: 'DELETE', + }); + } + + /** + * 查询通知定义 + * @param name 通知名称 + * @returns 通知定义数据传输对象 + */ + function getApi(name: string): Promise { + return request( + `/api/notifications/definitions/notifications/${name}`, + { + method: 'GET', + }, + ); + } + + /** + * 查询通知定义列表 + * @param input 通知过滤条件 + * @returns 通知定义数据传输对象列表 + */ + function getListApi( + input?: NotificationDefinitionGetListInput, + ): Promise> { + return request>( + `/api/notifications/definitions/notifications`, + { + method: 'GET', + params: input, + }, + ); + } + + /** + * 创建通知定义 + * @param input 通知定义参数 + * @returns 通知定义数据传输对象 + */ + function createApi( + input: NotificationDefinitionCreateDto, + ): Promise { + return request( + '/api/notifications/definitions/notifications', + { + data: input, + method: 'POST', + }, + ); + } + + /** + * 更新通知定义 + * @param name 通知名称 + * @param input 通知定义参数 + * @returns 通知定义数据传输对象 + */ + function updateApi( + name: string, + input: NotificationDefinitionUpdateDto, + ): Promise { + return request( + `/api/notifications/definitions/notifications/${name}`, + { + data: input, + method: 'PUT', + }, + ); + } + + return { + cancel, + createApi, + deleteApi, + getApi, + getListApi, + updateApi, + }; +} diff --git a/apps/vben5/packages/@abp/notifications/src/api/useNotificationsApi.ts b/apps/vben5/packages/@abp/notifications/src/api/useNotificationsApi.ts index 5934f3d11..484cfc089 100644 --- a/apps/vben5/packages/@abp/notifications/src/api/useNotificationsApi.ts +++ b/apps/vben5/packages/@abp/notifications/src/api/useNotificationsApi.ts @@ -2,6 +2,7 @@ import type { ListResultDto } from '@abp/core'; import type { NotificationGroupDto, + NotificationProviderDto, NotificationTemplateDto, } from '../types/definitions'; import type { @@ -13,6 +14,20 @@ import { useRequest } from '@abp/request'; export function useNotificationsApi() { const { cancel, request } = useRequest(); + /** + * 获取可用通知提供者列表 + * @returns {Promise>} 可用通知提供者列表 + */ + function getAssignableProvidersApi(): Promise< + ListResultDto + > { + return request>( + '/api/notifications/assignable-providers', + { + method: 'GET', + }, + ); + } /** * 获取可用通知列表 * @returns {Promise>} 可用通知列表 @@ -69,6 +84,7 @@ export function useNotificationsApi() { return { cancel, getAssignableNotifiersApi, + getAssignableProvidersApi, getAssignableTemplatesApi, sendNotiferApi, sendTemplateNotiferApi, diff --git a/apps/vben5/packages/@abp/notifications/src/components/definitions/groups/NotificationGroupDefinitionModal.vue b/apps/vben5/packages/@abp/notifications/src/components/definitions/groups/NotificationGroupDefinitionModal.vue index 02fbd6182..0b27ec15d 100644 --- a/apps/vben5/packages/@abp/notifications/src/components/definitions/groups/NotificationGroupDefinitionModal.vue +++ b/apps/vben5/packages/@abp/notifications/src/components/definitions/groups/NotificationGroupDefinitionModal.vue @@ -10,7 +10,7 @@ import { useVbenModal } from '@vben/common-ui'; import { $t } from '@vben/locales'; import { LocalizableInput, PropertyTable } from '@abp/ui'; -import { Form, Input, message, Tabs } from 'ant-design-vue'; +import { Checkbox, Form, Input, message, Tabs } from 'ant-design-vue'; import { useNotificationGroupDefinitionsApi } from '../../../api/useNotificationGroupDefinitionsApi'; @@ -47,9 +47,10 @@ const [Modal, modalApi] = useVbenModal({ }, onConfirm: async () => { await form.value?.validate(); + const input = toValue(formModel); const api = isEditModel.value - ? updateApi(formModel.value.name, toValue(formModel)) - : createApi(toValue(formModel)); + ? updateApi(formModel.value.name, input) + : createApi(input); modalApi.setState({ confirmLoading: true, loading: true }); api .then((res) => { @@ -132,6 +133,27 @@ function onPropDelete(prop: PropertyInfo) { :disabled="formModel.isStatic" /> + + + + + + {{ $t('Notifications.DisplayName:AllowSubscriptionToClients') }} + + diff --git a/apps/vben5/packages/@abp/notifications/src/components/definitions/groups/NotificationGroupDefinitionTable.vue b/apps/vben5/packages/@abp/notifications/src/components/definitions/groups/NotificationGroupDefinitionTable.vue index 9068b37fa..7a1dff33f 100644 --- a/apps/vben5/packages/@abp/notifications/src/components/definitions/groups/NotificationGroupDefinitionTable.vue +++ b/apps/vben5/packages/@abp/notifications/src/components/definitions/groups/NotificationGroupDefinitionTable.vue @@ -1,11 +1,14 @@ @@ -208,10 +236,27 @@ onMounted(onGet); > {{ $t('AbpUi.Delete') }} + + + onMenuClick(row, info)"> + + {{ $t('Notifications.NotificationDefinitions:AddNew') }} + + + + + onGet()" /> + diff --git a/apps/vben5/packages/@abp/notifications/src/components/definitions/notifications/NotificationDefinitionModal.vue b/apps/vben5/packages/@abp/notifications/src/components/definitions/notifications/NotificationDefinitionModal.vue new file mode 100644 index 000000000..0f3411654 --- /dev/null +++ b/apps/vben5/packages/@abp/notifications/src/components/definitions/notifications/NotificationDefinitionModal.vue @@ -0,0 +1,311 @@ + + + + + + + + + + + + + + + + + + + + + + + {{ $t('Notifications.DisplayName:AllowSubscriptionToClients') }} + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/apps/vben5/packages/@abp/notifications/src/components/definitions/notifications/NotificationDefinitionTable.vue b/apps/vben5/packages/@abp/notifications/src/components/definitions/notifications/NotificationDefinitionTable.vue new file mode 100644 index 000000000..888f87ca2 --- /dev/null +++ b/apps/vben5/packages/@abp/notifications/src/components/definitions/notifications/NotificationDefinitionTable.vue @@ -0,0 +1,418 @@ + + + + + + + {{ $t('Notifications.NotificationDefinitions:AddNew') }} + + + + + + + + + + + + + + {{ provider }} + + + + + + + {{ $t('AbpUi.Edit') }} + + + {{ $t('AbpUi.Delete') }} + + + + onMenuClick(definition, info)"> + + {{ $t('Notifications.Notifications:Send') }} + + + + + + + + + + + onGet()" /> + + + + diff --git a/apps/vben5/packages/@abp/notifications/src/components/definitions/notifications/NotificationSendModal.vue b/apps/vben5/packages/@abp/notifications/src/components/definitions/notifications/NotificationSendModal.vue new file mode 100644 index 000000000..787e5cfe8 --- /dev/null +++ b/apps/vben5/packages/@abp/notifications/src/components/definitions/notifications/NotificationSendModal.vue @@ -0,0 +1,143 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/apps/vben5/packages/@abp/notifications/src/components/definitions/notifications/useEnumMaps.ts b/apps/vben5/packages/@abp/notifications/src/components/definitions/notifications/useEnumMaps.ts new file mode 100644 index 000000000..4b5567992 --- /dev/null +++ b/apps/vben5/packages/@abp/notifications/src/components/definitions/notifications/useEnumMaps.ts @@ -0,0 +1,123 @@ +import { reactive } from 'vue'; + +import { $t } from '@vben/locales'; + +import { + NotificationContentType, + NotificationLifetime, + NotificationSeverity, + NotificationType, +} from '../../../types/notifications'; + +export function useEnumMaps() { + const notificationTypeOptions = reactive([ + { + label: $t('Notifications.NotificationType:User'), + value: NotificationType.User, + }, + { + label: $t('Notifications.NotificationType:System'), + value: NotificationType.System, + }, + { + label: $t('Notifications.NotificationType:Application'), + value: NotificationType.Application, + }, + { + label: $t('Notifications.NotificationType:ServiceCallback'), + value: NotificationType.ServiceCallback, + }, + ]); + const notificationTypeMap = reactive({ + [NotificationType.Application]: $t( + 'Notifications.NotificationType:Application', + ), + [NotificationType.ServiceCallback]: $t( + 'Notifications.NotificationType:ServiceCallback', + ), + [NotificationType.System]: $t('Notifications.NotificationType:System'), + [NotificationType.User]: $t('Notifications.NotificationType:User'), + }); + const notificationLifetimeOptions = reactive([ + { + label: $t('Notifications.NotificationLifetime:OnlyOne'), + value: NotificationLifetime.OnlyOne, + }, + { + label: $t('Notifications.NotificationLifetime:Persistent'), + value: NotificationLifetime.Persistent, + }, + ]); + const notificationLifetimeMap = reactive({ + [NotificationLifetime.OnlyOne]: $t( + 'Notifications.NotificationLifetime:OnlyOne', + ), + [NotificationLifetime.Persistent]: $t( + 'Notifications.NotificationLifetime:Persistent', + ), + }); + const notificationContentTypeOptions = reactive([ + { + label: $t('Notifications.NotificationContentType:Text'), + value: NotificationContentType.Text, + }, + { + label: $t('Notifications.NotificationContentType:Json'), + value: NotificationContentType.Json, + }, + { + label: $t('Notifications.NotificationContentType:Html'), + value: NotificationContentType.Html, + }, + { + label: $t('Notifications.NotificationContentType:Markdown'), + value: NotificationContentType.Markdown, + }, + ]); + const notificationContentTypeMap = reactive({ + [NotificationContentType.Html]: $t( + 'Notifications.NotificationContentType:Html', + ), + [NotificationContentType.Json]: $t( + 'Notifications.NotificationContentType:Json', + ), + [NotificationContentType.Markdown]: $t( + 'Notifications.NotificationContentType:Markdown', + ), + [NotificationContentType.Text]: $t( + 'Notifications.NotificationContentType:Text', + ), + }); + const notificationSeverityOptions = reactive([ + { + label: $t('Notifications.NotificationSeverity:Success'), + value: NotificationSeverity.Success, + }, + { + label: $t('Notifications.NotificationSeverity:Info'), + value: NotificationSeverity.Info, + }, + { + label: $t('Notifications.NotificationSeverity:Warn'), + value: NotificationSeverity.Warn, + }, + { + label: $t('Notifications.NotificationSeverity:Fatal'), + value: NotificationSeverity.Fatal, + }, + { + label: $t('Notifications.NotificationSeverity:Error'), + value: NotificationSeverity.Error, + }, + ]); + + return { + notificationContentTypeMap, + notificationContentTypeOptions, + notificationLifetimeMap, + notificationLifetimeOptions, + notificationSeverityOptions, + notificationTypeMap, + notificationTypeOptions, + }; +} diff --git a/apps/vben5/packages/@abp/notifications/src/components/index.ts b/apps/vben5/packages/@abp/notifications/src/components/index.ts index bb1fc6eb1..4b8306b41 100644 --- a/apps/vben5/packages/@abp/notifications/src/components/index.ts +++ b/apps/vben5/packages/@abp/notifications/src/components/index.ts @@ -1,2 +1,3 @@ export { default as NotificationGroupDefinitionTable } from './definitions/groups/NotificationGroupDefinitionTable.vue'; +export { default as NotificationDefinitionTable } from './definitions/notifications/NotificationDefinitionTable.vue'; export { default as MyNotificationTable } from './my-notifilers/MyNotificationTable.vue'; diff --git a/apps/vben5/packages/@abp/notifications/src/constants/permissions.ts b/apps/vben5/packages/@abp/notifications/src/constants/permissions.ts index 5b28b43d2..1c4e43c5e 100644 --- a/apps/vben5/packages/@abp/notifications/src/constants/permissions.ts +++ b/apps/vben5/packages/@abp/notifications/src/constants/permissions.ts @@ -8,3 +8,21 @@ export const GroupDefinitionsPermissions = { /** 更新 */ Update: 'Notifications.GroupDefinitions.Update', }; +/** 通知定义权限 */ +export const NotificationDefinitionsPermissions = { + /** 新增 */ + Create: 'Notifications.Definitions.Create', + Default: 'Notifications.Definitions', + /** 删除 */ + Delete: 'Notifications.Definitions.Delete', + /** 更新 */ + Update: 'Notifications.Definitions.Update', +}; +/** 通知权限 */ +export const NotificationPermissions = { + /** 发送通知 */ + Create: 'Notifications.Notification.Send', + Default: 'Notifications.Notification', + /** 删除 */ + Delete: 'Notifications.Notification.Delete', +}; diff --git a/apps/vben5/packages/@abp/notifications/src/hooks/useNotifications.ts b/apps/vben5/packages/@abp/notifications/src/hooks/useNotifications.ts index 39b2370a6..7b16013b5 100644 --- a/apps/vben5/packages/@abp/notifications/src/hooks/useNotifications.ts +++ b/apps/vben5/packages/@abp/notifications/src/hooks/useNotifications.ts @@ -61,16 +61,12 @@ export function useNotifications() { /** 通知推送 */ function _notification(notifier: Notification) { - let message = notifier.description; + let message = notifier.message; switch (notifier.contentType) { - case NotificationContentType.Html: - case NotificationContentType.Json: - case NotificationContentType.Markdown: { - message = notifier.title; - break; - } case NotificationContentType.Text: { - message = notifier.description; + if (notifier.description) { + message = notifier.description; + } } } switch (notifier.severity) { diff --git a/apps/vben5/packages/@abp/notifications/src/types/definitions.ts b/apps/vben5/packages/@abp/notifications/src/types/definitions.ts index 4a8425070..419686ba5 100644 --- a/apps/vben5/packages/@abp/notifications/src/types/definitions.ts +++ b/apps/vben5/packages/@abp/notifications/src/types/definitions.ts @@ -1,4 +1,10 @@ -import type { NotificationLifetime, NotificationType } from './notifications'; +import type { ExtensibleObject, IHasExtraProperties } from '@abp/core'; + +import type { + NotificationContentType, + NotificationLifetime, + NotificationType, +} from './notifications'; interface NotificationDto { description: string; @@ -14,6 +20,10 @@ interface NotificationGroupDto { notifications: NotificationDto[]; } +interface NotificationProviderDto { + name: string; +} + interface NotificationTemplateDto { content?: string; culture?: string; @@ -22,4 +32,56 @@ interface NotificationTemplateDto { title: string; } -export type { NotificationDto, NotificationGroupDto, NotificationTemplateDto }; +interface NotificationDefinitionDto extends ExtensibleObject { + allowSubscriptionToClients: boolean; + contentType: NotificationContentType; + description?: string; + displayName: string; + groupName: string; + isStatic: boolean; + name: string; + notificationLifetime: NotificationLifetime; + notificationType: NotificationType; + providers?: string[]; + template?: string; +} + +interface NotificationDefinitionGetListInput { + allowSubscriptionToClients?: boolean; + contentType?: NotificationContentType; + filter?: string; + groupName?: string; + notificationLifetime?: NotificationLifetime; + notificationType?: NotificationType; + template?: string; +} + +interface NotificationDefinitionCreateOrUpdateDto extends IHasExtraProperties { + allowSubscriptionToClients?: boolean; + contentType?: NotificationContentType; + description?: string; + displayName: string; + notificationLifetime?: NotificationLifetime; + notificationType?: NotificationType; + providers?: string[]; + template?: string; +} + +type NotificationDefinitionUpdateDto = NotificationDefinitionCreateOrUpdateDto; + +interface NotificationDefinitionCreateDto + extends NotificationDefinitionCreateOrUpdateDto { + groupName?: string; + name: string; +} + +export type { + NotificationDefinitionCreateDto, + NotificationDefinitionDto, + NotificationDefinitionGetListInput, + NotificationDefinitionUpdateDto, + NotificationDto, + NotificationGroupDto, + NotificationProviderDto, + NotificationTemplateDto, +};