From 88dfbde8acbdb4bf1e5b0b18a699cb22a7b8cc46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=8B=E6=9D=B0?= Date: Tue, 24 Jun 2025 16:12:25 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=BA=E5=AE=9D=E5=A5=87=E5=85=B5=E5=A4=A7?= =?UTF-8?q?=E6=A8=A1=E5=9E=8B=E9=9F=B3=E9=A2=91=E5=AE=8C=E6=88=90=EF=BC=9B?= =?UTF-8?q?=E6=83=85=E7=BB=AA=E5=A4=A7=E6=A8=A1=E5=9E=8Btoken=E6=B5=8F?= =?UTF-8?q?=E8=A7=88=E5=99=A8=E8=8E=B7=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/AIchat.vue | 145 +++++++++++++++++++++++++++++++++++++++++++----- src/views/AiEmotion.vue | 10 ++-- 2 files changed, 135 insertions(+), 20 deletions(-) diff --git a/src/views/AIchat.vue b/src/views/AIchat.vue index fc22c7e..64c4fcb 100644 --- a/src/views/AIchat.vue +++ b/src/views/AIchat.vue @@ -139,21 +139,35 @@ const pauseAudio = () => { // 音频轮流播放方法 const playAudioSequence = (audioUrls) => { + console.log('playAudioSequence被调用,参数:', audioUrls); if (!audioUrls || audioUrls.length === 0) { console.warn("音频URL列表为空,跳过播放"); return; } let currentIndex = 0; + let audioSequence = [...audioUrls]; // 保存音频序列 const playNext = () => { - if (currentIndex >= audioUrls.length) { - console.log("所有音频播放完成"); + if (currentIndex >= audioSequence.length) { + console.log("所有音频播放完成,重置到第一个音频"); + // 播放完成后重置到第一个音频,但不自动播放 + currentIndex = 0; + audioStore.isPlaying = false; + audioStore.isPaused = false; + audioStore.playbackPosition = 0; + if (audioSequence.length > 0) { + audioStore.setCurrentAudioUrl(audioSequence[0]); + } return; } - const currentUrl = audioUrls[currentIndex]; + const currentUrl = audioSequence[currentIndex]; console.log(`正在播放第${currentIndex + 1}个音频:`, currentUrl); + console.log('音频URL有效性检查:', !!currentUrl, '长度:', currentUrl?.length); + + // 设置当前音频URL + audioStore.setCurrentAudioUrl(currentUrl); // 停止当前播放的音频 if (audioStore.nowSound) { @@ -167,10 +181,19 @@ const playAudioSequence = (audioUrls) => { rate: 1.2, onplay: () => { audioStore.isPlaying = true; + audioStore.isPaused = false; console.log(`开始播放音频 ${currentIndex + 1}`); }, + onpause: () => { + audioStore.isPlaying = false; + audioStore.isPaused = true; + audioStore.playbackPosition = sound.seek() || 0; + console.log(`音频 ${currentIndex + 1} 已暂停`); + }, onend: () => { audioStore.isPlaying = false; + audioStore.isPaused = false; + audioStore.playbackPosition = 0; console.log(`音频 ${currentIndex + 1} 播放完成`); currentIndex++; // 播放下一个音频 @@ -180,6 +203,9 @@ const playAudioSequence = (audioUrls) => { }, onstop: () => { audioStore.isPlaying = false; + audioStore.isPaused = false; + audioStore.playbackPosition = 0; + console.log(`音频 ${currentIndex + 1} 已停止`); }, onloaderror: (id, err) => { console.error(`音频 ${currentIndex + 1} 加载失败:`, err); @@ -196,6 +222,30 @@ const playAudioSequence = (audioUrls) => { sound.play(); }; + // 重写togglePlayPause方法以支持音频序列控制 + const originalTogglePlayPause = audioStore.togglePlayPause; + audioStore.togglePlayPause = () => { + if (audioStore.soundInstance) { + if (audioStore.isPlaying) { + // 暂停当前音频 + audioStore.pause(); + } else if (audioStore.isPaused) { + // 从暂停位置继续播放 + audioStore.play(); + } else { + // 重新开始播放当前音频或从头开始播放序列 + if (currentIndex >= audioSequence.length) { + currentIndex = 0; // 重置到第一个音频 + } + playNext(); + } + } else { + // 没有音频实例时,从头开始播放 + currentIndex = 0; + playNext(); + } + }; + // 开始播放第一个音频 playNext(); }; @@ -1113,6 +1163,46 @@ watch( // }); } } + + // 检查是否所有API都已完成并执行 + if (apiStatus.one.completed && apiStatus.two.completed && apiStatus.three.completed && apiStatus.four.completed && apiStatus.four.executed) { + console.log('所有API已完成,开始收集音频URL'); + // 收集所有音频URL + const audioUrls = []; + console.log('API返回结果检查:'); + console.log('result21:', result21); + console.log('result22:', result22); + console.log('result23:', result23); + console.log('result24:', result24); + + if (result21?.data?.url) { + console.log('添加result21音频URL:', result21.data.url); + audioUrls.push(result21.data.url.trim()); + } + if (result22?.data?.url) { + console.log('添加result22音频URL:', result22.data.url); + audioUrls.push(result22.data.url.trim()); + } + if (result23?.data?.url) { + console.log('添加result23音频URL:', result23.data.url); + audioUrls.push(result23.data.url.trim()); + } + if (result24?.data?.url) { + console.log('添加result24音频URL:', result24.data.url); + audioUrls.push(result24.data.url.trim()); + } + + console.log('收集到的音频URLs:', audioUrls); + console.log('语音是否启用:', audioStore.isVoiceEnabled); + + // 开始轮流播放音频 + if (audioUrls.length > 0 && audioStore.isVoiceEnabled) { + console.log('开始播放音频序列'); + playAudioSequence(audioUrls); + } else { + console.log('跳过音频播放 - audioUrls长度:', audioUrls.length, '语音启用状态:', audioStore.isVoiceEnabled); + } + } }; const handleOneAPI = async () => { @@ -1238,17 +1328,7 @@ watch( // const result23 = await dbqbSecondThreeAPI(params2); // const result24 = await dbqbSecondFourAPI(params2); - // 收集所有音频URL - const audioUrls = []; - if (result21.data.url) audioUrls.push(result21.data.url.trim()); - if (result22.data.url) audioUrls.push(result22.data.url.trim()); - if (result23.data.url) audioUrls.push(result23.data.url.trim()); - if (result24.data.url) audioUrls.push(result24.data.url.trim()); - - // 开始轮流播放音频 - if (audioUrls.length > 0 && audioStore.isVoiceEnabled) { - playAudioSequence(audioUrls); - } + // 音频收集逻辑已移至checkAndExecuteInOrder函数内部 // // 修改后的消息处理逻辑 // const processedContent = marked(AIcontent.value); @@ -2935,6 +3015,9 @@ onMounted(() => { console.log("组件挂载完成"); + // 添加页面可见性变化监听器 + document.addEventListener('visibilitychange', handleVisibilityChange); + // 添加DOM变化监听器 const observer = new MutationObserver((mutations) => { mutations.forEach((mutation) => { @@ -2954,8 +3037,42 @@ onMounted(() => { observer.observe(document.body, { childList: true, subtree: true }); }); +// 页面可见性变化处理 +let wasPlayingBeforeHidden = false; + +const handleVisibilityChange = () => { + if (document.hidden) { + // 页面被隐藏时,如果音频正在播放,则暂停并记录状态 + if (audioStore.isPlaying) { + wasPlayingBeforeHidden = true; + audioStore.pause(); + console.log('页面切换离开,音频已暂停'); + } else { + wasPlayingBeforeHidden = false; + } + } else { + // 页面重新可见时,如果之前在播放,则恢复播放 + if (wasPlayingBeforeHidden && !audioStore.isPlaying) { + audioStore.play(); + console.log('页面切换回来,音频已恢复播放'); + wasPlayingBeforeHidden = false; + } + } +}; + + + // 组件卸载时清理所有图表实例和事件监听器 onUnmounted(() => { + // 移除页面可见性变化监听器 + document.removeEventListener('visibilitychange', handleVisibilityChange); + + // 停止音频播放 + if (audioStore.isPlaying) { + audioStore.stop(); + console.log('组件卸载,音频已停止'); + } + // 清理所有图表实例 Object.keys(chartInstancesMap).forEach((key) => { if (chartInstancesMap[key]) { diff --git a/src/views/AiEmotion.vue b/src/views/AiEmotion.vue index 841d31c..8fb21af 100644 --- a/src/views/AiEmotion.vue +++ b/src/views/AiEmotion.vue @@ -651,7 +651,7 @@ function startTypewriterEffect(conclusion) { }); // 添加免责声明的打字机效果(在所有模块显示完成后) - const disclaimerText = '该内容由AI生成,请注意甄别'; + const disclaimerText = '该内容由AI内容生成,请注意甄别'; // 显示免责声明模块 const showDisclaimerTimer = setTimeout(() => { @@ -795,8 +795,7 @@ async function handleSendMessage(input) { const params = { content: userMessage.text, userData: { - token: - "9ior41AF0xTIbIG2pRnnbZi0+fEeMx8pywnIlrmTwo5FbqJ9lWrSWOxp9MkpKiNtedtUafqvzIwpFKrwuMs", + token: localStorage.getItem('localToken'), language: "cn", brainPrivilegeState: "1", swordPrivilegeState: "1", @@ -824,8 +823,7 @@ async function handleSendMessage(input) { const conclusionParams = { content: input.trim(), userData: { - token: - "9ior41AF0xTIbIG2pRnnbZi0+fEeMx8pywnIlrmTwo5FbqJ9lWrSWOxp9MkpKiNtedtUafqvzIwpFKrwuMs", + token: localStorage.getItem('localToken'), language: "cn", marketList: "hk,cn,usa,my,sg,vi,in,gb", }, @@ -1109,7 +1107,7 @@ function setupIntersectionObserver() { two: conclusion.two || '', three: conclusion.three || '', four: conclusion.four || '', - disclaimer: '该内容由AI生成,请注意甄别' + disclaimer: '该内容由AI内容生成,请注意甄别' }; displayedTitles.value = { one: 'L1: 情绪监控',