From dbc5ea32aeec769cce362629228feadc537b536b Mon Sep 17 00:00:00 2001 From: shixi <2375768084@qq.com> Date: Tue, 11 Nov 2025 23:41:52 +0800 Subject: [PATCH] feat: add read and delete for each notification --- apps/web-antd/src/layouts/basic.vue | 17 +++++++++++ apps/web-ele/src/layouts/basic.vue | 17 +++++++++++ apps/web-naive/src/layouts/basic.vue | 17 +++++++++++ .../src/widgets/notification/notification.vue | 30 +++++++++++++++++-- .../layouts/src/widgets/notification/types.ts | 1 + 5 files changed, 79 insertions(+), 3 deletions(-) diff --git a/apps/web-antd/src/layouts/basic.vue b/apps/web-antd/src/layouts/basic.vue index 805b8a73..3f977e1f 100644 --- a/apps/web-antd/src/layouts/basic.vue +++ b/apps/web-antd/src/layouts/basic.vue @@ -23,6 +23,7 @@ import LoginForm from '#/views/_core/authentication/login.vue'; const notifications = ref([ { + id: 1, avatar: 'https://avatar.vercel.sh/vercel.svg?text=VB', date: '3小时前', isRead: true, @@ -30,6 +31,7 @@ const notifications = ref([ title: '收到了 14 份新周报', }, { + id: 2, avatar: 'https://avatar.vercel.sh/1', date: '刚刚', isRead: false, @@ -37,6 +39,7 @@ const notifications = ref([ title: '朱偏右 回复了你', }, { + id: 3, avatar: 'https://avatar.vercel.sh/1', date: '2024-01-01', isRead: false, @@ -44,6 +47,7 @@ const notifications = ref([ title: '曲丽丽 评论了你', }, { + id: 4, avatar: 'https://avatar.vercel.sh/satori', date: '1天前', isRead: false, @@ -102,6 +106,17 @@ function handleNoticeClear() { notifications.value = []; } +function markRead(id: number | string) { + const item = notifications.value.find((item) => item.id === id); + if (item) { + item.isRead = true; + } +} + +function remove(id: number | string) { + notifications.value = notifications.value.filter((item) => item.id !== id); +} + function handleMakeAll() { notifications.value.forEach((item) => (item.isRead = true)); } @@ -144,6 +159,8 @@ watch( :dot="showDot" :notifications="notifications" @clear="handleNoticeClear" + @read="(item) => item.id && markRead(item.id)" + @remove="(item) => item.id && remove(item.id)" @make-all="handleMakeAll" /> diff --git a/apps/web-ele/src/layouts/basic.vue b/apps/web-ele/src/layouts/basic.vue index 805b8a73..3f977e1f 100644 --- a/apps/web-ele/src/layouts/basic.vue +++ b/apps/web-ele/src/layouts/basic.vue @@ -23,6 +23,7 @@ import LoginForm from '#/views/_core/authentication/login.vue'; const notifications = ref([ { + id: 1, avatar: 'https://avatar.vercel.sh/vercel.svg?text=VB', date: '3小时前', isRead: true, @@ -30,6 +31,7 @@ const notifications = ref([ title: '收到了 14 份新周报', }, { + id: 2, avatar: 'https://avatar.vercel.sh/1', date: '刚刚', isRead: false, @@ -37,6 +39,7 @@ const notifications = ref([ title: '朱偏右 回复了你', }, { + id: 3, avatar: 'https://avatar.vercel.sh/1', date: '2024-01-01', isRead: false, @@ -44,6 +47,7 @@ const notifications = ref([ title: '曲丽丽 评论了你', }, { + id: 4, avatar: 'https://avatar.vercel.sh/satori', date: '1天前', isRead: false, @@ -102,6 +106,17 @@ function handleNoticeClear() { notifications.value = []; } +function markRead(id: number | string) { + const item = notifications.value.find((item) => item.id === id); + if (item) { + item.isRead = true; + } +} + +function remove(id: number | string) { + notifications.value = notifications.value.filter((item) => item.id !== id); +} + function handleMakeAll() { notifications.value.forEach((item) => (item.isRead = true)); } @@ -144,6 +159,8 @@ watch( :dot="showDot" :notifications="notifications" @clear="handleNoticeClear" + @read="(item) => item.id && markRead(item.id)" + @remove="(item) => item.id && remove(item.id)" @make-all="handleMakeAll" /> diff --git a/apps/web-naive/src/layouts/basic.vue b/apps/web-naive/src/layouts/basic.vue index 0e9747be..1339a841 100644 --- a/apps/web-naive/src/layouts/basic.vue +++ b/apps/web-naive/src/layouts/basic.vue @@ -23,6 +23,7 @@ import LoginForm from '#/views/_core/authentication/login.vue'; const notifications = ref([ { + id: 1, avatar: 'https://avatar.vercel.sh/vercel.svg?text=VB', date: '3小时前', isRead: true, @@ -30,6 +31,7 @@ const notifications = ref([ title: '收到了 14 份新周报', }, { + id: 2, avatar: 'https://avatar.vercel.sh/1', date: '刚刚', isRead: false, @@ -37,6 +39,7 @@ const notifications = ref([ title: '朱偏右 回复了你', }, { + id: 3, avatar: 'https://avatar.vercel.sh/1', date: '2024-01-01', isRead: false, @@ -44,6 +47,7 @@ const notifications = ref([ title: '曲丽丽 评论了你', }, { + id: 4, avatar: 'https://avatar.vercel.sh/satori', date: '1天前', isRead: false, @@ -102,6 +106,17 @@ function handleNoticeClear() { notifications.value = []; } +function markRead(id: number | string) { + const item = notifications.value.find((item) => item.id === id); + if (item) { + item.isRead = true; + } +} + +function remove(id: number | string) { + notifications.value = notifications.value.filter((item) => item.id !== id); +} + function handleMakeAll() { notifications.value.forEach((item) => (item.isRead = true)); } @@ -145,6 +160,8 @@ watch( :dot="showDot" :notifications="notifications" @clear="handleNoticeClear" + @read="(item) => item.id && markRead(item.id)" + @remove="(item) => item.id && remove(item.id)" @make-all="handleMakeAll" /> diff --git a/packages/effects/layouts/src/widgets/notification/notification.vue b/packages/effects/layouts/src/widgets/notification/notification.vue index e15f9b0e..c9a798aa 100644 --- a/packages/effects/layouts/src/widgets/notification/notification.vue +++ b/packages/effects/layouts/src/widgets/notification/notification.vue @@ -1,7 +1,7 @@