录音时长不增加则取消录音

This commit is contained in:
kuaifan 2022-05-29 11:13:17 +08:00
parent c6ab79db30
commit fb3bf48bbc

View File

@ -89,7 +89,7 @@
<!-- 录音浮窗 --> <!-- 录音浮窗 -->
<transition name="fade"> <transition name="fade">
<div <div
v-if="recordState === 'ing'" v-if="['ready', 'ing'].includes(recordState)"
v-transfer-dom v-transfer-dom
:data-transfer="true" :data-transfer="true"
class="chat-input-record-transfer" class="chat-input-record-transfer"
@ -184,9 +184,10 @@ export default {
recordReady: false, recordReady: false,
recordRec: null, recordRec: null,
recordState: "stop",
recordBlob: null, recordBlob: null,
recordWave: null, recordWave: null,
recordInter: null,
recordState: "stop",
recordDuration: 0, recordDuration: 0,
touchStart: {}, touchStart: {},
@ -210,6 +211,19 @@ export default {
}); });
this.observer.observe(this.$el); this.observer.observe(this.$el);
this.observer.observe(this.$refs.editor); this.observer.observe(this.$refs.editor);
//
this.recordInter = setInterval(_ => {
if (this.recordState === 'ing') {
//
if (this.__recordDuration && this.__recordDuration === this.recordDuration) {
this.__recordDuration = null;
this.stopRecord(true);
$A.messageWarning("录音失败,请重试")
} else {
this.__recordDuration = this.recordDuration;
}
}
}, 1000)
}, },
beforeDestroy() { beforeDestroy() {
if (this.quill) { if (this.quill) {
@ -219,6 +233,9 @@ export default {
this.observer.disconnect() this.observer.disconnect()
this.observer = null this.observer = null
} }
if (this.recordInter) {
clearInterval(this.recordInter)
}
}, },
computed: { computed: {
...mapState(['dialogInputCache', 'cacheProjects', 'cacheTasks', 'cacheUserBasic', 'userId']), ...mapState(['dialogInputCache', 'cacheProjects', 'cacheTasks', 'cacheUserBasic', 'userId']),
@ -612,20 +629,22 @@ export default {
startRecord() { startRecord() {
if (this.sendClass === 'recorder') { if (this.sendClass === 'recorder') {
this.recordState = "ready"; this.recordState = "ready";
this.recordRec.open(_ => { this.$nextTick(_ => {
if (this.recordState === "ready") { this.recordRec.open(_ => {
this.recordDuration = 0; if (this.recordState === "ready") {
this.recordState = "ing" this.recordDuration = 0;
this.recordBlob = null this.recordState = "ing"
setTimeout(_ => { this.recordBlob = null
this.recordRec.start() setTimeout(_ => {
}, 300) this.recordRec.start()
} else { }, 300)
this.recordRec.close(); } else {
} this.recordRec.close();
}, (msg) => { }
$A.messageError(msg || '打开录音失败') }, (msg) => {
}); $A.messageError(msg || '打开录音失败')
});
})
return true; return true;
} else { } else {
return false; return false;