mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-28 19:23:52 +08:00
fix: 修复聊天记录播放音频重叠播放的问题
This commit is contained in:
@@ -49,6 +49,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import { debounce } from '@/utils'
|
||||||
import Api from '@/apis/api';
|
import Api from '@/apis/api';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
@@ -259,7 +260,7 @@ export default {
|
|||||||
}
|
}
|
||||||
return 'el-icon-video-play';
|
return 'el-icon-video-play';
|
||||||
},
|
},
|
||||||
playAudio(message) {
|
playAudio: debounce(function(message) {
|
||||||
if (this.playingAudioId === message.audioId) {
|
if (this.playingAudioId === message.audioId) {
|
||||||
// 如果正在播放当前音频,则停止播放
|
// 如果正在播放当前音频,则停止播放
|
||||||
if (this.audioElement) {
|
if (this.audioElement) {
|
||||||
@@ -280,9 +281,12 @@ export default {
|
|||||||
this.playingAudioId = message.audioId;
|
this.playingAudioId = message.audioId;
|
||||||
Api.agent.getAudioId(message.audioId, (res) => {
|
Api.agent.getAudioId(message.audioId, (res) => {
|
||||||
if (res.data && res.data.data) {
|
if (res.data && res.data.data) {
|
||||||
// 使用获取到的下载ID播放音频
|
if (!this.audioElement) {
|
||||||
this.audioElement = new Audio(Api.getServiceUrl() + `/agent/play/${res.data.data}`);
|
this.audioElement = new Audio();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 使用获取到的下载ID播放音频
|
||||||
|
this.audioElement.src = Api.getServiceUrl() + `/agent/play/${res.data.data}`;
|
||||||
this.audioElement.onended = () => {
|
this.audioElement.onended = () => {
|
||||||
this.playingAudioId = null;
|
this.playingAudioId = null;
|
||||||
this.audioElement = null;
|
this.audioElement = null;
|
||||||
@@ -291,7 +295,7 @@ export default {
|
|||||||
this.audioElement.play();
|
this.audioElement.play();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
}, 300),
|
||||||
getUserAvatar(sessionId) {
|
getUserAvatar(sessionId) {
|
||||||
// 从 sessionId 中提取所有数字
|
// 从 sessionId 中提取所有数字
|
||||||
const numbers = sessionId.match(/\d+/g);
|
const numbers = sessionId.match(/\d+/g);
|
||||||
|
|||||||
@@ -58,7 +58,6 @@ export default new Vuex.Store({
|
|||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
commit('clearAuth')
|
commit('clearAuth')
|
||||||
goToPage(Constant.PAGE.LOGIN, true);
|
goToPage(Constant.PAGE.LOGIN, true);
|
||||||
window.location.reload(); // 彻底重置状态
|
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
// 添加获取公共配置的 action
|
// 添加获取公共配置的 action
|
||||||
|
|||||||
@@ -257,3 +257,33 @@ export function sm2Decrypt(privateKey, cipherText) {
|
|||||||
return sm2.doDecrypt(dataWithoutPrefix, privateKey, 1);
|
return sm2.doDecrypt(dataWithoutPrefix, privateKey, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 防抖函数
|
||||||
|
* @param {Function} fn 要防抖的函数
|
||||||
|
* @param {number} delay 延迟时间(毫秒),默认500ms
|
||||||
|
* @param {boolean} immediate 是否立即执行,默认false
|
||||||
|
* @returns {Function} 防抖处理后的函数
|
||||||
|
*/
|
||||||
|
export function debounce(fn, delay = 500, immediate = false) {
|
||||||
|
let timer = null;
|
||||||
|
|
||||||
|
return function (...args) {
|
||||||
|
const context = this;
|
||||||
|
|
||||||
|
if (timer) {
|
||||||
|
clearTimeout(timer);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (immediate && !timer) {
|
||||||
|
fn.apply(context, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
timer = setTimeout(() => {
|
||||||
|
if (!immediate) {
|
||||||
|
fn.apply(context, args);
|
||||||
|
}
|
||||||
|
timer = null;
|
||||||
|
}, delay);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user