From 5396ffc7b0f2d63573b99bb496bee23fa9709028 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=8B=E6=9D=B0?= Date: Fri, 4 Jul 2025 15:29:01 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=BA=E5=AE=9D=E5=A5=87=E5=85=B5=E9=9F=B3?= =?UTF-8?q?=E9=A2=91=E9=87=8D=E6=96=B0=E6=92=AD=E6=94=BE=E5=8F=AA=E6=92=AD?= =?UTF-8?q?=E6=94=BE=E7=AC=AC=E5=9B=9B=E4=B8=AA=E9=97=AE=E9=A2=98=E8=A7=A3?= =?UTF-8?q?=E5=86=B3=EF=BC=9B=E6=89=93=E5=AD=97=E6=9C=BA=E9=80=9F=E5=BA=A6?= =?UTF-8?q?=E4=B8=8E=E9=9F=B3=E9=A2=91=E5=AF=B9=E5=BA=94=EF=BC=9B=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E6=83=85=E7=BB=AA=E5=A4=A7=E6=A8=A1=E5=9E=8B=E6=97=A5?= =?UTF-8?q?=E6=9C=9F=E6=A0=BC=E5=BC=8F=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/AIchat.vue | 120 ++++++++++++++++++++++++++++++++++++++++-------- src/views/AiEmotion.vue | 15 +++++- 2 files changed, 115 insertions(+), 20 deletions(-) diff --git a/src/views/AIchat.vue b/src/views/AIchat.vue index aca0296..a56cab2 100644 --- a/src/views/AIchat.vue +++ b/src/views/AIchat.vue @@ -717,18 +717,37 @@ watch( // 播放音频队列 // 防止重复调用的标志 let isCallingPlayNext = false; + // 当前播放索引 + let currentPlayIndex = 0; const playNextAudio = () => { + console.log('=== playNextAudio 被调用 ==='); + console.log('当前队列状态:', { + queueLength: audioQueue.value.length, + queueItems: audioQueue.value.map(item => item.name), + currentPlayIndex: currentPlayIndex, + isPlayingAudio: isPlayingAudio.value, + isCallingPlayNext: isCallingPlayNext, + audioStoreIsPlaying: audioStore.isPlaying + }); + if (audioQueue.value.length === 0 || isPlayingAudio.value || isCallingPlayNext) { - console.log('播放条件不满足 - 队列长度:', audioQueue.value.length, '正在播放:', isPlayingAudio.value, '正在调用:', isCallingPlayNext); + console.log('❌ 播放条件不满足 - 队列长度:', audioQueue.value.length, '正在播放:', isPlayingAudio.value, '正在调用:', isCallingPlayNext); return; } + // 检查是否已播放完所有音频(仅在队列不为空时重置) + if (currentPlayIndex >= audioQueue.value.length && audioQueue.value.length > 0) { + console.log('🔄 所有音频播放完成,重置索引从第一个开始'); + currentPlayIndex = 0; + } + isCallingPlayNext = true; isPlayingAudio.value = true; - const audioInfo = audioQueue.value.shift(); + const audioInfo = audioQueue.value[currentPlayIndex]; - console.log(`开始播放${audioInfo.name}音频,剩余队列:`, audioQueue.value.length); + console.log(`✅ 开始播放${audioInfo.name}音频 (索引:${currentPlayIndex}),队列总长度:`, audioQueue.value.length); + console.log('完整队列内容:', audioQueue.value.map((item, index) => `${index === currentPlayIndex ? '▶️' : '⏸️'} ${item.name}`)); // 只有在确实需要停止时才停止之前的音频 if (audioStore.nowSound && (audioStore.nowSound.playing() || audioStore.nowSound.state() === 'loading')) { @@ -744,6 +763,7 @@ watch( onplay: () => { audioStore.isPlaying = true; audioStore.isPaused = false; + isPlayingAudio.value = true; // 确保状态同步 isCallingPlayNext = false; // 重置调用标志 console.log(`${audioInfo.name}音频开始播放,时长:`, audio.duration()); console.log('音频播放状态确认 - isPlayingAudio:', isPlayingAudio.value, 'audioStore.isPlaying:', audioStore.isPlaying); @@ -761,21 +781,27 @@ watch( }, onend: () => { console.log(`${audioInfo.name}音频播放完成,准备播放下一个`); - console.log('播放完成时的状态 - 队列长度:', audioQueue.value.length, 'isPlayingAudio:', isPlayingAudio.value); + console.log('播放完成时的状态 - 当前索引:', currentPlayIndex, '队列长度:', audioQueue.value.length, 'isPlayingAudio:', isPlayingAudio.value); audioStore.isPlaying = false; audioStore.isPaused = false; audioStore.playbackPosition = 0; isPlayingAudio.value = false; + // 移动到下一个音频索引 + currentPlayIndex++; + // 确保只有在音频真正播放完成时才播放下一个 - if (audioQueue.value.length > 0) { - console.log('队列中还有音频,500ms后播放下一个,当前队列:', audioQueue.value.map(item => item.name)); + if (currentPlayIndex < audioQueue.value.length) { + console.log(`队列中还有音频,500ms后播放下一个 (索引:${currentPlayIndex}),当前队列:`, audioQueue.value.map((item, index) => `${index === currentPlayIndex ? '▶️' : '⏸️'} ${item.name}`)); setTimeout(() => { isCallingPlayNext = false; // 在调用前重置标志 playNextAudio(); }, 500); } else { - console.log('所有音频播放完成'); + console.log('🎉 所有音频播放完成,清除音频实例,队列保持完整,下次播放将从第一个开始'); + // 清除音频实例,确保重新播放时不会使用旧实例 + audioStore.nowSound = null; + audioStore.soundInstance = null; isCallingPlayNext = false; // 重置调用标志 } }, @@ -865,8 +891,10 @@ watch( console.log('当前音频状态 - isPlaying:', audioStore.isPlaying, 'isPaused:', audioStore.isPaused); console.log('当前音频实例:', audioStore.soundInstance); console.log('队列播放状态 - isPlayingAudio:', isPlayingAudio.value, '队列长度:', audioQueue.value.length); + console.log('当前播放索引:', currentPlayIndex, '是否所有音频播放完成:', currentPlayIndex >= audioQueue.value.length); - if (audioStore.soundInstance) { + // 检查是否所有音频都播放完成,如果是则重新开始 + if (audioStore.soundInstance && currentPlayIndex < audioQueue.value.length && isPlayingAudio.value) { if (audioStore.isPlaying) { // 暂停当前音频 console.log('暂停当前音频'); @@ -883,23 +911,77 @@ watch( } } else { console.log('没有音频实例,检查是否需要重新播放队列'); + console.log('重新播放条件检查:', { + isPlayingAudio: isPlayingAudio.value, + queueLength: audioQueue.value.length, + currentPlayIndex: currentPlayIndex, + condition1: audioQueue.value.length === 0, + condition2: currentPlayIndex >= audioQueue.value.length, + finalCondition: !isPlayingAudio.value && (audioQueue.value.length === 0 || currentPlayIndex >= audioQueue.value.length) + }); // 没有音频实例时,检查是否所有音频都播放完成 - if (!isPlayingAudio.value && audioQueue.value.length === 0) { + if (!isPlayingAudio.value && (audioQueue.value.length === 0 || currentPlayIndex >= audioQueue.value.length)) { console.log('所有音频播放完成,重新构建队列从第一个开始播放'); - // 重新构建音频队列,按顺序添加所有音频 + // 重新构建音频队列,按顺序添加所有音频(不自动播放) + const audioItems = []; if (audioPreloadStatus.one.url) { - addToAudioQueue(audioPreloadStatus.one.url, "API1-第一个"); + audioItems.push({ url: audioPreloadStatus.one.url, name: "API1-第一个", order: 1 }); } if (audioPreloadStatus.two.url) { - addToAudioQueue(audioPreloadStatus.two.url, "API2-第二个"); + audioItems.push({ url: audioPreloadStatus.two.url, name: "API2-第二个", order: 2 }); } if (audioPreloadStatus.three.url) { - addToAudioQueue(audioPreloadStatus.three.url, "API3-第三个"); + audioItems.push({ url: audioPreloadStatus.three.url, name: "API3-第三个", order: 3 }); } if (audioPreloadStatus.four.url) { - addToAudioQueue(audioPreloadStatus.four.url, "API4-第四个"); + audioItems.push({ url: audioPreloadStatus.four.url, name: "API4-第四个", order: 4 }); + } + + // 按顺序排序并添加到队列 + audioItems.sort((a, b) => a.order - b.order); + audioQueue.value = audioItems; + + console.log('队列重建完成,队列内容:', audioQueue.value.map(item => item.name)); + console.log('开始从第一个音频播放'); + + // 重置播放状态并开始播放第一个音频 + if (audioQueue.value.length > 0) { + // 完全重置所有播放相关状态 + isPlayingAudio.value = false; + isCallingPlayNext = false; + currentPlayIndex = 0; // 重置播放索引到第一个音频 + audioStore.isPlaying = false; + audioStore.isPaused = false; + audioStore.playbackPosition = 0; + audioStore.nowSound = null; + audioStore.soundInstance = null; + + console.log('🔄 状态完全重置完成,准备从第一个音频开始播放'); + + console.log('✅ 完全重置播放状态,准备播放第一个音频'); + console.log('重置后状态检查:', { + isPlayingAudio: isPlayingAudio.value, + isCallingPlayNext: isCallingPlayNext, + currentPlayIndex: currentPlayIndex, + audioStoreIsPlaying: audioStore.isPlaying, + queueLength: audioQueue.value.length + }); + + setTimeout(() => { + console.log('🚀 延迟后开始播放第一个音频'); + console.log('播放前最终状态检查:', { + currentPlayIndex: currentPlayIndex, + queueLength: audioQueue.value.length, + queueItems: audioQueue.value.map((item, index) => `${index}: ${item.name}`), + isPlayingAudio: isPlayingAudio.value, + isCallingPlayNext: isCallingPlayNext, + audioStoreIsPlaying: audioStore.isPlaying, + audioStoreInstance: !!audioStore.soundInstance + }); + console.log('🎯 即将调用 playNextAudio,期望播放:', audioQueue.value[currentPlayIndex]?.name || '无音频'); + playNextAudio(); + }, 200); } - console.log('队列重建完成,开始从第一个音频播放'); } else if (!isPlayingAudio.value && audioQueue.value.length > 0) { console.log('队列中还有音频,继续播放'); playNextAudio(); @@ -1342,7 +1424,7 @@ watch( // } // }, 50); // 调整速度为50ms/字符 - addTypingTask(aiMessage3, [ac31, ac32], 180); + addTypingTask(aiMessage3, [ac31, ac32], 200); // chatStore.messages.push({ // sender: "ai", @@ -1423,7 +1505,7 @@ watch( addTypingTask( aiMessage4, [ac41, ac42, ac43, ac44, ac45, ac46, ac47, ac48], - 180 + 200 ); // chatStore.messages.push({ @@ -1508,7 +1590,7 @@ watch( // } // }, 50); // 调整速度为50ms/字符 - addTypingTask(aiMessage5, [ac51, ac52, ac53, ac54], 180); + addTypingTask(aiMessage5, [ac51, ac52, ac53, ac54], 240); // chatStore.messages.push({ // sender: "ai", @@ -1539,7 +1621,7 @@ watch( // } // }, 50); // 调整速度为50ms/字符 - addTypingTask(aiMessage6, ["", ac6], 180); + addTypingTask(aiMessage6, ["", ac6], 210); // chatStore.messages.push({ // sender: "ai", diff --git a/src/views/AiEmotion.vue b/src/views/AiEmotion.vue index ca207e3..a185d4c 100644 --- a/src/views/AiEmotion.vue +++ b/src/views/AiEmotion.vue @@ -291,7 +291,19 @@ const stockName = computed(() => currentStock.value?.stockInfo.name || ""); const displayDate = computed(() => { if (!currentStock.value?.apiData) return ""; const lastData = currentStock.value.apiData.GSWDJ?.at(-1); - return lastData ? lastData[0] : ""; + if (!lastData || !lastData[0]) return ""; + + const dateStr = lastData[0]; + // 假设原格式为 YYYY-MM-DD 或 YYYY/MM/DD + const dateMatch = dateStr.match(/(\d{4})[\-\/](\d{1,2})[\-\/](\d{1,2})/); + if (dateMatch) { + const [, year, month, day] = dateMatch; + // 转换为 DD/MM/YYYY 格式 + return `更新时间:${day.padStart(2, '0')}/${month.padStart(2, '0')}/${year}`; + } + + // 如果不匹配预期格式,返回原始值 + return dateStr; }); const data1 = computed(() => { if (!currentStock.value?.apiData) return null; @@ -2004,6 +2016,7 @@ defineExpose({ .span02 { font-size: 1.5rem; + font-weight: bold; color: white; float: right; margin-top: -2%;