2020-07-21 15:15:28 +08:00
|
|
|
<template>
|
|
|
|
<div class="chatcontentIn">
|
|
|
|
<div class="chatcontentInner">
|
|
|
|
<div v-for="(chatContent,index) in chatContentList" :key="index" class="chatContentInClass">
|
2020-07-22 13:55:12 +08:00
|
|
|
<div :class="chatContent.self?'rightUser':'leftUser'">
|
2020-07-21 15:15:28 +08:00
|
|
|
<div class="userHeader">
|
2020-07-22 13:55:12 +08:00
|
|
|
<div v-if="!chatContent.self" class="userName">{{ chatContent.member.label }}</div>
|
|
|
|
<div :class="chatContent.self?'userChatTime textRight':'userChatTime'">{{ chatContent.chatTime }}</div>
|
2020-07-21 15:15:28 +08:00
|
|
|
</div>
|
|
|
|
<div class="userBubble" @click="playAudio(baseUrl+chatContent.src)">
|
|
|
|
<div class="userMessage">
|
|
|
|
<span class="el-icon-video-play playicon" />
|
2020-07-22 13:55:12 +08:00
|
|
|
<span class="messageText">{{ chatContent.message }}</span>
|
2020-07-21 15:15:28 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<audio id="audioPlay" style="display:none" />
|
2020-07-22 13:55:12 +08:00
|
|
|
</div>
|
2020-07-21 15:15:28 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
<script>
|
|
|
|
|
|
|
|
export default {
|
|
|
|
props:{
|
|
|
|
chatContentList:{
|
|
|
|
type:Array,
|
|
|
|
required:true
|
|
|
|
}
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
2020-09-01 11:20:53 +08:00
|
|
|
currentAudioList:[],
|
|
|
|
currentAudioIndex:0,
|
|
|
|
isPlay:false,
|
|
|
|
isAutoPlay: false,
|
2020-08-28 18:04:46 +08:00
|
|
|
baseUrl:process.env.VUE_APP_VOICE_API + 'audio/'
|
2020-07-21 15:15:28 +08:00
|
|
|
};
|
|
|
|
},
|
2020-09-01 11:20:53 +08:00
|
|
|
watch: {
|
|
|
|
'currentAudioList': function(val) {
|
|
|
|
if (val.length > 0 && !this.isPlay && !this.isAutoPlay) {
|
|
|
|
this.playEachAudio(val[0].src);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2020-07-21 15:15:28 +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-08-10 15:54:38 +08:00
|
|
|
},
|
2020-09-01 11:20:53 +08:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
});
|
|
|
|
},
|
2020-08-10 15:54:38 +08:00
|
|
|
playAudio(audioUrl) {
|
2020-09-01 11:20:53 +08:00
|
|
|
this.isPlay = true;
|
2020-08-10 15:54:38 +08:00
|
|
|
document.querySelector('#audioPlay').src = audioUrl;
|
|
|
|
document.querySelector('#audioPlay').play();
|
2020-09-01 11:20:53 +08:00
|
|
|
const that = this;
|
|
|
|
document.querySelector('#audioPlay').onended = function() {
|
|
|
|
that.isPlay = false;
|
|
|
|
that.isAutoPlay = false;
|
|
|
|
};
|
|
|
|
},
|
|
|
|
addAudioList(converstion) {
|
|
|
|
this.currentAudioList.push(converstion);
|
|
|
|
this.scrollTop();
|
2020-08-10 15:54:38 +08:00
|
|
|
}
|
2020-07-21 15:15:28 +08:00
|
|
|
// conversationChange() {
|
|
|
|
// this.currentAudioList = [];
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
.chatcontentIn{
|
|
|
|
height: 100%;
|
2020-07-22 13:55:12 +08:00
|
|
|
width: 360px;
|
2020-07-21 15:15:28 +08:00
|
|
|
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;}
|
2020-07-22 17:20:24 +08:00
|
|
|
.userName{font-size: 12px;display:inline-block;margin-right:10px;}
|
2020-07-21 15:15:28 +08:00
|
|
|
.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>
|