Parcourir la source

优化消息通知的菜单徽标更新逻辑

yusheng il y a 10 mois
Parent
commit
85aca3f602
1 fichiers modifiés avec 9 ajouts et 20 suppressions
  1. 9 20
      src/layout/components/header-notice.vue

+ 9 - 20
src/layout/components/header-notice.vue

@@ -202,22 +202,16 @@
         return this.noticeCount;
         return this.noticeCount;
       }
       }
     },
     },
+    watch: {
+      noticeCount() {
+        this.$store.dispatch('user/setMenuBadge', {
+          path: '/page-wt/message',
+          value: this.noticeCount,
+          color: 'danger'
+        });
+      }
+    },
     created() {
     created() {
-      // [1, 2].forEach((item) => {
-      //   setTimeout(()=>{
-      //     this.$notify({
-      //     title: '提示',
-      //     message: '消息消息',
-      //     position: 'bottom-right',
-      //     duration: 0,
-      //     onClose: (a) => {
-      //       console.log(item);
-      //     }
-      //   });
-      //   },500)
-
-      // });
-
       if (getToken()) {
       if (getToken()) {
         console.log(window);
         console.log(window);
         let url =
         let url =
@@ -228,11 +222,6 @@
         let socket = new WebSocket(url);
         let socket = new WebSocket(url);
         socket.onmessage = (event) => {
         socket.onmessage = (event) => {
           this.noticeCount = event.data * 1 || 0;
           this.noticeCount = event.data * 1 || 0;
-          this.$store.dispatch('user/setMenuBadge', {
-            path: '/page-wt/message',
-            value: this.noticeCount,
-            color: 'danger'
-          });
           if (this.noticeCount) {
           if (this.noticeCount) {
             getUnreadNotice().then((res) => {
             getUnreadNotice().then((res) => {
               this.visibleModal = false;
               this.visibleModal = false;