From 0b3d7a21d514f9e6732a843bb66682d80793198e Mon Sep 17 00:00:00 2001 From: AnNingUI Date: Fri, 15 Aug 2025 11:59:29 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=BF=81=E7=A7=BBmarkAllRead=E5=87=BD?= =?UTF-8?q?=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend_nuxt/utils/notification.js | 32 +++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/frontend_nuxt/utils/notification.js b/frontend_nuxt/utils/notification.js index 723a5ea9a..7214dbb43 100644 --- a/frontend_nuxt/utils/notification.js +++ b/frontend_nuxt/utils/notification.js @@ -1,7 +1,7 @@ import { navigateTo, useRuntimeConfig } from 'nuxt/app' import { reactive, ref } from 'vue' import { toast } from '~/composables/useToast' -import { getToken } from '~/utils/auth' +import { authState, getToken } from '~/utils/auth' import { reactionEmojiMap } from '~/utils/reactions' export const notificationState = reactive({ @@ -303,13 +303,41 @@ function createFetchNotifications() { fetchUnreadCount() } } + + const markAllRead = async () => { + // 除了 REGISTER_REQUEST 类型消息 + const idsToMark = notifications.value + .filter((n) => n.type !== 'REGISTER_REQUEST' && !n.read) + .map((n) => n.id) + if (idsToMark.length === 0) return + notifications.value.forEach((n) => { + if (n.type !== 'REGISTER_REQUEST') n.read = true + }) + notificationState.unreadCount = notifications.value.filter((n) => !n.read).length + const ok = await markNotificationsRead(idsToMark) + if (!ok) { + notifications.value.forEach((n) => { + if (idsToMark.includes(n.id)) n.read = false + }) + await fetchUnreadCount() + return + } + fetchUnreadCount() + if (authState.role === 'ADMIN') { + toast.success('已读所有消息(注册请求除外)') + } else { + toast.success('已读所有消息') + } + } return { fetchNotifications, markRead, notifications, isLoadingMessage, + markRead, + markAllRead, } } -export const { fetchNotifications, markRead, notifications, isLoadingMessage } = +export const { fetchNotifications, markRead, notifications, isLoadingMessage, markAllRead } = createFetchNotifications()