2020-07-06 18:00:44 +08:00
|
|
|
<template>
|
|
|
|
<div class="chatcontentIn">
|
|
|
|
<div class="chatcontentInner">
|
|
|
|
<div v-for="(chatContent,index) in messageList" :key="index" class="chatContentInClass">
|
|
|
|
<div :class="chatContent.self?'rightUser':'leftUser'">
|
|
|
|
<div class="userHeader">
|
2020-07-07 10:54:57 +08:00
|
|
|
<div v-if="!chatContent.self" class="userName">{{ covertName(chatContent,false) }}</div>
|
|
|
|
<div :class="chatContent.self?'userChatTime textRight':'userChatTime'">{{ chatContent.time }}</div>
|
2020-07-06 18:00:44 +08:00
|
|
|
</div>
|
|
|
|
<div class="userBubble" @click="playAudio(baseUrl+chatContent.src)">
|
|
|
|
<div class="userMessage">
|
|
|
|
<span class="el-icon-video-play playicon" />
|
2020-07-07 10:54:57 +08:00
|
|
|
<span class="messageText">{{ chatContent.content }}</span>
|
2020-07-06 18:00:44 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<audio id="audioPlay" style="display:none" />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
<script>
|
|
|
|
|
|
|
|
export default {
|
|
|
|
props:{
|
|
|
|
messageList:{
|
|
|
|
type:Array,
|
|
|
|
required:true
|
|
|
|
},
|
|
|
|
isAnswering:{
|
|
|
|
type:Boolean,
|
|
|
|
required:true
|
|
|
|
},
|
|
|
|
conversitionId: {
|
|
|
|
type: String,
|
|
|
|
required: true
|
2020-07-07 10:54:57 +08:00
|
|
|
},
|
|
|
|
conversitionMemberList: {
|
|
|
|
type: Array,
|
|
|
|
required: true
|
|
|
|
},
|
|
|
|
simulationUsers: {
|
|
|
|
type: Object,
|
|
|
|
required: true
|
2020-07-17 19:07:34 +08:00
|
|
|
},
|
|
|
|
userRole: {
|
|
|
|
type: String,
|
|
|
|
required: true
|
2020-07-20 15:19:11 +08:00
|
|
|
},
|
|
|
|
commonConversation: {
|
|
|
|
type: Boolean,
|
|
|
|
required: true
|
2020-07-06 18:00:44 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
chatContentList:[],
|
|
|
|
coversition:{},
|
|
|
|
currentAudioList:[],
|
|
|
|
currentAudioIndex:0,
|
|
|
|
isPlay:false,
|
|
|
|
baseUrl:process.env.VUE_APP_VOICE_API
|
|
|
|
};
|
|
|
|
},
|
|
|
|
watch:{
|
2020-07-07 09:39:27 +08:00
|
|
|
'$store.state.socket.conversationInfo':function (val, old) { // 仿真聊天
|
|
|
|
const conversationInfo = this.$store.state.socket.conversationInfo;
|
2020-07-07 10:54:57 +08:00
|
|
|
const member = this.$store.state.training.memberData[val.message.memberId];
|
2020-07-07 13:15:20 +08:00
|
|
|
conversationInfo.message.src = `/audio/${conversationInfo.message.audioPath}`;
|
2020-07-07 10:54:57 +08:00
|
|
|
if (member) {
|
2020-07-07 13:15:20 +08:00
|
|
|
conversationInfo.message.self = this.$store.state.userId == member.userId;
|
2020-07-07 10:54:57 +08:00
|
|
|
}
|
2020-07-06 18:00:44 +08:00
|
|
|
if (this.conversitionId == val.id) {
|
2020-07-21 13:22:58 +08:00
|
|
|
this.$emit('changeMessageList', {message:conversationInfo.message, flag: true});
|
2020-07-07 10:54:57 +08:00
|
|
|
if (member && member.userId != this.$store.state.user.id) {
|
|
|
|
this.currentAudioList.push(this.baseUrl + '/audio/' + conversationInfo.message.audioPath);
|
2020-07-06 18:00:44 +08:00
|
|
|
if (!this.isPlay) {
|
|
|
|
this.isPlay = true;
|
|
|
|
this.playAllAudio();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.scrollTop();
|
2020-07-20 15:19:11 +08:00
|
|
|
} else if (this.userRole === 'AUDIENCE' || this.commonConversation) {
|
2020-07-21 13:22:58 +08:00
|
|
|
this.$emit('changeMessageList', {message:conversationInfo.message, flag: true});
|
2020-07-07 10:54:57 +08:00
|
|
|
if (member && member.userId != this.$store.state.user.id) {
|
|
|
|
this.currentAudioList.push(this.baseUrl + '/audio/' + conversationInfo.message.audioPath);
|
2020-07-06 18:00:44 +08:00
|
|
|
if (!this.isPlay) {
|
|
|
|
this.isPlay = true;
|
|
|
|
this.playAllAudio();
|
|
|
|
}
|
|
|
|
}
|
2020-07-21 13:22:58 +08:00
|
|
|
} else { this.$emit('changeMessageList', {message:conversationInfo.message, flag: false}); }
|
2020-07-06 18:00:44 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
// this.coversition = this.currentCoversition;
|
|
|
|
// this.inintData();
|
|
|
|
},
|
|
|
|
methods:{
|
|
|
|
scrollTop() {
|
|
|
|
this.$nextTick(function() {
|
|
|
|
const scrollTop = document.querySelector('.chatcontentInner').offsetHeight - document.querySelector('.chatcontentIn').offsetHeight + 30;
|
|
|
|
document.querySelector('.chatcontentIn').scrollTop = scrollTop;
|
|
|
|
});
|
|
|
|
},
|
2020-07-20 10:48:53 +08:00
|
|
|
|
2020-07-06 18:00:44 +08:00
|
|
|
playAllAudio() {
|
|
|
|
this.playEachAudio(this.currentAudioList[this.currentAudioIndex]);
|
|
|
|
},
|
|
|
|
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) {
|
2020-07-07 10:54:57 +08:00
|
|
|
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;
|
2020-07-06 18:00:44 +08:00
|
|
|
} else {
|
2020-07-07 10:54:57 +08:00
|
|
|
return this.covertEachName(data.memberId);
|
2020-07-06 18:00:44 +08:00
|
|
|
}
|
|
|
|
},
|
2020-07-07 10:54:57 +08:00
|
|
|
covertEachName(memberId) {
|
|
|
|
let name = '';
|
|
|
|
const member = this.$store.state.training.memberData[memberId];
|
|
|
|
if (member && member.userId) {
|
|
|
|
const user = this.simulationUsers[member.userId];
|
2020-07-07 13:15:20 +08:00
|
|
|
name = member.label + '(' + user.nickName + ')';
|
2020-07-07 10:54:57 +08:00
|
|
|
} else if (member) {
|
|
|
|
name = member.label;
|
2020-07-06 18:00:44 +08:00
|
|
|
}
|
2020-07-07 10:54:57 +08:00
|
|
|
return name;
|
2020-07-06 18:00:44 +08:00
|
|
|
},
|
|
|
|
playAudio(audioUrl) {
|
|
|
|
document.querySelector('#audioPlay').src = audioUrl;
|
|
|
|
document.querySelector('#audioPlay').play();
|
2020-07-20 10:48:53 +08:00
|
|
|
},
|
|
|
|
conversationChange() {
|
2020-07-20 13:38:54 +08:00
|
|
|
this.currentAudioList = [];
|
2020-07-06 18:00:44 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
.chatcontentIn{
|
|
|
|
height: 100%;
|
|
|
|
width: 380px;
|
|
|
|
display: inline-block;
|
|
|
|
overflow: auto;
|
|
|
|
padding-bottom: 20px;
|
|
|
|
cursor:auto;
|
|
|
|
}
|
|
|
|
.leftUser{
|
|
|
|
float: left;
|
|
|
|
margin-left: 10px;
|
|
|
|
margin-top: 10px;
|
|
|
|
display: inline-block;
|
|
|
|
}
|
|
|
|
.rightUser{
|
|
|
|
float: right;
|
|
|
|
margin-right: 10px;
|
|
|
|
margin-top: 10px;
|
|
|
|
display: inline-block;
|
|
|
|
}
|
|
|
|
.userHeader{margin-bottom: 2px;}
|
|
|
|
.userName{font-size: 12px;display:inline-block;}
|
|
|
|
.userChatTime{font-size: 12px;display:inline-block;}
|
|
|
|
.userBubble{
|
|
|
|
max-width: 200px;
|
|
|
|
font-size: 12px;
|
|
|
|
padding: 10px;
|
|
|
|
background: #ccc;
|
|
|
|
border-radius: 5px;
|
|
|
|
cursor: pointer;
|
|
|
|
}
|
|
|
|
.playicon{
|
|
|
|
font-size: 20px;
|
|
|
|
vertical-align: top;
|
|
|
|
}
|
|
|
|
.textRight{text-align: right;width: 100%;}
|
|
|
|
.userMessage{}
|
|
|
|
.messageText{line-height: 20px;}
|
|
|
|
.chatContentInClass{
|
|
|
|
display: inline-block;
|
|
|
|
width: 100%;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 谷歌、safari、qq浏览器、360浏览器滚动条样式
|
|
|
|
// 定义滚动条高宽及背景 高宽分别对应横竖滚动条的尺寸
|
|
|
|
.chatcontentIn::-webkit-scrollbar {
|
|
|
|
width: 6px;
|
|
|
|
height: 6px;
|
|
|
|
// height: 110px;
|
|
|
|
background-color: #FFFFFF;
|
|
|
|
}
|
|
|
|
/*定义滚动条轨道 内阴影+圆角*/
|
|
|
|
.chatcontentIn::-webkit-scrollbar-track {
|
|
|
|
// box-shadow: inset 0 0 6px rgba(0,0,0,0.3);
|
|
|
|
border-radius: 10px;
|
|
|
|
background-color: #FFFFFF;;
|
|
|
|
}
|
|
|
|
/*定义滑块 内阴影+圆角*/
|
|
|
|
.chatcontentIn::-webkit-scrollbar-thumb {
|
|
|
|
border-radius: 10px;
|
|
|
|
// box-shadow: inset 0 0 6px rgba(0,0,0,.3);
|
|
|
|
background-color: #cacaca;
|
|
|
|
}
|
|
|
|
/*滑块效果*/
|
|
|
|
.chatcontentIn::-webkit-scrollbar-thumb:hover {
|
|
|
|
border-radius: 5px;
|
|
|
|
// box-shadow: inset 0 0 5px rgba(0,0,0,0.2);
|
|
|
|
background: rgba(0,0,0,0.4);
|
|
|
|
}
|
|
|
|
/*IE滚动条颜色*/
|
|
|
|
html {
|
|
|
|
scrollbar-face-color:#bfbfbf;/*滚动条颜色*/
|
|
|
|
scrollbar-highlight-color:#000;
|
|
|
|
scrollbar-3dlight-color:#000;
|
|
|
|
scrollbar-darkshadow-color:#000;
|
|
|
|
scrollbar-Shadow-color:#adadad;/*滑块边色*/
|
|
|
|
scrollbar-arrow-color:rgba(0,0,0,0.4);/*箭头颜色*/
|
|
|
|
scrollbar-track-color:#eeeeee;/*背景颜色*/
|
|
|
|
}
|
|
|
|
</style>
|