From f89803cf9b18909e91f3ae567daebf1d8d3a3ee8 Mon Sep 17 00:00:00 2001 From: luyuan <1162963624@qq.com> Date: Mon, 10 Aug 2020 10:41:20 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B6=88=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- static/imservice.js | 86 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) diff --git a/static/imservice.js b/static/imservice.js index 1616e8e..11a2705 100644 --- a/static/imservice.js +++ b/static/imservice.js @@ -386,7 +386,85 @@ IMService.prototype.initialIMListeners = function () { // }) }; +IMService.prototype.sendMessagesSetStorage = function (friendId,message){ + let friend = this.friends[friendId]; + console.log(friend) + // return ; + let sorts = function (friends){ + let paixu = function (a,b){ + if(a.date > b.date){ + return 0; + }else{ + return 1; + } + } + friends.sort(paixu) + + } + + let that = this + if(!friend && friend == undefined){ + const token = uni.getStorageSync('token'); + console.log(token) + uni.request({ + url:"https://dmmall.sdbairui.com/api/Specialci/getAtwillUserInfo", + data:{ + userId:friendId + }, + method:"POST", + header:{ + "Authorization" : 'Bearer' + " " + token + }, + success(res){ + console.log(res) + that.friends[friendId] = new Friend(res.data.data.member_id, res.data.data.member_nickname, res.data.data.member_avatar); + friend = that.friends[friendId]; + console.log(friend) + friend.text = message + let time = new Date() + friend.date = time.getTime() + friend.time = time.getHours() + ":" + time.getMinutes() + ":" + time.getSeconds() + console.log(that.friends) + that.friendsarr = [] + for(let i in that.friends){ + console.log(i) + that.friendsarr.push(that.friends[i]) + } + sorts(that.friendsarr) + let arr = [] + for(let i in that.friends){ + arr.push([that.friends[i].uuid,that.friends[i].time,that.friends[i].text,that.friends[i].date,0]) + } + console.log(arr) + uni.setStorageSync('imlist',JSON.stringify(arr)) + + that.onFriendListChange(that.friends); + + } + }) + }else{ + console.log(friend) + friend.text = message + let time = new Date() + friend.date = time.getTime() + friend.time = time.getHours() + ":" + time.getMinutes() + ":" + time.getSeconds() + console.log(this.friends) + that.friendsarr = [] + for(let i in this.friends){ + that.friendsarr.push(this.friends[i]) + } + sorts(that.friendsarr) + let arr = [] + for(let i in that.friends){ + arr.push([that.friends[i].uuid,that.friends[i].time,that.friends[i].text,that.friends[i].date,0]) + } + console.log(arr) + uni.setStorageSync('imlist',JSON.stringify(arr)) + this.onFriendListChange(this.friends); + + } +} //订阅群消息 IMService.prototype.subscribeGroupMessage = function (id) { this.im.subscribeGroup([id]) @@ -462,6 +540,8 @@ IMService.prototype.sendPrivateTextMessage = function (friendId, text) { text: text }); this.sendPrivateMessage(friendId, textMessage); + this.sendMessagesSetStorage(friendId, text) + }; //私聊图片消息 @@ -473,6 +553,8 @@ IMService.prototype.sendPrivateImageMessage = function (friendId, imageFile) { } }); this.sendPrivateMessage(friendId, imageMessage); + this.sendMessagesSetStorage(friendId, '其他消息') + }; //私聊视频消息 @@ -484,6 +566,8 @@ IMService.prototype.sendPrivateVideoMessage = function (friendId, videoFile) { } }); this.sendPrivateMessage(friendId, videoMessage); + this.sendMessagesSetStorage(friendId, '其他消息') + }; IMService.prototype.sendPrivateAudioMessage = function (friendId, audiofile) { @@ -495,6 +579,8 @@ IMService.prototype.sendPrivateAudioMessage = function (friendId, audiofile) { }); this.sendPrivateMessage(friendId, audioMessage); + this.sendMessagesSetStorage(friendId, '其他消息') + }; //发送私聊消息