diff --git a/src/views/AiEmotion.vue b/src/views/AiEmotion.vue index bedd275..33df9af 100644 --- a/src/views/AiEmotion.vue +++ b/src/views/AiEmotion.vue @@ -290,6 +290,8 @@ const typewriterTimers = ref([]); const stockTypewriterShown = ref(new Map()); // 记录每个股票是否已经播放过音频 const stockAudioPlayed = ref(new Map()); +// 存储当前的完成回调函数 +const currentOnCompleteCallback = ref(null); // 音频播放相关数据 const audioUrl = ref(''); @@ -650,6 +652,9 @@ watch(parsedConclusion, (newConclusion) => { function startTypewriterEffect(conclusion, onComplete) { console.log('开始打字机效果,结论数据:', conclusion); + // 保存当前的完成回调函数 + currentOnCompleteCallback.value = onComplete; + // 详细调试各个字段 console.log('L1字段 - one1:', conclusion.one1); console.log('L1字段 - one2:', conclusion.one2); @@ -787,6 +792,8 @@ function startTypewriterEffect(conclusion, onComplete) { // 调用完成回调,重新启用输入框 if (onComplete && typeof onComplete === 'function') { onComplete(); + // 清除保存的回调函数 + currentOnCompleteCallback.value = null; } }, 100); } @@ -914,6 +921,8 @@ async function handleSendMessage(input, onComplete) { // 调用完成回调,重新启用输入框 if (onComplete && typeof onComplete === 'function') { onComplete(); + // 清除保存的回调函数 + currentOnCompleteCallback.value = null; } return; } @@ -936,6 +945,8 @@ async function handleSendMessage(input, onComplete) { // 调用完成回调,重新启用输入框 if (onComplete && typeof onComplete === 'function') { onComplete(); + // 清除保存的回调函数 + currentOnCompleteCallback.value = null; } return; } @@ -957,6 +968,8 @@ async function handleSendMessage(input, onComplete) { // 调用完成回调,重新启用输入框 if (onComplete && typeof onComplete === 'function') { onComplete(); + // 清除保存的回调函数 + currentOnCompleteCallback.value = null; } return; } @@ -996,6 +1009,8 @@ async function handleSendMessage(input, onComplete) { // 调用完成回调,重新启用输入框 if (onComplete && typeof onComplete === 'function') { onComplete(); + // 清除保存的回调函数 + currentOnCompleteCallback.value = null; } return; } @@ -1066,6 +1081,8 @@ async function handleSendMessage(input, onComplete) { // 如果不需要打字机效果,直接调用完成回调 if (onComplete && typeof onComplete === 'function') { onComplete(); + // 清除保存的回调函数 + currentOnCompleteCallback.value = null; } } } @@ -1084,6 +1101,8 @@ async function handleSendMessage(input, onComplete) { // 调用完成回调,重新启用输入框 if (onComplete && typeof onComplete === 'function') { onComplete(); + // 清除保存的回调函数 + currentOnCompleteCallback.value = null; } return; } @@ -1096,6 +1115,8 @@ async function handleSendMessage(input, onComplete) { // 调用完成回调,重新启用输入框 if (onComplete && typeof onComplete === 'function') { onComplete(); + // 清除保存的回调函数 + currentOnCompleteCallback.value = null; } return; } finally { @@ -1653,6 +1674,13 @@ onMounted(async () => { // 组件卸载时清理定时器、音频和observer onUnmounted(() => { clearTypewriterTimers(); + + // 如果有未完成的回调函数,调用它来重新启用输入框 + if (currentOnCompleteCallback.value && typeof currentOnCompleteCallback.value === 'function') { + currentOnCompleteCallback.value(); + currentOnCompleteCallback.value = null; + } + stopAudio(); // 重置触发状态 diff --git a/src/views/homePage.vue b/src/views/homePage.vue index 41a9e2f..30c55ba 100644 --- a/src/views/homePage.vue +++ b/src/views/homePage.vue @@ -98,6 +98,10 @@ const tabs = computed(() => [ const setActiveTab = (tab, index, forceAIchat = false) => { isScrolling.value = false; //回复滚动到底部方法 isAnnouncementVisible.value = false; + + // 重置输入框禁用状态,防止页面切换时状态残留 + isInputDisabled.value = false; + if (forceAIchat && activeTab.value !== "AIchat") { activeTab.value = "AIchat"; activeIndex.value = 0;