diff --git a/src/views/AIchat.vue b/src/views/AIchat.vue index 1318ff0..1e176b6 100644 --- a/src/views/AIchat.vue +++ b/src/views/AIchat.vue @@ -19,9 +19,9 @@ import { useAudioStore } from "../store/audio"; import { useDataStore } from "@/store/dataList.js"; import { marked } from "marked"; // 引入marked库 // 导入思考过程GIF -import thinkingGif from '@/assets/img/gif/思考.gif'; -import analyzeGif from '@/assets/img/gif/解析.gif'; -import generateGif from '@/assets/img/gif/生成.gif'; +import thinkingGif from "@/assets/img/gif/思考.gif"; +import analyzeGif from "@/assets/img/gif/解析.gif"; +import generateGif from "@/assets/img/gif/生成.gif"; import katex from "katex"; // 引入 KaTeX 库 import { htmlToText } from "html-to-text"; import { Howl, Howler } from "howler"; @@ -1063,6 +1063,29 @@ watch( previousMessagesLength.value = newVal.length; if (newVal.length > 0) { + // 清理语音下标 + chatStore.currentUserIndex = null; + audioStore.stop(); // 暂停语音 + + // 🔧 新增:重置音频队列状态,确保新音频能够自动播放 + audioQueue.value = []; + isPlayingAudio.value = false; + currentPlayIndex = 0; + isCallingPlayNext = false; + + // 重置音频预加载状态 + audioPreloadStatus.one = { loaded: false, url: null }; + audioPreloadStatus.two = { loaded: false, url: null }; + audioPreloadStatus.three = { loaded: false, url: null }; + audioPreloadStatus.four = { loaded: false, url: null }; + + // 清除音频实例 + audioStore.soundInstance = null; + audioStore.nowSound = null; + audioStore.isPlaying = false; + audioStore.isPaused = false; + audioStore.playbackPosition = 0; + console.log("消息列表已更新,最新消息:", newVal[newVal.length - 1]); chatStore.messages.push(newVal[newVal.length - 1]); chatStore.currentUserIndex = chatStore.messages.length - 1; @@ -1110,7 +1133,12 @@ watch( codeData.value.name ); } - + for (let i = chatStore.messages.length - 1; i >= 0; --i) { + if (chatStore.messages[i].sender == "user") { + chatStore.messages[i].audioStatus = true; + break; + } + } chatStore.messages.push({ class: "ing", type: "ing", @@ -2419,6 +2447,10 @@ watch( return; } try { + // 清理语音下标 + chatStore.currentUserIndex = null; + audioStore.stop(); // 暂停语音 + // 解开输入框 emit("enableInput"); // 清除打字机队列和状态 @@ -4316,6 +4348,8 @@ onMounted(() => { }); renderAllKlineCharts(); console.log("组件挂载完成"); + // 重置音频下标 + chatStore.currentUserIndex = null; chatStore.messages.forEach((item) => { if (item.sender == "user") { @@ -4434,7 +4468,7 @@ onUnmounted(() => {
- {{moment(msg.timestamp).format("YYYY-MM-DD HH:mm:ss")}} + {{ moment(msg.timestamp).format("YYYY-MM-DD HH:mm:ss") }}
@@ -4739,7 +4773,7 @@ p { margin-right: 5px; } -.user-sendTime{ +.user-sendTime { width: 100%; text-align: center; color: rgba(255, 255, 255, 0.6); diff --git a/src/views/homePage.vue b/src/views/homePage.vue index c9518fd..ae0e851 100644 --- a/src/views/homePage.vue +++ b/src/views/homePage.vue @@ -258,7 +258,7 @@ const sendMessage = async () => { content: messageContent, timestamp: new Date().toISOString(), audioArray: [], - audioStatus: true, + audioStatus: false, }, ]; console.log(messages.value, "messages.value");