liuhj 1 year ago
parent
commit
c28f08eba5
1 changed files with 20 additions and 8 deletions
  1. 20 8
      src/components/home.vue

+ 20 - 8
src/components/home.vue

@@ -562,7 +562,7 @@ export default {
             that.$message.error(res.data.msg);
           }
       }).catch(function (error) {
-          that.$message.error("获取消息类型失败!");
+          that.$message.error(error);
       });
     },
     //未读条数
@@ -593,7 +593,7 @@ export default {
                 that.$message.error(res.data.msg);
             }
         }).catch(function (error) {
-            that.$message.error("获取未读条数!");
+            that.$message.error(error);
         });
     },
     //消息确认已读
@@ -708,8 +708,10 @@ export default {
           done();
         })
         .catch(_ => {});
+    },
+    setIntervaltime(){
+
     }
-    
     //实时通讯
     // async startConnection() {
     //   this.connection = new signalR.HubConnectionBuilder()
@@ -738,23 +740,33 @@ export default {
     // },
   },
   mounted() {
-    this.userId=JSON.parse(localStorage.getItem('userinif')).userInfo.userId;
-    this.token=JSON.parse(localStorage.getItem('userinif')).token;
+    
     // this.unReadCount=JSON.parse(localStorage.getItem('unReadCount'));
     this.removal();
     this.radioChange(false);
     this.ifIndexValue();
     this.getmenu();
-    this.PotsMessageUnreadTotalCount();
+    
     this.PotsMsgTypeData();
+
+    let timer = setInterval(() => {
+      this.PotsMessageUnreadTotalCount();
+    }, 10000)
+    this.$once('hook:beforeDestroy', () => {
+      clearInterval(timer)
+      timer = null
+    })
     // setTimeout(this.PotsMessagePageList(),500)
-    
-    setInterval(this.PotsMessageUnreadTotalCount, 10000);
+    // this.setIntervaltime();
+    // setInterval(this.PotsMessageUnreadTotalCount, 10000);
     // setInterval(this.PsotMsgPageList, 3000);
     // this.chatHub();
   },
   created() {
+    this.userId=JSON.parse(localStorage.getItem('userinif')).userInfo.userId;
+    this.token=JSON.parse(localStorage.getItem('userinif')).token;
     this.userinif = JSON.parse(localStorage.getItem('userinif'));
+    this.PotsMessageUnreadTotalCount();
     
     // this.startConnection();
   },