From c66ee881b107c741d9b6f2d0ead67007a8bf8dec Mon Sep 17 00:00:00 2001 From: jxxghp Date: Wed, 17 Jun 2026 16:32:00 +0800 Subject: [PATCH] refactor: remove ShortcutMessageDialog and MessageView components; update ShortcutBar and UserNotification for improved notification handling --- src/api/types.ts | 20 +- src/components/cards/MessageCard.vue | 226 -------- .../dialog/ShortcutMessageDialog.vue | 139 ----- src/layouts/components/ShortcutBar.vue | 101 +--- src/layouts/components/UserNotification.vue | 492 +++++++++++++++--- src/locales/en-US.ts | 4 - src/locales/zh-CN.ts | 4 - src/locales/zh-TW.ts | 4 - src/views/system/MessageView.vue | 426 --------------- 9 files changed, 454 insertions(+), 962 deletions(-) delete mode 100644 src/components/cards/MessageCard.vue delete mode 100644 src/components/dialog/ShortcutMessageDialog.vue delete mode 100644 src/views/system/MessageView.vue diff --git a/src/api/types.ts b/src/api/types.ts index 38f131b9..c40b055a 100644 --- a/src/api/types.ts +++ b/src/api/types.ts @@ -1131,6 +1131,12 @@ export interface MediaServerLibrary { // 消息通知 export interface Message { + // 消息ID + id?: number + // 消息渠道 + channel?: string + // 消息来源 + source?: string // 消息类型 mtype?: string // 消息标题 @@ -1150,19 +1156,15 @@ export interface Message { // 消息方向:0-接收,1-发送 action?: number // JSON - note?: string + note?: string | any[] | Record } // 系统通知 -export interface SystemNotification { - // 通知类型 user/system/plugin - type: string - // 通知标题 - title: string - // 通知内容 - text: string +export interface SystemNotification extends Message { + // 通知类型 user/system/plugin/notification + type?: string // 通知时间 - date: string + date?: string // 是否已读 read?: boolean } diff --git a/src/components/cards/MessageCard.vue b/src/components/cards/MessageCard.vue deleted file mode 100644 index b1d79bf6..00000000 --- a/src/components/cards/MessageCard.vue +++ /dev/null @@ -1,226 +0,0 @@ - - - - - diff --git a/src/components/dialog/ShortcutMessageDialog.vue b/src/components/dialog/ShortcutMessageDialog.vue deleted file mode 100644 index c5f16d54..00000000 --- a/src/components/dialog/ShortcutMessageDialog.vue +++ /dev/null @@ -1,139 +0,0 @@ - - - diff --git a/src/layouts/components/ShortcutBar.vue b/src/layouts/components/ShortcutBar.vue index 24cece50..194bbe2b 100644 --- a/src/layouts/components/ShortcutBar.vue +++ b/src/layouts/components/ShortcutBar.vue @@ -5,7 +5,6 @@ import { openSharedDialog } from '@/composables/useSharedDialog' import { useI18n } from 'vue-i18n' import { useUserStore } from '@/stores' import { buildUserPermissionContext, filterItemsByPermission, hasItemPermission, type PermissionProtectedItem } from '@/utils/permission' -import { clearUnreadMessages, getUnreadCount, onUnreadMessage } from '@/utils/badge' // 国际化 const { t } = useI18n() @@ -21,7 +20,6 @@ const WordsView = defineAsyncComponent(() => import('@/views/system/WordsView.vu const CacheView = defineAsyncComponent(() => import('@/views/system/CacheView.vue')) const AccountSettingService = defineAsyncComponent(() => import('@/views/system/ServiceView.vue')) const ShortcutLogDialog = defineAsyncComponent(() => import('@/components/dialog/ShortcutLogDialog.vue')) -const ShortcutMessageDialog = defineAsyncComponent(() => import('@/components/dialog/ShortcutMessageDialog.vue')) const ShortcutToolDialog = defineAsyncComponent(() => import('@/components/dialog/ShortcutToolDialog.vue')) type ShortcutItem = PermissionProtectedItem & { @@ -44,12 +42,6 @@ const appsMenu = ref(false) // 菜单最大宽度 const menuMaxWidth = ref(420) -// 未读消息数量,用于控制消息捷径卡片上的红点。 -const unreadMessageCount = ref(0) -const hasUnreadMessages = computed(() => unreadMessageCount.value > 0) -let unreadStateRevision = 0 -let stopUnreadMessageListener: (() => void) | null = null - // 定义捷径列表 const shortcuts: ShortcutItem[] = [ { @@ -123,55 +115,16 @@ const shortcuts: ShortcutItem[] = [ component: ModuleTestView, titleText: t('shortcut.system.subtitle'), }, - { - title: t('shortcut.message.title'), - subtitle: t('shortcut.message.subtitle'), - icon: 'mdi-message', - dialog: 'message', - customDialog: ShortcutMessageDialog, - }, ].map(item => ({ ...item, permission: 'admin' })) const visibleShortcuts = computed(() => filterItemsByPermission(shortcuts, userPermissions.value)) -/** 设置消息捷径卡片的未读数量。 */ -function setUnreadMessageCount(count: number) { - unreadMessageCount.value = Math.max(0, count) -} - -/** 同步全局未读消息数量到消息捷径卡片。 */ -function handleUnreadMessage(count: number) { - unreadStateRevision += 1 - setUnreadMessageCount(count) -} - -/** 从 Service Worker 读取当前未读数量,避免错过启动早期事件。 */ -async function syncUnreadMessageStateFromBadge() { - const revision = unreadStateRevision - const count = await getUnreadCount() - - if (revision === unreadStateRevision) { - setUnreadMessageCount(count) - } -} - -/** 清空未读消息数量和 PWA 桌面角标。 */ -function clearUnreadMessageState() { - unreadStateRevision += 1 - setUnreadMessageCount(0) - void clearUnreadMessages() -} - /** 打开快捷工具对应的共享弹窗。 */ function openShortcutDialog(item: (typeof shortcuts)[number]) { if (!hasItemPermission(item, userPermissions.value)) return appsMenu.value = false - if (item.dialog === 'message') { - clearUnreadMessageState() - } - if (item.customDialog) { openSharedDialog(item.customDialog, {}, {}, { closeOn: ['close', 'update:modelValue'] }) return @@ -195,21 +148,7 @@ function openShortcutDialog(item: (typeof shortcuts)[number]) { ) } -/** 供外部调用的打开消息弹窗方法。 */ -function openMessageDialogFromExternal() { - const messageShortcut = visibleShortcuts.value.find(item => item.dialog === 'message') - if (messageShortcut) openShortcutDialog(messageShortcut) -} - -// 暴露方法给父组件 -defineExpose({ - openMessageDialog: openMessageDialogFromExternal, -}) - onMounted(() => { - stopUnreadMessageListener = onUnreadMessage(handleUnreadMessage) - void syncUnreadMessageStateFromBadge() - const shortcut = getQueryValue('shortcut') if (shortcut) { const found = visibleShortcuts.value.find(item => item.dialog === shortcut) @@ -218,10 +157,6 @@ onMounted(() => { } } }) - -onBeforeUnmount(() => { - stopUnreadMessageListener?.() -})