From b914133dd7011cd5109348f2d3431e07eafe92ab Mon Sep 17 00:00:00 2001 From: mtvpls Date: Wed, 18 Feb 2026 19:56:47 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=80=9A=E7=9F=A5=E5=B7=B2?= =?UTF-8?q?=E8=AF=BB=E4=B8=8D=E6=9B=B4=E6=96=B0=E8=8F=9C=E5=8D=95=E7=8A=B6?= =?UTF-8?q?=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/NotificationPanel.tsx | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/components/NotificationPanel.tsx b/src/components/NotificationPanel.tsx index d6b3300..6231c47 100644 --- a/src/components/NotificationPanel.tsx +++ b/src/components/NotificationPanel.tsx @@ -55,6 +55,8 @@ export const NotificationPanel: React.FC = ({ n.id === notificationId ? { ...n, read: true } : n ) ); + // 触发事件通知 UserMenu 更新未读计数 + window.dispatchEvent(new Event('notificationsUpdated')); } } catch (error) { console.error('标记已读失败:', error); @@ -74,7 +76,12 @@ export const NotificationPanel: React.FC = ({ }); if (response.ok) { + const deletedNotification = notifications.find((n) => n.id === notificationId); setNotifications((prev) => prev.filter((n) => n.id !== notificationId)); + // 如果删除的是未读通知,触发事件更新 UserMenu + if (deletedNotification && !deletedNotification.read) { + window.dispatchEvent(new Event('notificationsUpdated')); + } } } catch (error) { console.error('删除通知失败:', error); @@ -94,6 +101,8 @@ export const NotificationPanel: React.FC = ({ if (response.ok) { setNotifications([]); + // 触发事件通知 UserMenu 更新未读计数 + window.dispatchEvent(new Event('notificationsUpdated')); } } catch (error) { console.error('清空通知失败:', error);