This commit is contained in:
fan 2023-11-30 09:41:55 +08:00
commit c0bf588334
3 changed files with 76 additions and 6 deletions

View File

@ -123,6 +123,7 @@ export default {
}
},
id() {
this.stopNoReadPlay();
this.cancelRecording();
}
},
@ -140,6 +141,45 @@ export default {
this.contentDom = '';
},
methods: {
stopNoReadPlay() {
this.currentAudioList = [];
this.messageList.forEach(item => {
this.$set(item, 'activeAuto', false);
});
const audioDom = document.querySelector('#audioPlay');
audioDom && audioDom.pause();
},
playNoReadMessage() {
if (!this.id && !this.privateChatId) return;
const list = this.getNoReadVoiceList();
if (this.play) {
const filterList = list.filter(item => {
return !this.currentAudioList.find(ii => {
return ii.id == item.id;
});
});
this.currentAudioList.push(...filterList);
} else {
if (list.length) {
this.currentAudioList = list;
this.playAllAudio();
}
}
},
getNoReadVoiceList() {
const filter = this.messageList.filter(item => {
return item.type == 'Voice' && !item.allRead && !item.readerSet.includes(this.myMemberId) && this.myMemberId != item.memberId;
});
return filter;
},
setActiveAutoStatus(ms, s = false) {
const findIndex = this.messageList.findIndex(item => {
return item.id == ms.id;
});
if (findIndex > -1) {
this.$set(this.messageList[findIndex], 'activeAuto', s);
}
},
setIsBottomFn() {
const scrollTop = this.contentDom.scrollHeight - this.contentDom.clientHeight;
if (scrollTop == 0 || this.contentDom.scrollTop >= scrollTop) {
@ -157,16 +197,18 @@ export default {
},
playAllAudio() {
this.$nextTick(function() {
this.currentMessage = this.currentAudioList.shift();
if (this.currentMessage.type === 'Text') {
if (!this.currentAudioList || !this.currentAudioList[0] || this.currentAudioList[0].type === 'Text') {
return;
}
this.currentMessage = this.currentAudioList.shift();
document.querySelector('#audioPlay').src = this.currentMessage.audioPath;
document.querySelector('#audioPlay').play();
this.$set(this.currentMessage, 'activeAuto', true);
this.setActiveAutoStatus(this.currentMessage, true);
this.play = true;
document.querySelector('#audioPlay').onended = () => {
this.$set(this.currentMessage, 'activeAuto', false);
this.setActiveAutoStatus(this.currentMessage);
if (!this.currentAudioList || !this.currentAudioList.length) {
this.play = false;
} else {
@ -176,8 +218,7 @@ export default {
});
},
playAudio(audioPath, data) {
this.$set(this.currentMessage, 'activeAuto', false);
this.currentAudioList = [];
this.stopNoReadPlay();
this.currentMessage = data;
this.play = true;
document.querySelector('#audioPlay').src = audioPath;
@ -234,6 +275,10 @@ export default {
},
//
stopRecording() {
if (this.seconds < 1) {
this.$message.info('录制语音时间太短!');
return;
}
this.audioPlay = true;
clearInterval(this.inter);
this.seconds = 0;

View File

@ -56,7 +56,7 @@
</div>
</div>
<div class="right">
<chat-content v-if="id || privateChatId" :id="id" :group-name="activeGroupName" :private-chat-id="privateChatId" :message-list="activeMessageList" />
<chat-content v-if="id || privateChatId" :id="id" ref="chatContentRef" :group-name="activeGroupName" :private-chat-id="privateChatId" :message-list="activeMessageList" />
</div>
</div>
<div v-show="tabActive==1" class="contentBox">
@ -591,6 +591,9 @@ export default {
this.getMessageStatus(obj);
});
});
this.$nextTick(() => {
this.$refs.chatContentRef && this.$refs.chatContentRef.playNoReadMessage();
});
},
handleClose() {
this.$store.dispatch('training/setChatBoxMin', true);

View File

@ -6,6 +6,9 @@
</el-badge>
</div>
<chatDialog ref="chatDialog" @setTotalUnread="setTotalUnread" />
<audio id="chatBuzzer" style="display:none">
<source :src="buzzerAudio" type="audio/mpeg">
</audio>
</div>
</template>
@ -13,6 +16,7 @@
import { OperationEvent } from '@/scripts/cmdPlugin/OperationHandler';
// import {UserOperationType} from '@/scripts/ConstDic';
import chatDialog from './chatDialog';
import teleRing from '@/assets/teleRing.mp3';
export default {
name: 'ChatBox',
components: {
@ -20,7 +24,8 @@ export default {
},
data() {
return {
totalUnreadNum: 0
totalUnreadNum: 0,
buzzerAudio: teleRing
};
},
computed:{
@ -36,11 +41,27 @@ export default {
this.$nextTick(() => {
this.$store.dispatch('training/emitTipFresh');
});
},
totalUnreadNum(val) {
if (val && !this.$refs.chatDialog.dialogVisible) {
this.playBuzzer();
}
}
},
mounted() {
},
methods: {
playBuzzer() {
const audioDom = document.querySelector('#chatBuzzer');
if (audioDom) {
audioDom.currentTime = 0;
audioDom.play();
}
},
pauseBuzzer() {
const audioDom = document.querySelector('#chatBuzzer');
audioDom && audioDom.pause();
},
setTotalUnread(val) {
this.totalUnreadNum = val;
},
@ -52,6 +73,7 @@ export default {
// };
this.$store.dispatch('training/setChatBoxMin', false);
this.$refs.chatDialog.dialogVisible = true;
this.pauseBuzzer();
// if (this.$store.state.trainingNew.trainingSwitch) {
// this.$nextTick(() => {
// this.$store.dispatch('trainingNew/next', operate);