diff --git a/src/views/newMap/chatView/chatBox.vue b/src/views/newMap/chatView/chatBox.vue index 2ebc567cb..d0f1a3948 100644 --- a/src/views/newMap/chatView/chatBox.vue +++ b/src/views/newMap/chatView/chatBox.vue @@ -247,7 +247,6 @@ export default { const that = this; this.recorders.stopRecording(function(blobURL) { const data = URL.createObjectURL(that.recorders.getBlob()); - console.log('--------', data); clearInterval(that.inter); that.seconds = 0; const blob = that.recorders.getBlob(); @@ -307,6 +306,9 @@ export default { }, inviteMember() { this.$refs.chatToolTip.doShow(); + }, + addAudioList(data) { + this.$refs.chatContent.addAudioList(data); } } }; diff --git a/src/views/newMap/chatView/chatContent.vue b/src/views/newMap/chatView/chatContent.vue index 3938b7cb7..df9b5d61e 100644 --- a/src/views/newMap/chatView/chatContent.vue +++ b/src/views/newMap/chatView/chatContent.vue @@ -30,12 +30,20 @@ export default { }, data() { return { - // currentAudioList:[], - // currentAudioIndex:0, - // isPlay:false, + currentAudioList:[], + currentAudioIndex:0, + isPlay:false, + isAutoPlay: false, baseUrl:process.env.VUE_APP_VOICE_API + 'audio/' }; }, + watch: { + 'currentAudioList': function(val) { + if (val.length > 0 && !this.isPlay && !this.isAutoPlay) { + this.playEachAudio(val[0].src); + } + } + }, mounted() { // this.coversition = this.currentCoversition; // this.inintData(); @@ -47,50 +55,36 @@ export default { document.querySelector('.chatcontentIn').scrollTop = scrollTop; }); }, - // playEachAudio(audioUrl) { - // this.$nextTick(function() { - // document.querySelector('#audioPlay').src = audioUrl; - // document.querySelector('#audioPlay').play(); - // const that = this; - // document.querySelector('#audioPlay').onended = function() { - // that.currentAudioList.shift(); - // console.log(that.currentAudioList.length); - // if (that.currentAudioList.length > 0) { - // that.playEachAudio(that.currentAudioList[that.currentAudioIndex]); - // } else { - // that.isPlay = false; - // } - // }; - // }); - // }, - // covertName(data, status) { - // if (status) { - // let result = ''; - // const members = data.members || this.conversitionMemberList; - // (members || []).forEach(member => { - // if (member.memberId != data.memberId) { - // result += ('@' + this.covertEachName(member.memberId)); - // } - // }); - // return result; - // } else { - // return this.covertEachName(data.memberId); - // } - // }, - // covertEachName(memberId) { - // let name = ''; - // const member = this.$store.state.training.memberData[memberId]; - // if (member && member.userId) { - // const user = this.simulationUsers[member.userId]; - // name = member.label + '(' + user.nickName + ')'; - // } else if (member) { - // name = member.label; - // } - // return name; - // }, + + playEachAudio(audioUrl) { + this.$nextTick(function() { + this.isAutoPlay = true; + document.querySelector('#audioPlay').src = this.baseUrl + audioUrl; + document.querySelector('#audioPlay').play(); + const that = this; + document.querySelector('#audioPlay').onended = function() { + that.currentAudioList.shift(); + if (that.currentAudioList.length > 0) { + that.playEachAudio(that.currentAudioList[0].src); + } else { + that.isAutoPlay = false; + } + }; + }); + }, playAudio(audioUrl) { + this.isPlay = true; document.querySelector('#audioPlay').src = audioUrl; document.querySelector('#audioPlay').play(); + const that = this; + document.querySelector('#audioPlay').onended = function() { + that.isPlay = false; + that.isAutoPlay = false; + }; + }, + addAudioList(converstion) { + this.currentAudioList.push(converstion); + this.scrollTop(); } // conversationChange() { // this.currentAudioList = []; diff --git a/src/views/newMap/displayNew/demonChat.vue b/src/views/newMap/displayNew/demonChat.vue index fb696e4c8..0ff21f0fa 100644 --- a/src/views/newMap/displayNew/demonChat.vue +++ b/src/views/newMap/displayNew/demonChat.vue @@ -108,9 +108,12 @@ export default { // 创建会话 '$store.state.socket.createConversition':function(val) { if (this.memberData.length > 0) { - const member = this.memberData.find(member=>{ return member.id == val.creatorId; }); - if (member && member.userId == this.$store.state.user.id) { + const conversitionMember = this.memberData.find(member=>{ return member.userId == this.$store.state.user.id; }); + if (conversitionMember && val.memberIds.includes(conversitionMember.id)) { // 当前用户创建的会话 + if (val.creatorId !== conversitionMember.id) { + this.$message.success(this.coverName(val) + '与你开启会话'); + } this.isHasCoversition = true; this.isStartRecord = true; this.isQuitShow = true; @@ -118,6 +121,7 @@ export default { const memberList = []; val.memberIds.forEach(id=>{ if (val.creatorId == id) { + const member = this.memberData.find(member=>{ return member.id == id; }); member.connect = true; memberList.push(member); } else { @@ -177,7 +181,11 @@ export default { '$store.state.socket.conversationInfo':function (val, old) { // 仿真聊天 const simulationText = this.$store.state.socket.conversationInfo; if (val.messageType == 'MESSAGE' && (this.conversitionId == val.id || this.userRole == 'AUDIENCE')) { - this.chatContentList.push(this.addContent(simulationText.message)); + const content = this.addContent(simulationText.message); + this.chatContentList.push(content); + if (!content.self) { + this.$refs.chatbox.addAudioList(content); + } } }, // 按计划行车的列车列表更新(更新司机列表) @@ -217,23 +225,23 @@ export default { }, // 邀请会话的消息 '$store.state.socket.inviteSimulationConversition':function(val) { - const member = this.memberData.find(member=>{ return member.id == val.creatorId; }); - if (member) { - this.inviteUserName = member.label; - this.conversitionId = val.id; - member.connect = true; - member.online = true; - this.inviteUser = member; - - this.currentMemberList.push(member); - const member = this.memberData.find(member=>{ return member.id == val.memberId; }); - member.connect = true; - this.currentMemberList.push(member); - this.isStartRecord = true; - - // this.$refs.chatbox.inviteMember(); - this.$message.success(this.inviteUserName + '与你开启会话'); - } + // const conversitionMember = this.memberData.find(member=>{ return member.id == val.creatorId; }); + // if (conversitionMember) { + // this.inviteUserName = conversitionMember.label; + // this.conversitionId = val.id; + // conversitionMember.connect = true; + // conversitionMember.online = true; + // this.inviteUser = conversitionMember; + // + // this.currentMemberList.push(conversitionMember); + // const member = this.memberData.find(member=>{ return member.id == val.memberId; }); + // member.connect = true; + // this.currentMemberList.push(member); + // this.isStartRecord = true; + // this.isHasCoversition = true; + // // this.$refs.chatbox.inviteMember(); + // this.$message.success(this.inviteUserName + '与你开启会话'); + // } } }, @@ -254,6 +262,10 @@ export default { } return text; }, + coverName(inviteUser) { + const member = this.memberData.find(member=>{ return member.id == inviteUser.creatorId; }); + return member.label; + }, clearAllData() { this.resetCoversition(); this.createCoversition = true; diff --git a/src/views/newMap/jointTrainingNew/chatView/chatBox.vue b/src/views/newMap/jointTrainingNew/chatView/chatBox.vue index 420ec5fad..f112dd848 100644 --- a/src/views/newMap/jointTrainingNew/chatView/chatBox.vue +++ b/src/views/newMap/jointTrainingNew/chatView/chatBox.vue @@ -92,7 +92,7 @@