From 19c671de8bf03b4d19e30d134821aae8e99894e8 Mon Sep 17 00:00:00 2001 From: junleea <354425203@qq.com> Date: Tue, 13 Aug 2024 11:46:05 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=8E=B7=E5=8F=96=E5=8E=86?= =?UTF-8?q?=E5=8F=B2=E6=B6=88=E6=81=AF=EF=BC=8C=E6=B7=BB=E5=8A=A0=E6=B6=88?= =?UTF-8?q?=E6=81=AF=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/Chat.vue | 71 +++++++++++++++++++++++++++++++------- src/views/DeviceRealVP.vue | 7 ++-- 2 files changed, 64 insertions(+), 14 deletions(-) diff --git a/src/views/Chat.vue b/src/views/Chat.vue index 98aa176..19c147e 100644 --- a/src/views/Chat.vue +++ b/src/views/Chat.vue @@ -18,7 +18,9 @@ {{ user.name }} + + @@ -44,6 +46,12 @@
+ 历史消息 data[j].CreatedAt) { - let temp = data[i]; - data[i] = data[j]; - data[j] = temp; - } - } - } + // for (let i = 0; i < data.length; i++) { + // for (let j = i + 1; j < data.length; j++) { + // if (data[i].CreatedAt > data[j].CreatedAt) { + // let temp = data[i]; + // data[i] = data[j]; + // data[j] = temp; + // } + // } + // } + data.sort((a, b) => { + const dateA = new Date(a.CreatedAt); + const dateB = new Date(b.CreatedAt); + + // 返回时间差,用于排序 + return dateA - dateB; + }); this.MsgList=data; - this.scrollToBottom(); + if(this.history_cnt <=2){ + this.scrollToBottom(); + } }, formatTime(time){ let date = new Date(time); @@ -276,7 +306,14 @@ export default { if (data.type == "msg") { // 如果是消息类型,解密消息内容 // console.log("收到数据====" + JSON.stringify(msg.data)); console.log("msg_:", data.data); - _this.MsgList.push(JSON.parse(data.data)); + let msg_data=JSON.parse(data.data) + _this.MsgList.push(msg_data); + if(_this.cur_user_id != msg_data.FromUserID){ + _this.hasUnreadMsg[msg_data.FromUserID] = true; + }else{ + _this.scrollToBottom(); + } + //console.log("msglist:", _this.MsgList); // 构建消息内容 }else if (data.type == "check") { @@ -479,4 +516,14 @@ export default { margin-top: 20px; color: white; } +.unread-dot { + position: absolute; + top: 0; + right: 0; + width: 8px; + height: 8px; + background-color: red; + border-radius: 50%; + transform: translate(50%, -50%); +} \ No newline at end of file diff --git a/src/views/DeviceRealVP.vue b/src/views/DeviceRealVP.vue index 51af3fc..afce332 100644 --- a/src/views/DeviceRealVP.vue +++ b/src/views/DeviceRealVP.vue @@ -13,6 +13,7 @@