|
|
@ -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]) { |
|
|
|