wansfa 1 سال پیش
والد
کامیت
6812803028
2فایلهای تغییر یافته به همراه54 افزوده شده و 69 حذف شده
  1. 37 41
      src/components/LemonUI/components/index.vue
  2. 17 28
      src/views/qw/qwChat/qq.vue

+ 37 - 41
src/components/LemonUI/components/index.vue

@@ -186,38 +186,37 @@ export default {
      * 新增一条消息
      */
     appendMessage(message, scrollToBottom = false) {
-      let unread = "+1";
-      let messageList = allMessages[message.toContactId];
-      // 如果是自己的消息需要push,发送的消息不再增加未读条数
-      let conversation=this.findConversation(message.toContactId);
-      unread=!!conversation.unread?(conversation.unread+1):1;
-      if (message.type == 'event' || this.user.id == message.fromUser.id) unread = "+0";
-      if (messageList === undefined) {
-        this.updateContact({
-          id: message.toContactId,
-          unread: unread,
-          lastSendTime: message.sendTime,
-          lastContent: this.lastContentRender(message),
-        });
+        let messageList = allMessages[message.toContactId];
+        // 如果是自己的消息需要push,发送的消息不再增加未读条数
+        let conversation=this.findConversation(message.toContactId);
+        let unread=!!conversation.unread && conversation.unread>0?(conversation.unread+1):1;
+        if (message.type == 'event' || this.user.id == message.fromUser.id) unread = "+0";
+        if (messageList === undefined) {
+          this.updateContact({
+            id: message.toContactId,
+            unread: unread,
+            lastSendTime: message.sendTime,
+            lastContent: this.lastContentRender(message),
+          });
       } else {
-        // 如果消息存在则不再添加
-        let hasMsg = messageList.some(({id})=>id == message.id);
-        if (hasMsg) return;
-        this._addMessage(message, message.toContactId, 1);
-        const updateContact = {
-          id: message.toContactId,
-          lastContent: this.lastContentRender(message),
-          lastSendTime: message.sendTime,
-        };
-        if (message.toContactId == this.currentContactId) {
-          if (scrollToBottom == true) {
-            this.messageViewToBottom();
+          // 如果消息存在则不再添加
+          let hasMsg = messageList.some(({id})=>id == message.id);
+          if (hasMsg) return;
+          this._addMessage(message, message.toContactId, 1);
+          
+          conversation.lastContent=this.lastContentRender(message);
+          conversation.lastSendTime=message.sendTime;
+          if (message.toContactId == this.currentContactId) {
+            
+            conversation.unread=0;
+            if (scrollToBottom == true) {
+              this.messageViewToBottom();
+            }
+            this.CacheDraft.remove(message.toContactId);
+          } else {
+            conversation.unread = unread;
           }
-           this.CacheDraft.remove(message.toContactId);
-        } else {
-           updateContact.unread = unread;
-        }
-        this.updateContact(updateContact);
+          this.updateContact(conversation);
       }
     },
     _emitSend(message, next, file) {
@@ -305,7 +304,6 @@ export default {
           this.CacheMessageLoaded.set(this.currentContactId, isEnd);
           if (isEnd == true) this.$refs.messages.loaded();
           this.updateCurrentMessages();
-          console.log("qxj _emitPullMessages");
           this._changeContactLock = false;
           next(isEnd);
         },
@@ -694,7 +692,7 @@ export default {
       });
       
       var tempDraft=this.CacheDraft.get(cid);
-        console.log("qxj editorValue:"+editorValue+",tempDraft:"+JSON.stringify(tempDraft)+"lastContent:"+lastContent);
+      //console.log("qxj editorValue:"+editorValue+",tempDraft:"+JSON.stringify(tempDraft)+"lastContent:"+lastContent);
 
       this.updateContact({
         id: cid,
@@ -1016,16 +1014,14 @@ export default {
      * @param {Contact} data 修改的数据,根据 Contact.id 查找联系人并覆盖传入的值
      */
     updateContact(data) {
-      const contactId = data.id;
-      delete data.id;
-      const index = this.findConversationIndexById(contactId);  
+      const conversationId = data.conversationId;
+      const index = this.findConversationIndexById(conversationId);  
       if (index !== -1) {
-        const { unread } = data;
-        if (isString(unread)) {
-          if (unread.indexOf("+") === 0 || unread.indexOf("-") === 0) {
-            data.unread =parseInt(unread) + parseInt(this.conversations[index].unread);
-          }
-        }
+        // if(isString(data.unread)) {
+        //     if (unread.indexOf("+") === 0 || unread.indexOf("-") === 0) {
+        //       data.unread =parseInt(unread) + parseInt(this.conversations[index].unread);
+        //     }
+        // }
         this.$set(this.conversations, index, {
           ...this.conversations[index],
           ...data,

+ 17 - 28
src/views/qw/qwChat/qq.vue

@@ -325,7 +325,6 @@ export default {
         }, 2000);
         return;
     }
-    // console.log("qxj qwUserId:"+JSON.stringify(this.qwUser));
     this.isFromLogin=this.$route.query.isFromLogin;
     console.log("qxj isFromLogin:"+this.isFromLogin);
     if(!this.qwIm.hasLogin){
@@ -376,14 +375,6 @@ export default {
     conversationData.sort((a1, a2) => {
       return a2.lastSendTime - a1.lastSendTime;
     });
-
-  
-    // IMUI.initContacts(ContactsData);
-    // IMUI.initConversations(conversationData);
-    // setTimeout(() => {
-    //     IMUI.changeContact(1688856679458971);
-    // }, 500);
-
     this.getContacts();  //获取联系人信息
     this.getConversation();   //获取会话信息
   
@@ -441,7 +432,6 @@ export default {
         isBottom: true,
       },
     ]);
-
     IMUI.initEmoji(EmojiData); 
   
   },
@@ -490,20 +480,22 @@ export default {
                                    });
                              }else{
                                   that.appendMessageAction(msgData);
-                                  let queryParams={conversationId:msgData.toContactId,userId:that.qwUser.userId};
-                                  getConversation(queryParams).then(response => {
-                                          if(response.code==200){
-                                              var conversation=response.data;
-                                              var unread=conversation.unread;
-                                              if(!unread){
-                                                 conversation.unread=1;
-                                              }else{
-                                                conversation.unread+=1;
-                                              }
-                                              IMUI.topPopConversations(conversation);
+                                  let conversation=IMUI.findConversation(msgData.toContactId);
+                                  IMUI.topPopConversations(conversation);
+                                  // let queryParams={conversationId:msgData.toContactId,userId:that.qwUser.userId};
+                                  // getConversation(queryParams).then(response => {
+                                  //         if(response.code==200){
+                                  //             var conversation=response.data;
+                                  //             var unread=conversation.unread;
+                                  //             if(!unread){
+                                  //                conversation.unread=1;
+                                  //             }else{
+                                  //               conversation.unread+=1;
+                                  //             }
+                                  //             IMUI.topPopConversations(conversation);
 
-                                          }
-                                   });
+                                  //         }
+                                  //  });
                              }
                         }
                   };
@@ -520,7 +512,6 @@ export default {
              this.roomInfo=response.detail;
         });
     },
-  
     getContacts(){  
       getContactsByUser(this.qwUser.userId).then(response => {
            this.contactData = response.data;
@@ -546,7 +537,6 @@ export default {
       });
     },
     messageTimeFormat(time) {
-      //console.log("qxj messageTimeFormat:"+time);
       return this.friendlyDate(time);
     },
     changeTheme() {
@@ -603,7 +593,7 @@ export default {
        this.queryParams.pageNum=pages[conversation.conversationId];
        this.queryParams.conversationId=conversation.conversationId;
        if(conversation.unread>0){
-          conversation.unread==0;
+          conversation.unread=0;
           instance.updateContact(conversation);
        }
        instance.closeDrawer();
@@ -659,7 +649,6 @@ export default {
     handleSend(message, next, file) {
       const IMUI = this.$refs.IMUI;
       var params={};
-      console.log("qxj message:"+JSON.stringify(message));
       if(message.type=="text"){  //text   image   voice   video
           params={"conversationId":message.toContactId,"deviceId":this.qwUser.deviceId,"userId":this.qwUser.userId,"content":message.content};
           sendTextMsg(params).then(response => {
@@ -712,7 +701,7 @@ export default {
     },
     handleMessageClick(e, key, message, instance) {
       console.log("点击了消息", e, key, message);
-      console.log("qxj message:"+JSON.stringify(message));
+      //console.log("qxj message:"+JSON.stringify(message));
       if(message.type=="image"){
            var url=!!message.url?message.url:message.content;
            this.handlePicturePreview(url);