Jelajahi Sumber

fix: 优化通知消息时间显示格式及WebSocket数据处理逻辑

yusheng 7 bulan lalu
induk
melakukan
13d588a4a4
1 mengubah file dengan 15 tambahan dan 10 penghapusan
  1. 15 10
      src/layout/components/header-notice.vue

+ 15 - 10
src/layout/components/header-notice.vue

@@ -30,7 +30,7 @@
               "
             >
               <div class="ele-text-secondary ele-elip"
-                >{{ item.createTime }}
+                >{{ new Date(item.createTime).toLocaleString() }}
               </div>
               <div
                 class="el-icon-view"
@@ -145,7 +145,7 @@
                 "
               >
                 <div class="ele-text-secondary ele-elip"
-                  >{{ item.createTime }}
+                  >{{ new Date(item.createTime).toLocaleString() }}
                 </div>
                 <div class="el-icon-view" title="已读"></div>
               </div>
@@ -217,21 +217,22 @@
     },
     created() {
       if (getToken()) {
-        console.log(window);
         let url =
           'ws://' +
           window.location.host +
           '/ws/websocket/UnreadNotifyMessageCount?token=' +
           getToken();
+
         let socket = new WebSocket(url);
         socket.onmessage = (event) => {
-          this.noticeCount = event.data * 1 || 0;
-          if (this.noticeCount) {
-            getUnreadNotice().then((res) => {
-              this.visibleModal = false;
-              this.visibleModal = true;
-              this.notice = res.slice(0, 20);
-            });
+          if (event.data) {
+            let data = JSON.parse(event.data);
+            this.noticeCount = data.length || 0;
+            this.visibleModal = false;
+            this.visibleModal = true;
+            this.notice = data.slice(0, 20);
+          } else {
+            this.visibleModal = false;
           }
         };
       }
@@ -257,6 +258,10 @@
           await updateNotifyMessageReadByIdAPI([item.id]);
           this.notice.splice(index, 1);
           this.noticeCount = this.noticeCount ? this.noticeCount - 1 : 0;
+          if (!this.noticeCount) {
+            alert(1);
+            this.visibleModal = false;
+          }
         } else {
           await updateAllNotifyMessageReadAPI();
           this.notice = [];