fix: 任务弹窗无法发送语音

This commit is contained in:
kuaifan 2022-05-29 12:45:40 +08:00
parent e750d2ae80
commit 4853d5227b
4 changed files with 75 additions and 57 deletions

View File

@ -138,6 +138,10 @@ export default {
type: Boolean,
default: false
},
disabledRecord: {
type: Boolean,
default: false
},
loading: {
type: Boolean,
default: false
@ -532,44 +536,46 @@ export default {
return delta
})
// Load recorder
$A.loadScriptS([
'js/recorder/recorder.mp3.min.js',
'js/recorder/lib.fft.js',
'js/recorder/frequency.histogram.view.js',
], (e) => {
if (e !== null || typeof window.Recorder !== 'function') {
return;
}
this.recordRec = window.Recorder({
type: "mp3",
bitRate: 32,
sampleRate: 16000,
onProcess: (buffers, powerLevel, duration, sampleRate, newBufferIdx, asyncEnd) => {
this.recordWave.input(buffers[buffers.length - 1], powerLevel, sampleRate);
this.recordDuration = duration;
if (duration >= 3 * 60 * 1000) {
// 3
this.stopRecord(false);
}
}
})
if (window.Recorder.Support()) {
this.recordReady = true;
this.$nextTick(_ => {
this.recordWave = window.Recorder.FrequencyHistogramView({
elem: this.$refs.recwave,
lineCount: 90,
position: 0,
minHeight: 1,
stripeEnable: false
})
})
}
});
// Ready event
this.$emit('on-ready', this.quill)
// Load recorder
if (!this.disabledRecord) {
$A.loadScriptS([
'js/recorder/recorder.mp3.min.js',
'js/recorder/lib.fft.js',
'js/recorder/frequency.histogram.view.js',
], (e) => {
if (e !== null || typeof window.Recorder !== 'function') {
return;
}
this.recordRec = window.Recorder({
type: "mp3",
bitRate: 32,
sampleRate: 16000,
onProcess: (buffers, powerLevel, duration, sampleRate, newBufferIdx, asyncEnd) => {
this.recordWave.input(buffers[buffers.length - 1], powerLevel, sampleRate);
this.recordDuration = duration;
if (duration >= 3 * 60 * 1000) {
// 3
this.stopRecord(false);
}
}
})
if (window.Recorder.Support()) {
this.recordReady = true;
this.$nextTick(_ => {
this.recordWave = window.Recorder.FrequencyHistogramView({
elem: this.$refs.recwave,
lineCount: 90,
position: 0,
minHeight: 1,
stripeEnable: false
})
})
}
});
}
},
setText(value) {
@ -721,13 +727,10 @@ export default {
}
const reader = new FileReader();
reader.onloadend = () => {
this.$emit('on-send', {
type: 'record',
data: {
type: this.recordBlob.type,
base64: reader.result,
duration,
}
this.$emit('on-record', {
type: this.recordBlob.type,
base64: reader.result,
duration,
})
};
reader.readAsDataURL(this.recordBlob);

View File

@ -120,6 +120,7 @@
@on-blur="onEventBlur"
@on-more="onEventMore"
@on-file="sendFileMsg"
@on-record="sendRecord"
@on-send="sendMsg"
@on-emoji-visible-change="onEventEmojiVisibleChange"
:placeholder="$L('输入消息...')"/>
@ -330,11 +331,13 @@ export default {
'$route': {
handler (route) {
if ($A.isJson(window.__sendDialogMsg) && window.__sendDialogMsg.time > $A.Time()) {
const {msgFile, msgText} = window.__sendDialogMsg;
const {msgFile, msgRecord, msgText} = window.__sendDialogMsg;
window.__sendDialogMsg = null;
this.$nextTick(() => {
if ($A.isArray(msgFile) && msgFile.length > 0) {
this.sendFileMsg(msgFile);
} else if ($A.isJson(msgRecord) && msgRecord.duration > 0) {
this.sendRecord(msgRecord);
} else if (msgText) {
this.sendMsg(msgText);
}
@ -411,13 +414,6 @@ export default {
* @param text
*/
sendMsg(text) {
if ($A.isJson(text)) {
if (text.type === 'record') {
// text.record
this.sendRecordMsg(text.data);
}
return;
}
let msgText;
if (typeof text === "string" && text) {
msgText = text;
@ -465,7 +461,7 @@ export default {
* 发送录音
* @param msg {base64, duration}
*/
sendRecordMsg(msg) {
sendRecord(msg) {
this.onToBottom();
this.onActive();
//

View File

@ -409,8 +409,9 @@
:placeholder="$L('输入消息...')"
@on-more="onEventMore"
@on-file="onSelectFile"
@on-record="onRecord"
@on-send="onSend"/>
<Badge class="input-badge" :count="taskDetail.msg_num"/>
<div v-if="taskDetail.msg_num" class="input-badge" @click.stop="onSend">{{taskDetail.msg_num > 99 ? '99+' : taskDetail.msg_num}}</div>
</div>
<div v-if="dialogDrag" class="drag-over" @click="dialogDrag=false">
<div class="drag-text">{{$L('拖动到这里发送')}}</div>
@ -492,6 +493,7 @@ export default {
msgText: '',
msgFile: [],
msgRecord: {},
navActive: 'dialog',
logLoadIng: false,
@ -1106,8 +1108,10 @@ export default {
window.__sendDialogMsg = {
time: $A.Time() + 10,
msgText: this.msgText,
msgFile: this.msgFile
msgFile: this.msgFile,
msgRecord: this.msgRecord
};
this.msgRecord = {};
this.msgFile = [];
this.msgText = "";
this.goForward({name: 'manage-messenger', params: {dialogId: data.dialog_id}, query: {_: $A.randomString(6)}});
@ -1173,6 +1177,11 @@ export default {
this.msgDialog()
},
onRecord(row) {
this.msgRecord = row;
this.msgDialog()
},
onSend() {
this.$refs.chatInput && this.$refs.chatInput.hidePopover();
this.msgDialog();

View File

@ -571,7 +571,7 @@
position: relative;
margin: 22px 0 0 36px;
background-color: #F4F5F7;
padding: 10px 8px;
padding: 10px 4px 10px 6px;
border-radius: 10px;
.chat-input-box {
.chat-input-wrapper {
@ -588,11 +588,21 @@
}
.input-badge {
position: absolute;
transform: scale(0.6) translateX(100%);
transform: scale(0.8) translateX(100%);
transform-origin: right center;
top: 2px;
right: 25px;
right: 22px;
z-index: 2;
height: 20px;
border-radius: 10px;
min-width: 20px;
background: #ed4014;
color: #fff;
line-height: 20px;
text-align: center;
padding: 0 6px;
font-size: 12px;
white-space: nowrap;
}
}
.drag-over {