Parcourir la source

解决无法删除数据

ys il y a 2 semaines
Parent
commit
f1c7a18615

+ 2 - 8
yushu-uivue3/src/layout/components/Navbar.vue

@@ -419,22 +419,19 @@ onMounted(() => {
   fetchNotificationList()
   fetchMessageList()
   
-  console.log('[Navbar] 初始化 WebSocket 监听器...')
-  
   // 先注册所有监听器,再连接(确保不会错过消息)
   
   // 监听连接状态
   wsService.on('connected', () => {
-    console.log('[Navbar] WebSocket 已连接')
+    // WebSocket 已连接
   })
   
   wsService.on('disconnected', () => {
-    console.log('[Navbar] WebSocket 已断开')
+    // WebSocket 已断开
   })
   
   // 监听新消息(私聊)- 弹窗提示并可跳转
   wsService.on('new_message', (payload) => {
-    console.log('[Navbar] 收到新消息:', payload)
     // 刷新消息列表
     fetchMessageList()
     
@@ -462,7 +459,6 @@ onMounted(() => {
   
   // 监听新通知(系统通知)- 弹窗提示
   wsService.on('new_notification', (payload) => {
-    console.log('[Navbar] 收到通知:', payload)
     // 刷新通知列表
     fetchNotificationList()
     
@@ -488,12 +484,10 @@ onMounted(() => {
   
   // 监听待办更新
   wsService.on('todo_update', (payload) => {
-    console.log('[Navbar] 待办更新:', payload)
     fetchTodoList()
   })
   
   // 最后建立 WebSocket 连接
-  console.log('[Navbar] 建立 WebSocket 连接...')
   wsService.connect()
 })
 

+ 0 - 11
yushu-uivue3/src/utils/websocket.js

@@ -21,7 +21,6 @@ class WebSocketService {
   connect() {
     const token = getToken()
     if (!token) {
-      console.warn('[WebSocket] 未登录,无法建立连接')
       return
     }
 
@@ -32,13 +31,10 @@ class WebSocketService {
     const wsHost = import.meta.env.DEV ? 'localhost:8080' : host
     const wsUrl = `${protocol}//${wsHost}/ws/message?token=${token}`
 
-    console.log('[WebSocket] 正在连接:', wsUrl)
-
     try {
       this.ws = new WebSocket(wsUrl)
 
       this.ws.onopen = () => {
-        console.log('[WebSocket] 连接成功')
         this.isConnected = true
         this.reconnectAttempts = 0
         this.startHeartbeat()
@@ -50,7 +46,6 @@ class WebSocketService {
       }
 
       this.ws.onclose = (event) => {
-        console.log('[WebSocket] 连接关闭:', event.code, event.reason)
         this.isConnected = false
         this.stopHeartbeat()
         this.emit('disconnected')
@@ -58,7 +53,6 @@ class WebSocketService {
         // 尝试重连
         if (this.reconnectAttempts < this.maxReconnectAttempts) {
           this.reconnectAttempts++
-          console.log(`[WebSocket] ${this.reconnectDelay / 1000}秒后尝试重连 (${this.reconnectAttempts}/${this.maxReconnectAttempts})`)
           setTimeout(() => this.connect(), this.reconnectDelay)
         }
       }
@@ -79,17 +73,13 @@ class WebSocketService {
     try {
       // 心跳响应
       if (data === 'pong') {
-        console.log('[WebSocket] 收到心跳响应')
         return
       }
 
-      console.log('[WebSocket] 收到原始数据:', data)
       const message = JSON.parse(data)
-      console.log('[WebSocket] 解析后消息:', message.type, message)
 
       switch (message.type) {
         case 'connection_ack':
-          console.log('[WebSocket] 连接已确认')
           break
 
         case 'unread_snapshot':
@@ -128,7 +118,6 @@ class WebSocketService {
    * 处理新通知
    */
   handleNewNotification(payload) {
-    console.log('[WebSocket] handleNewNotification 触发, listeners:', this.listeners.has('new_notification'), this.listeners.get('new_notification')?.size)
     // 只触发事件,弹窗由 Navbar.vue 统一处理
     this.emit('new_notification', payload)
   }

+ 24 - 10
yushu-uivue3/src/views/system/message/index.vue

@@ -81,7 +81,7 @@
       :columns="columns"
       :row-selection="{ selectedRowKeys: selectedRowKeys, onChange: handleSelectionChange }"
       :pagination="false"
-      rowKey="messageId"
+      rowKey="notificationId"
     >
       <template #bodyCell="{ column, record }">
         <template v-if="column.key === 'priority'">
@@ -199,6 +199,7 @@
 
 <script setup name="MessageManagement">
 import { SearchOutlined, ReloadOutlined, SendOutlined, DeleteOutlined, EyeOutlined } from '@ant-design/icons-vue'
+import { Modal } from 'ant-design-vue'
 import { listNotification, getNotification, delNotification } from "@/api/system/message"
 import SendMessageDialog from './components/SendMessageDialog.vue'
 
@@ -227,7 +228,7 @@ const sendDialogRef = ref(null)
 const queryFormRef = ref(null)
 
 const columns = [
-  { title: '消息ID', dataIndex: 'messageId', key: 'messageId', width: 80, align: 'center' },
+  { title: '消息ID', dataIndex: 'notificationId', key: 'notificationId', width: 80, align: 'center' },
   { title: '优先级', key: 'priority', width: 80, align: 'center' },
   { title: '消息标题', dataIndex: 'title', key: 'title', ellipsis: true, minWidth: 200 },
   { title: '发送者', key: 'senderName', width: 120, align: 'center' },
@@ -280,7 +281,7 @@ function handleSendSuccess() {
 /** 查看消息详情 */
 function handleView(row) {
   loading.value = true
-  getNotification(row.messageId).then(response => {
+  getNotification(row.notificationId).then(response => {
     form.value = response.data
     receiverList.value = response.data.receivers || []
     viewOpen.value = true
@@ -290,13 +291,26 @@ function handleView(row) {
 
 /** 删除按钮操作 */
 function handleDelete(row) {
-  const messageIds = row.messageId || ids.value
-  proxy.$modal.confirm('是否确认删除消息ID为"' + messageIds + '"的数据项?').then(() => {
-    return delNotification(messageIds)
-  }).then(() => {
-    getList()
-    proxy.$modal.msgSuccess("删除成功")
-  }).catch(() => {})
+  const notificationIds = row?.notificationId ? [row.notificationId] : ids.value
+  
+  if (!notificationIds || notificationIds.length === 0) {
+    proxy.$modal.msgError("请选择要删除的数据")
+    return
+  }
+  
+  const notificationIdStr = notificationIds.join(',')
+  Modal.confirm({
+    title: '系统提示',
+    content: '是否确认删除消息ID为"' + notificationIdStr + '"的数据项?',
+    okText: '确定',
+    cancelText: '取消',
+    onOk: () => {
+      return delNotification(notificationIdStr).then(() => {
+        getList()
+        proxy.$modal.msgSuccess("删除成功")
+      })
+    }
+  })
 }
 
 getList()