2019-11-08 09:13:38 +08:00
|
|
|
<template>
|
|
|
|
<!-- 聊天窗口 -->
|
|
|
|
<div class="chat">
|
|
|
|
<div class="chat__head">
|
|
|
|
<div class="chat__head--title"> 会话窗口</div>
|
|
|
|
</div>
|
2019-11-08 18:15:52 +08:00
|
|
|
<div ref="content" class="chat__container" :style="{height: listHeight+'px'}">
|
2019-11-08 09:13:38 +08:00
|
|
|
<ul class="chat__container--list">
|
|
|
|
<div v-for="(nor, index) in textList" :key="index" style="margin-top: 5px;">
|
|
|
|
<li v-if="nor.self" style="position: relative">
|
|
|
|
<div class="userName" style="position: absolute; right: 4px; top: 4px; font-size: 14px;">
|
2020-04-20 18:12:16 +08:00
|
|
|
{{ covertTime(nor.chatTime) }} {{ nor.userName }}</div>
|
2019-11-08 09:13:38 +08:00
|
|
|
<div class="news">
|
|
|
|
<span>{{ nor.value }}</span>
|
|
|
|
</div>
|
2020-04-20 18:12:16 +08:00
|
|
|
<div v-if="nor.voice" class="yuyin" @click="playAudio(nor)">
|
|
|
|
<i class="el-icon-caret-right" />
|
|
|
|
</div>
|
2019-11-08 09:13:38 +08:00
|
|
|
</li>
|
|
|
|
<li v-if="nor.other" style="position: relative">
|
|
|
|
<div class="userName" style="position: absolute; left: 12px; top: 4px; font-size: 14px;">
|
2020-04-20 18:12:16 +08:00
|
|
|
{{ nor.userName }} {{ covertTime(nor.chatTime) }}</div>
|
2019-11-08 09:13:38 +08:00
|
|
|
<div class="answers">
|
|
|
|
<span>{{ nor.value }}</span>
|
|
|
|
</div>
|
2020-04-20 18:12:16 +08:00
|
|
|
<div v-if="nor.voice" class="yuyin1" @click="playAudio(nor)">
|
|
|
|
<i class="el-icon-caret-right" />
|
|
|
|
</div>
|
2019-11-08 09:13:38 +08:00
|
|
|
</li>
|
2020-04-20 18:12:16 +08:00
|
|
|
<li v-if="nor.join" class="roomTip">{{ nor.roomTip }}</li>
|
2019-11-08 09:13:38 +08:00
|
|
|
</div>
|
|
|
|
</ul>
|
2020-04-20 18:12:16 +08:00
|
|
|
<div v-if="recordSending" class="chat_record_tip">
|
2020-04-21 11:26:07 +08:00
|
|
|
<div id="record_progress_bar" :style="'width:'+100/60*seconds+'%'" />
|
2020-04-20 18:12:16 +08:00
|
|
|
<div class="record_icon" />
|
|
|
|
<div class="record_tip_text">正在录音...</div>
|
|
|
|
<div class="record_tip_confirm" @click="stopRecording()">确定</div>
|
|
|
|
<div class="record_tip_cancle" @click="cancleRecording()">取消</div>
|
|
|
|
</div>
|
2019-11-08 09:13:38 +08:00
|
|
|
</div>
|
2020-05-14 14:36:15 +08:00
|
|
|
<audio ref="audio" />
|
2019-11-08 09:13:38 +08:00
|
|
|
<div class="chat__footer">
|
2020-04-20 18:12:16 +08:00
|
|
|
<div class="chat_tool">
|
|
|
|
<div class="microphoneBtn" @click="startRecording()">
|
|
|
|
<span class="el-icon-microphone" />
|
|
|
|
</div>
|
|
|
|
</div>
|
2019-11-08 09:13:38 +08:00
|
|
|
<textarea id="dope" v-model="text" class="chat__footer--text" style="width: 99%;height: 47px; border: none;outline: none;" @keyup="handleSetInputState" />
|
|
|
|
<button class="chat__footer--send" :disabled="disabled" @click="handleSendText">{{ $t('trainRoom.sendText') }}</button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2020-04-20 18:12:16 +08:00
|
|
|
// import HZRecorder from '@/utils/HZRecorder';
|
|
|
|
import RecordRTC from 'recordrtc';
|
2020-05-14 14:36:15 +08:00
|
|
|
import { chatWithText, chatWithAudio, chatWithAudioNew } from '@/api/chat';
|
2020-03-16 15:29:26 +08:00
|
|
|
import { chatWithTextNew } from '@/api/jointTraining';
|
2019-11-08 09:13:38 +08:00
|
|
|
|
|
|
|
export default {
|
|
|
|
props: {
|
|
|
|
room: {
|
|
|
|
type: Object,
|
|
|
|
required: true
|
|
|
|
},
|
|
|
|
members: {
|
|
|
|
type: Array,
|
|
|
|
required: true
|
|
|
|
},
|
|
|
|
height: {
|
|
|
|
type: Number,
|
|
|
|
required: true
|
|
|
|
}
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
textList: [],
|
2020-04-20 18:12:16 +08:00
|
|
|
recordSending:false,
|
2019-11-08 09:13:38 +08:00
|
|
|
text: '',
|
2020-04-21 11:26:07 +08:00
|
|
|
seconds:0,
|
|
|
|
inter:null,
|
2020-04-20 18:12:16 +08:00
|
|
|
recorders: null,
|
2019-11-08 09:13:38 +08:00
|
|
|
sending: false,
|
2020-04-20 18:12:16 +08:00
|
|
|
disabled:true,
|
2020-05-14 14:36:15 +08:00
|
|
|
microphone:null,
|
|
|
|
baseUrl:process.env.VUE_APP_VOICE_API
|
2019-11-08 09:13:38 +08:00
|
|
|
};
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
listHeight() {
|
2020-04-20 18:12:16 +08:00
|
|
|
return this.height - 119;
|
2019-11-08 18:15:52 +08:00
|
|
|
},
|
|
|
|
group() {
|
|
|
|
return this.$route.query.group;
|
|
|
|
},
|
|
|
|
userId() {
|
|
|
|
return this.$store.state.user ? this.$store.state.user.id : '';
|
2020-03-16 15:29:26 +08:00
|
|
|
},
|
|
|
|
drawWay() {
|
2020-05-14 14:36:15 +08:00
|
|
|
const drawWay = this.$route.query.drawWay;
|
|
|
|
return drawWay && JSON.parse(drawWay);
|
2019-11-08 18:15:52 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
'$store.state.socket.chatContent': function (val) { // 房间内语音聊天
|
|
|
|
if (val.chatInfo) {
|
|
|
|
this.handelTextList(val);
|
|
|
|
}
|
2019-11-08 09:13:38 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
2019-11-08 18:15:52 +08:00
|
|
|
async handleSetInputState() {
|
2019-11-08 09:13:38 +08:00
|
|
|
if (!this.text.trim()) {
|
|
|
|
this.disabled = true;
|
|
|
|
} else {
|
|
|
|
this.disabled = false;
|
|
|
|
}
|
|
|
|
},
|
2020-04-20 18:12:16 +08:00
|
|
|
covertTime(time) {
|
|
|
|
return time.slice(0, time.indexOf('.'));
|
|
|
|
},
|
2019-11-08 18:15:52 +08:00
|
|
|
async handleSendText() {
|
|
|
|
try {
|
|
|
|
if (this.text.trim()) {
|
2020-05-14 14:36:15 +08:00
|
|
|
if (this.drawWay) {
|
2020-03-16 15:29:26 +08:00
|
|
|
await chatWithTextNew(this.text, this.group);
|
|
|
|
} else {
|
|
|
|
await chatWithText(this.text, this.group);
|
|
|
|
}
|
2019-11-08 18:15:52 +08:00
|
|
|
this.text = '';
|
|
|
|
this.disabled = true;
|
|
|
|
}
|
|
|
|
} catch (error) {
|
|
|
|
console.error(error);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
async handelTextList(params) {
|
|
|
|
if (!params.inSimulation) {
|
|
|
|
this.textList.push(params);
|
|
|
|
this.textList.sort((a, b) => {
|
|
|
|
return a.date - b.date;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
this.sending = false;
|
|
|
|
this.$store.dispatch('socket/setChatContent', {});
|
|
|
|
this.$nextTick(() => {
|
|
|
|
if (this.$refs.content) {
|
|
|
|
this.$refs.content.scrollTop = this.$refs.content.scrollHeight;
|
|
|
|
}
|
|
|
|
});
|
2020-04-20 18:12:16 +08:00
|
|
|
},
|
|
|
|
// 语音录制开始
|
|
|
|
startRecording() {
|
|
|
|
const that = this;
|
|
|
|
if (!this.recordSending && !this.recorders && !this.microphone) {
|
2020-05-14 14:36:15 +08:00
|
|
|
const StereoAudioRecorder = RecordRTC.StereoAudioRecorder;
|
2020-04-20 18:12:16 +08:00
|
|
|
navigator.getUserMedia(
|
|
|
|
{ audio: true } // 只启用音频
|
|
|
|
, function (stream) {
|
|
|
|
that.microphone = stream;
|
|
|
|
that.recorders = new RecordRTC(that.microphone, {
|
|
|
|
type: 'audio',
|
2020-05-14 14:36:15 +08:00
|
|
|
recorderType: StereoAudioRecorder,
|
|
|
|
numberOfAudioChannels: 1,
|
|
|
|
bitsPerSecond:256000,
|
|
|
|
desiredSampRate: 16000
|
2020-04-20 18:12:16 +08:00
|
|
|
});
|
|
|
|
that.recorders.startRecording();
|
|
|
|
that.recordSending = true;
|
2020-04-21 11:26:07 +08:00
|
|
|
that.inter = setInterval(() => {
|
|
|
|
if (that.seconds < 60) {
|
|
|
|
that.seconds++;
|
|
|
|
} else {
|
|
|
|
clearInterval(that.inter);
|
|
|
|
}
|
|
|
|
}, 1000);
|
2020-04-20 18:12:16 +08:00
|
|
|
}, function (error) {
|
|
|
|
switch (error.code || error.name) {
|
|
|
|
case 'PERMISSION_DENIED':
|
|
|
|
case 'PermissionDeniedError':
|
|
|
|
that.$message({
|
|
|
|
showClose: true,
|
|
|
|
message: '用户拒绝提供信息',
|
|
|
|
type: 'error'
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
case 'NOT_SUPPORTED_ERROR':
|
|
|
|
case 'NotSupportedError':
|
|
|
|
that.$message({
|
|
|
|
showClose: true,
|
|
|
|
message: '浏览器不支持硬件设备',
|
|
|
|
type: 'error'
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
case 'MANDATORY_UNSATISFIED_ERROR':
|
|
|
|
case 'MandatoryUnsatisfiedError':
|
|
|
|
that.$message({
|
|
|
|
showClose: true,
|
|
|
|
message: '无法发现指定的硬件设备',
|
|
|
|
type: 'error'
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
that.$message({
|
|
|
|
showClose: true,
|
|
|
|
message: '无法打开麦克风',
|
|
|
|
type: 'error'
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
// 停止录制
|
|
|
|
stopRecording() {
|
|
|
|
const that = this;
|
|
|
|
this.recorders.stopRecording(function(blobURL) {
|
2020-04-21 11:26:07 +08:00
|
|
|
clearInterval(that.inter);
|
|
|
|
that.seconds = 0;
|
2020-04-20 18:12:16 +08:00
|
|
|
const blob = that.recorders.getBlob();
|
|
|
|
const fd = new FormData();
|
|
|
|
fd.append('file', blob);
|
2020-05-14 14:36:15 +08:00
|
|
|
if (that.drawWay) {
|
|
|
|
chatWithAudioNew(fd, that.group)
|
|
|
|
.then((data) => {
|
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
console.log(error);
|
2020-04-20 18:12:16 +08:00
|
|
|
});
|
2020-05-14 14:36:15 +08:00
|
|
|
} else {
|
|
|
|
chatWithAudio(fd, that.group)
|
|
|
|
.then((data) => {
|
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
console.log(error);
|
2020-04-20 18:12:16 +08:00
|
|
|
});
|
2020-05-14 14:36:15 +08:00
|
|
|
}
|
|
|
|
|
2020-04-20 18:12:16 +08:00
|
|
|
if (that.microphone) {
|
|
|
|
that.microphone.stop();
|
|
|
|
that.microphone = null;
|
|
|
|
that.recordSending = false;
|
|
|
|
that.recorders = null;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
cancleRecording() {
|
2020-04-21 11:26:07 +08:00
|
|
|
if (this.microphone) {
|
|
|
|
clearInterval(this.inter);
|
|
|
|
this.seconds = 0;
|
|
|
|
this.microphone.stop();
|
|
|
|
this.microphone = null;
|
|
|
|
this.recordSending = false;
|
|
|
|
this.recorders = null;
|
|
|
|
}
|
2020-04-20 18:12:16 +08:00
|
|
|
},
|
|
|
|
playAudio(nor) {
|
2020-05-14 14:36:15 +08:00
|
|
|
this.$refs.audio.src = this.baseUrl + nor.src;
|
2020-04-20 18:12:16 +08:00
|
|
|
this.$refs.audio.play();
|
2019-11-08 09:13:38 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style scoped lang="scss">
|
|
|
|
ul,
|
|
|
|
li {
|
|
|
|
list-style: none;
|
|
|
|
padding: 0;
|
|
|
|
margin: 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
::-webkit-scrollbar {
|
|
|
|
width: 0px;
|
|
|
|
}
|
|
|
|
|
|
|
|
::-webkit-scrollbar-thumb {
|
|
|
|
background-color: #c7c7c7;
|
|
|
|
}
|
|
|
|
|
|
|
|
.chat {
|
|
|
|
border: 1px solid #ccc;
|
|
|
|
height: 100%;
|
|
|
|
background-color: #fff;
|
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
|
|
|
justify-content: space-between;
|
|
|
|
|
|
|
|
&__head {
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
background: #f0f0f0;
|
|
|
|
border-bottom: 1px solid #ccc;
|
|
|
|
|
|
|
|
&--title {
|
|
|
|
font-size: 16px;
|
|
|
|
font-weight: bold;
|
2019-11-18 17:11:40 +08:00
|
|
|
padding:10px 0px 10px 10px;
|
2019-11-08 09:13:38 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
&__container {
|
|
|
|
-webkit-box-flex: 1;
|
|
|
|
overflow-y: scroll;
|
|
|
|
padding-right: 8px;
|
|
|
|
padding-left: 2px;
|
2020-04-20 18:12:16 +08:00
|
|
|
position: relative;
|
2019-11-08 09:13:38 +08:00
|
|
|
&--list {
|
|
|
|
list-style: none;
|
|
|
|
margin: 0;
|
|
|
|
padding: 10px 0;
|
|
|
|
|
|
|
|
li {
|
|
|
|
width: 100%;
|
|
|
|
overflow: hidden;
|
|
|
|
padding-top: 8px;
|
2020-04-20 18:12:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
.yuyin {
|
|
|
|
width: 20px;
|
|
|
|
height: 20px;
|
|
|
|
cursor: pointer;
|
|
|
|
margin-top: 21px;
|
|
|
|
margin-right: 3px;
|
|
|
|
float: right;
|
|
|
|
border: 1px solid #ccc;
|
|
|
|
border-radius: 50%;
|
|
|
|
}
|
|
|
|
|
|
|
|
.yuyin1 {
|
|
|
|
width: 20px;
|
|
|
|
height: 20px;
|
|
|
|
cursor: pointer;
|
|
|
|
margin-top: 21px;
|
|
|
|
margin-left: 3px;
|
|
|
|
float: left;
|
|
|
|
border: 1px solid #ccc;
|
|
|
|
border-radius: 50%;
|
|
|
|
}
|
2019-11-08 09:13:38 +08:00
|
|
|
|
|
|
|
.news {
|
|
|
|
max-width: 55%;
|
|
|
|
width: auto;
|
|
|
|
height: auto;
|
|
|
|
background: #2683f5;
|
|
|
|
padding: 6px 10px;
|
|
|
|
margin-top: 15px;
|
|
|
|
line-height: 20px;
|
|
|
|
font-size: 14px;
|
|
|
|
border-radius: 4px;
|
|
|
|
position: relative;
|
|
|
|
float: right;
|
|
|
|
color: #fff;
|
|
|
|
text-align: left;
|
|
|
|
}
|
|
|
|
|
|
|
|
.answers {
|
|
|
|
max-width: 55%;
|
|
|
|
width: auto;
|
|
|
|
height: auto;
|
|
|
|
background: #eee;
|
|
|
|
padding: 5px 10px;
|
|
|
|
margin-top: 15px;
|
|
|
|
line-height: 22px;
|
|
|
|
font-size: 14px;
|
|
|
|
border-radius: 5px;
|
|
|
|
margin-left: 10px;
|
|
|
|
position: relative;
|
|
|
|
float: left;
|
|
|
|
text-align: left;
|
2020-04-20 18:12:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
.roomTip{
|
|
|
|
font-size: 12px;
|
|
|
|
text-align: center;
|
|
|
|
}
|
2019-11-08 09:13:38 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-21 11:26:07 +08:00
|
|
|
#record_progress_bar{
|
|
|
|
height: 100%;
|
|
|
|
position: absolute;
|
|
|
|
background: #bbe5f5;
|
|
|
|
}
|
|
|
|
|
2020-04-20 18:12:16 +08:00
|
|
|
.chat_record_tip{
|
|
|
|
height: 28px;
|
|
|
|
display: inline-block;
|
|
|
|
background: #dfe6ee;
|
|
|
|
width: 100%;
|
|
|
|
font-size: 13px;
|
|
|
|
border-top: 1px #d8dce5 solid;
|
|
|
|
position: absolute;
|
|
|
|
bottom: 0;
|
|
|
|
right: 0;
|
|
|
|
}
|
|
|
|
.record_icon{
|
|
|
|
display: inline-block;
|
|
|
|
width: 8px;
|
|
|
|
height: 8px;
|
|
|
|
background: #25d825;
|
|
|
|
border-radius: 10px;
|
2020-04-21 11:26:07 +08:00
|
|
|
left: 7px;
|
2020-04-20 18:12:16 +08:00
|
|
|
margin-right: 0px;
|
|
|
|
box-shadow: -1px 0px 3px #6d6d6d;
|
|
|
|
border: 1px #28d228 solid;
|
2020-04-21 11:26:07 +08:00
|
|
|
position: absolute;
|
|
|
|
top: 10px;
|
2020-04-20 18:12:16 +08:00
|
|
|
}
|
|
|
|
.record_tip_text{
|
|
|
|
display: inline-block;
|
|
|
|
font-size: 12px;
|
|
|
|
margin-left: 3px;
|
2020-04-21 11:26:07 +08:00
|
|
|
// padding: 8px 0px 6px 0px;
|
|
|
|
position: absolute;
|
|
|
|
top: 8px;
|
|
|
|
left:20px
|
2020-04-20 18:12:16 +08:00
|
|
|
}
|
|
|
|
.record_tip_confirm{
|
|
|
|
position: absolute;
|
|
|
|
right: 63px;
|
|
|
|
padding: 3px 0px 2px 0px;
|
|
|
|
border: 1px #a2a5aa solid;
|
|
|
|
border-radius: 5px;
|
|
|
|
width: 45px;
|
|
|
|
text-align: center;
|
|
|
|
font-size: 12px;
|
|
|
|
top: 4px;
|
|
|
|
background: #eeeeee;
|
|
|
|
cursor: pointer;
|
|
|
|
}
|
|
|
|
.record_tip_cancle{
|
|
|
|
position: absolute;
|
|
|
|
right: 10px;
|
|
|
|
padding: 3px 0px 2px 0px;
|
|
|
|
border: 1px #a2a5aa solid;
|
|
|
|
border-radius: 5px;
|
|
|
|
width: 45px;
|
|
|
|
text-align: center;
|
|
|
|
font-size: 12px;
|
|
|
|
top: 4px;
|
|
|
|
background: #eeeeee;
|
|
|
|
cursor: pointer;
|
|
|
|
}
|
|
|
|
|
2019-11-08 09:13:38 +08:00
|
|
|
&__footer {
|
|
|
|
width: 100%;
|
2020-04-20 18:12:16 +08:00
|
|
|
height: 113px;
|
2019-11-08 09:13:38 +08:00
|
|
|
position: relative;
|
|
|
|
|
2020-04-20 18:12:16 +08:00
|
|
|
.chat_tool{
|
|
|
|
border-top: 1px solid #d8dce5;
|
|
|
|
width: 100%;
|
|
|
|
padding: 5px;
|
|
|
|
}
|
|
|
|
.microphoneBtn{
|
|
|
|
font-size: 18px;
|
|
|
|
padding: 2px;
|
|
|
|
width: 24px;
|
|
|
|
text-align: center;
|
|
|
|
&:hover{
|
|
|
|
color:#0188fb;
|
|
|
|
cursor: pointer;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-08 09:13:38 +08:00
|
|
|
&--text {
|
|
|
|
width: 99%;
|
|
|
|
height: 75px;
|
|
|
|
border: none;
|
|
|
|
outline: none;
|
|
|
|
resize: none;
|
|
|
|
font-size: 16px;
|
2019-11-18 17:11:40 +08:00
|
|
|
padding-left: 10px;
|
2020-04-20 18:12:16 +08:00
|
|
|
padding-top: 0px;
|
2019-11-08 09:13:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
&--send {
|
|
|
|
width: 70px;
|
|
|
|
height: 25px;
|
|
|
|
background: #0188fb;
|
|
|
|
border: 0;
|
|
|
|
position: absolute;
|
|
|
|
bottom: 10px;
|
|
|
|
right: 10px;
|
|
|
|
color: #fff;
|
|
|
|
cursor: pointer;
|
|
|
|
font-size: 12px;
|
|
|
|
line-height: 25px;
|
|
|
|
text-align: center;
|
|
|
|
&:disabled{
|
|
|
|
background: #6dbcff;
|
|
|
|
cursor: no-drop;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|