From 31e43b73379326df5d0d06dcc37ef5049a34f0f1 Mon Sep 17 00:00:00 2001
From: yuan <123@>
Date: 星期三, 26 八月 2026 14:28:55 +0800
Subject: [PATCH] feat: 添加清除当前用户的所有消息按钮

---
 src/layout/components/NotificationCenter/index.vue |   57 +++++++++++++++++++++++++---
 src/api/system/message.js                          |    8 ++++
 2 files changed, 58 insertions(+), 7 deletions(-)

diff --git a/src/api/system/message.js b/src/api/system/message.js
index dd81cc5..e4d278c 100644
--- a/src/api/system/message.js
+++ b/src/api/system/message.js
@@ -35,6 +35,14 @@
   });
 }
 
+// 娓呴櫎褰撳墠鐢ㄦ埛鐨勫叏閮ㄦ秷鎭�
+export function clearAllMessage() {
+  return request({
+    url: "/system/notice/clearAll",
+    method: "delete",
+  });
+}
+
 // 纭娑堟伅
 export function confirmMessage(noticeId, status) {
   return request({
diff --git a/src/layout/components/NotificationCenter/index.vue b/src/layout/components/NotificationCenter/index.vue
index 66f489a..ad066ec 100644
--- a/src/layout/components/NotificationCenter/index.vue
+++ b/src/layout/components/NotificationCenter/index.vue
@@ -2,12 +2,20 @@
   <div class="notification-popover-content">
     <div class="popover-header">
       <span class="popover-title">娑堟伅閫氱煡</span>
-      <el-button type="primary"
-                 size="small"
-                 @click="handleMarkAllAsRead"
-                 :disabled="unreadCount === 0">
-        涓�閿凡璇�
-      </el-button>
+      <div class="popover-actions">
+        <el-button type="primary"
+                   size="small"
+                   @click="handleMarkAllAsRead"
+                   :disabled="unreadCount === 0">
+          涓�閿凡璇�
+        </el-button>
+        <el-button type="danger"
+                   size="small"
+                   plain
+                   @click="handleClearAll">
+          娓呴櫎
+        </el-button>
+      </div>
     </div>
     <div class="notification-content">
       <el-tabs v-model="activeTab"
@@ -91,10 +99,11 @@
     listMessage,
     markAsRead,
     markAllAsRead,
+    clearAllMessage,
     confirmMessage,
     getUnreadCount,
   } from "@/api/system/message";
-  import { ElMessage } from "element-plus";
+  import { ElMessage, ElMessageBox } from "element-plus";
   import useUserStore from "@/store/modules/user";
   import { useRouter } from "vue-router";
 
@@ -221,6 +230,35 @@
     }
   };
 
+  // 娓呴櫎鍏ㄩ儴娑堟伅
+  const handleClearAll = async () => {
+    try {
+      await ElMessageBox.confirm("纭娓呴櫎鍏ㄩ儴娑堟伅鍚楋紵娓呴櫎鍚庢棤娉曟仮澶嶃��", "鎻愮ず", {
+        confirmButtonText: "纭畾",
+        cancelButtonText: "鍙栨秷",
+        type: "warning",
+      });
+    } catch (error) {
+      // 鍙栨秷娓呴櫎
+      return;
+    }
+    try {
+      const res = await clearAllMessage();
+      if (res.code === 200) {
+        ElMessage.success("娓呴櫎鎴愬姛");
+        unreadList.value = [];
+        readList.value = [];
+        total.value = 0;
+        pageNum.value = 1;
+        loadMessages();
+        loadUnreadCount();
+      }
+    } catch (error) {
+      console.error("娓呴櫎娑堟伅澶辫触:", error);
+      ElMessage.error("娓呴櫎澶辫触");
+    }
+  };
+
   // 鍒嗛〉澶у皬鏀瑰彉
   const handleSizeChange = size => {
     pageSize.value = size;
@@ -272,6 +310,11 @@
       font-weight: 500;
       color: var(--text-primary);
     }
+
+    .popover-actions {
+      display: flex;
+      align-items: center;
+    }
   }
 
   .notification-content {

--
Gitblit v1.9.3