diff --git a/src/views/AiEmotion.vue b/src/views/AiEmotion.vue index 9cd8dc0..3d1c238 100644 --- a/src/views/AiEmotion.vue +++ b/src/views/AiEmotion.vue @@ -420,10 +420,10 @@ const toggleVoiceForUser = (stock) => { const isAnyAudioPlaying = emotionAudioStore.isPlaying || currentState.isPlaying; - // 如果当前点击的股票正在播放,则暂停 + // 如果当前点击的股票正在播放,则暂停播放(不重置打字机状态) if (currentState.isPlaying) { console.log("暂停当前股票音频:", stock.stockInfo?.name); - // 暂停音频而不是停止 + // 暂停音频播放但不重置打字机状态 if (emotionAudioStore.nowSound && emotionAudioStore.nowSound.playing()) { emotionAudioStore.nowSound.pause(); emotionAudioStore.isPaused = true; @@ -431,9 +431,13 @@ const toggleVoiceForUser = (stock) => { } setStockAudioState(stock, { isPlaying: false, isPaused: true }); } else if (currentState.isPaused) { - // 如果当前股票处于暂停状态,则继续播放 + // 如果当前股票处于暂停状态,则继续播放(不重置打字机状态) console.log("继续播放当前股票音频:", stock.stockInfo?.name); if (emotionAudioStore.nowSound) { + // 从暂停位置继续播放,不重新开始 + if (emotionAudioStore.playbackPosition > 0) { + emotionAudioStore.nowSound.seek(emotionAudioStore.playbackPosition); + } emotionAudioStore.nowSound.play(); emotionAudioStore.isPaused = false; emotionAudioStore.isPlaying = true; @@ -958,9 +962,20 @@ const isStockStateReady = (stock) => { const isFirstTime = !stockTypewriterShown.value.has(stockUniqueId); - // 如果是第一次且用户主动搜索,需要确保打字机状态已初始化 + // 如果是第一次且用户主动搜索,提前初始化状态并返回true if (isFirstTime && isUserInitiated.value) { - return stockTypewriterTexts.value.has(stockUniqueId) && stockTypewriterVisibility.value.has(stockUniqueId); + // 提前初始化打字机状态,避免渲染时的状态闪烁 + if (!stockTypewriterTexts.value.has(stockUniqueId)) { + stockTypewriterTexts.value.set(stockUniqueId, { + one1: "", one2: "", two: "", three: "", four: "", disclaimer: "" + }); + } + if (!stockTypewriterVisibility.value.has(stockUniqueId)) { + stockTypewriterVisibility.value.set(stockUniqueId, { + one: false, two: false, three: false, four: false, disclaimer: false + }); + } + return true; } // 其他情况下,只要有结论数据就可以显示 @@ -1583,15 +1598,19 @@ const playNextAudio = () => { console.log('设置当前股票音频状态为播放中:', currentStock.stockInfo?.name); } - // 如果是第一个音频且需要启动打字机效果,则启动 + // 如果是第一个音频且需要启动打字机效果,且不是从暂停状态恢复播放,则启动 if ( currentPlayIndex === 0 && audioInfo.shouldStartTypewriter && - parsedConclusion.value + parsedConclusion.value && + !emotionAudioStore.isPaused && // 不是从暂停状态恢复 + emotionAudioStore.playbackPosition === 0 // 从头开始播放 ) { console.log("🎬 第一个音频开始播放,同时启动打字机效果"); const stockId = currentStock ? getStockUniqueId(currentStock) : null; startTypewriterEffect(parsedConclusion.value, stockId, audioInfo.onComplete); + } else if (currentPlayIndex === 0 && audioInfo.shouldStartTypewriter) { + console.log("🔄 从暂停状态恢复播放,不重新启动打字机效果"); } }, onpause: () => { @@ -2356,29 +2375,12 @@ async function handleSendMessage(input, onComplete) { // 将结论数据存储到store中的当前激活股票 emotionStore.updateActiveStockConclusion(conclusionResponse.data); - // 确保状态在页面显示前已正确设置 + // 状态初始化现在由isStockStateReady方法自动处理,避免重复设置 const stockUniqueId = getStockUniqueId(parsedData); if (stockUniqueId) { - const isFirstTime = !stockTypewriterShown.value.has(stockUniqueId); - if (isFirstTime && isUserInitiated.value) { - // 确保打字机状态已正确初始化 - console.log('初始化打字机状态:', parsedData.name); - stockTypewriterTexts.value.set(stockUniqueId, { - one1: "", one2: "", two: "", three: "", four: "", disclaimer: "" - }); - stockTypewriterVisibility.value.set(stockUniqueId, { - one: false, two: false, three: false, four: false, disclaimer: false - }); - } else { - // 确保完整显示模式的状态已清理 - console.log('设置完整显示模式:', parsedData.name); - stockTypewriterTexts.value.delete(stockUniqueId); - stockTypewriterVisibility.value.delete(stockUniqueId); - } - - // 强制触发响应式更新 + // 强制触发响应式更新,确保状态准备就绪 nextTick(() => { - console.log('状态设置完成,股票状态准备就绪:', parsedData.name, 'isReady:', isStockStateReady(parsedData)); + console.log('数据加载完成,股票状态准备就绪:', parsedData.name, 'isReady:', isStockStateReady(parsedData)); }); }