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

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,6 +629,7 @@ export default {
startRecord() { startRecord() {
if (this.sendClass === 'recorder') { if (this.sendClass === 'recorder') {
this.recordState = "ready"; this.recordState = "ready";
this.$nextTick(_ => {
this.recordRec.open(_ => { this.recordRec.open(_ => {
if (this.recordState === "ready") { if (this.recordState === "ready") {
this.recordDuration = 0; this.recordDuration = 0;
@ -626,6 +644,7 @@ export default {
}, (msg) => { }, (msg) => {
$A.messageError(msg || '打开录音失败') $A.messageError(msg || '打开录音失败')
}); });
})
return true; return true;
} else { } else {
return false; return false;