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..59969db 100644 --- a/static/imservice.js +++ b/static/imservice.js @@ -7,6 +7,7 @@ import GoEasyIM from './goeasy-im-1.0.9'; import restApi from './restapi'; +import music from './music.mp3' function Friend(uuid, name, avatar,time = "", text = "",date = "",unReadMessage = 0) { this.uuid = uuid; @@ -50,7 +51,7 @@ function IMService() { //群聊消息记录,map格式,每个群对应一个数组 this.groupMessages = {}; - + this.uid = 0; /* * 监听器们 * @@ -77,6 +78,10 @@ function IMService() { this.whenOnlineUserChange = function () { }; + this.warrings = function() { + + }; + } //登录 @@ -258,6 +263,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 +285,14 @@ IMService.prototype.initialIMListeners = function () { friends.sort(paixu) } + if(message.senderId != this.uid){ + const innerAudioContext = uni.createInnerAudioContext(); + innerAudioContext.autoplay = true; + innerAudioContext.src = music; + innerAudioContext.onPlay(() => { + console.log('开始播放'); + }); + } let that = this if(!friend && friend == undefined){ diff --git a/static/music.mp3 b/static/music.mp3 new file mode 100644 index 0000000..61c030b Binary files /dev/null and b/static/music.mp3 differ