Browse Source

未读消息取消轮询

zhengnaiwen_citu 4 months ago
parent
commit
f2e29fbafb
2 changed files with 22 additions and 21 deletions
  1. 5 0
      src/api/message.js
  2. 17 21
      src/layout/components/LayoutNotification.vue

+ 5 - 0
src/api/message.js

@@ -30,3 +30,8 @@ export function getMessage (data) {
 export function sendMessage (data) {
   return http.post('/authentication/message/website/send', data)
 }
+
+// 获取未读数量
+export function sendUnreadCount () {
+  return http.post('/authentication/message/website/unread/count')
+}

+ 17 - 21
src/layout/components/LayoutNotification.vue

@@ -72,7 +72,8 @@ import {
   setMessageRead,
   deleteMessage,
   deleteMessageRead,
-  setMessageAllRead
+  setMessageAllRead,
+  sendUnreadCount
 } from '@/api/message'
 import { mapGetters } from 'vuex'
 export default {
@@ -94,7 +95,7 @@ export default {
       },
       loading: false,
       items: [],
-      timer: null,
+      // timer: null,
       readState: null,
       unreadTotal: 0
     }
@@ -104,18 +105,18 @@ export default {
   },
   created () {
     this.getUnread()
-    if (this.timer) {
-      clearInterval(this.timer)
-    }
-    this.timer = setInterval(() => {
-      this.getUnread()
-    }, 3000)
-  },
-  beforeDestroy () {
-    if (this.timer) {
-      clearInterval(this.timer)
-    }
+    // if (this.timer) {
+    //   clearInterval(this.timer)
+    // }
+    // this.timer = setInterval(() => {
+    //   this.getUnread()
+    // }, 3000)
   },
+  // beforeDestroy () {
+  //   if (this.timer) {
+  //     clearInterval(this.timer)
+  //   }
+  // },
   methods: {
     onCommand (index) {
       this.menuActive = index
@@ -137,17 +138,12 @@ export default {
     },
     async getUnread () {
       try {
-        const { data } = await getMessage({
-          userId: this.userInfo.id,
-          readState: 0,
-          page: {
-            size: 1,
-            current: 1
-          }
-        })
+        const { data } = await sendUnreadCount()
         this.unreadTotal = data.total
       } catch (error) {
         this.$message.error(error)
+      } finally {
+        this.getUnread()
       }
     },
     async onInit () {