From 4e02daa8545fd632422171a778321e65c5ed1d3d Mon Sep 17 00:00:00 2001 From: luyuan <1162963624@qq.com> Date: Thu, 27 Aug 2020 09:52:43 +0800 Subject: [PATCH] =?UTF-8?q?t=E6=B7=BB=E5=8A=A0=E4=BA=86=E6=8F=90=E7=A4=BA?= =?UTF-8?q?=E5=92=8C=E7=9B=B4=E6=92=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/messages/privateChat.vue | 2 ++ pages/release/zhibo.nvue | 27 +++++++++++++++++++++++++++ static/imservice.js | 19 ++++++++++++++++++- 3 files changed, 47 insertions(+), 1 deletion(-) diff --git a/pages/messages/privateChat.vue b/pages/messages/privateChat.vue index b5a6a75..9d35ee6 100644 --- a/pages/messages/privateChat.vue +++ b/pages/messages/privateChat.vue @@ -126,6 +126,7 @@ this.friend = JSON.parse(options.id); this.currentUser = this.imService.currentUser; let privateMessages = this.imService.getPrivateMessages(this.friend.uuid); + this.imService.uid = this.friend.uuid; this.messages = privateMessages.sentMessages; this.pendingMessages = privateMessages.pendingMessages; @@ -151,6 +152,7 @@ this.imService.onPrivateHistoryLoad = (friendId, messages) =>{}; //将未读消息数清零 this.imService.resetFriendUnReadMessage(this.friend); + this.imService.uid = 0; }, methods: { initialListeners () { diff --git a/pages/release/zhibo.nvue b/pages/release/zhibo.nvue index 0e44a85..5218c15 100644 --- a/pages/release/zhibo.nvue +++ b/pages/release/zhibo.nvue @@ -476,6 +476,7 @@ //构造chatRoomService that.chatRoomService.subscribeRoomMessage(room,currentUser) that.chatRoomService.initialWhenNewMessage(that.whenNewMessage); + that.chatRoomService.warrings = that.jinggao //获取当前聊天室数据 that.room = that.chatRoomService.room; that.chatRoomService.initialWhenOnlineUserChange(that.renqu) @@ -560,6 +561,32 @@ }, methods: { + jinggao(text){ + console.log(text) + if(text.message_type == 1){ + uni.showModal({ + title: '警告', + content: text.content, + showCancel:false, + success: function (res) { + + } + }); + }else if(text.message_type == 2){ + uni.showModal({ + title: '警告', + content: text.content, + showCancel:false, + success: function (res) { + uni.navigateBack({ + delta: 1 + }); + } + }); + this.stop() + + } + }, renqu(res){ if(res.users.length > this.renqu){ this.renqu = res.users.length diff --git a/static/imservice.js b/static/imservice.js index 297a33d..75d78b2 100644 --- a/static/imservice.js +++ b/static/imservice.js @@ -50,7 +50,7 @@ function IMService() { //群聊消息记录,map格式,每个群对应一个数组 this.groupMessages = {}; - + this.uid = 0; /* * 监听器们 * @@ -77,6 +77,10 @@ function IMService() { this.whenOnlineUserChange = function () { }; + this.warrings = function() { + + }; + } //登录 @@ -258,6 +262,11 @@ IMService.prototype.initialIMListeners = function () { //监听私聊消息 this.im.on(GoEasyIM.EVENT.PRIVATE_MESSAGE_RECEIVED, (message) => { console.log(message) + if(message.senderId == 0){ + console.log(message.payload.text) + this.warrings(JSON.parse(message.payload.text)) + return; + } //如果不是自己发的,朋友未读消息数 +1 if (message.senderId != this.currentUser.uuid) { let friend = this.friends[message.senderId]; @@ -275,6 +284,14 @@ IMService.prototype.initialIMListeners = function () { friends.sort(paixu) } + if(message.senderId != this.uid){ + const innerAudioContext = uni.createInnerAudioContext(); + innerAudioContext.autoplay = true; + innerAudioContext.src = 'https://img-cdn-qiniu.dcloud.net.cn/uniapp/audio/music.mp3'; + innerAudioContext.onPlay(() => { + console.log('开始播放'); + }); + } let that = this if(!friend && friend == undefined){