From ba3d683f3c439e37d2faac9ba2d53c6fe1404f98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=8B=E6=9D=B0?= Date: Thu, 21 Aug 2025 16:16:24 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E7=BB=93=E8=AE=BA=E5=85=88?= =?UTF-8?q?=E5=85=A8=E9=83=A8=E5=87=BA=E7=8E=B0=E5=90=8E=E6=89=93=E5=AD=97?= =?UTF-8?q?=E6=9C=BA=E7=9A=84=E9=97=AE=E9=A2=98=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/AiEmotion.vue | 61 ++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 48 insertions(+), 13 deletions(-) diff --git a/src/views/AiEmotion.vue b/src/views/AiEmotion.vue index e7dbaa9..effd541 100644 --- a/src/views/AiEmotion.vue +++ b/src/views/AiEmotion.vue @@ -694,9 +694,15 @@ const stockAudioStates = ref(new Map()); // 生成股票唯一标识符的辅助函数 const getStockUniqueId = (stock) => { + // 优先使用预设的uniqueId + if (stock.uniqueId) { + return stock.uniqueId; + } + + // 兼容旧的生成方式 const stockCode = stock.stockInfo?.code || stock.stockInfo?.symbol; const timestamp = stock.timestamp; - return stockCode && timestamp ? `${stockCode}_${timestamp}` : stockCode; + return stockCode && timestamp ? `${stockCode}_${timestamp}` : null; }; // 存储当前的完成回调函数 const currentOnCompleteCallback = ref(null); @@ -943,7 +949,7 @@ watch( hasTriggeredAudio.value = false; hasTriggeredTypewriter.value = false; - // 获取股票唯一标识 + // 获取股票唯一标识(使用预设的uniqueId) const stockUniqueId = getStockUniqueId(newStock); // 处理当前股票的音频URL @@ -955,10 +961,10 @@ watch( ? newStock.conclusionData : JSON.parse(newStock.conclusionData); - // 检查该股票是否已经显示过打字机效果 - if (stockUniqueId && stockTypewriterShown.value.has(stockUniqueId)) { - // 如果已经显示过,直接显示完整内容,不需要打字机效果 - + // 基于预设状态处理音频URL + const shouldShowTypewriter = stockUniqueId && stockTypewriterTexts.value.has(stockUniqueId); + + if (!shouldShowTypewriter) { // 提取音频URL但不自动播放,等待用户手动点击 let voiceUrl = null; // 优先使用one1_url,如果没有则尝试其他音频URL @@ -2176,16 +2182,44 @@ async function handleSendMessage(input, onComplete) { }; console.log("第二个接口参数:", conclusionParams); + // 在Promise.all调用前添加股票唯一标识生成和判断逻辑 + const stockUniqueId = `${parsedData.code}_${parsedData.market}_${new Date().toISOString()}`; + 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); + + // 如果是第一次但非用户主动搜索,标记为已显示 + if (isFirstTime) { + stockTypewriterShown.value.set(stockUniqueId, true); + stockAudioPlayed.value.set(stockUniqueId, true); + } + } + // 同时调用第二个数据流接口和fetchData方法 const [conclusionResult, fetchDataResult] = await Promise.all([ getConclusionAPI(conclusionParams), fetchData( - parsedData.code, - parsedData.market, - parsedData.name || "未知股票", - input.trim(), - parsedData.stockId - ), + parsedData.code, + parsedData.market, + parsedData.name || "未知股票", + input.trim(), + parsedData.stockId, + stockUniqueId // 传递预生成的唯一标识 + ), ]); // 处理结论接口返回的数据 @@ -2436,7 +2470,7 @@ async function handleSendMessage(input, onComplete) { } // 请求数据接口 -async function fetchData(code, market, stockName, queryText, stockId) { +async function fetchData(code, market, stockName, queryText, stockId, presetUniqueId = null) { try { const stockDataParams = { stockId: stockId, @@ -2516,6 +2550,7 @@ async function fetchData(code, market, stockName, queryText, stockId) { apiData: stockDataResponse.data, conclusionData: conclusionData.value, // 包含结论数据 timestamp: new Date().toISOString(), + uniqueId: presetUniqueId || `${code}_${market}_${new Date().toISOString()}`, // 添加唯一标识 }; // 将股票数据添加到store中,显示在StockTabs中 emotionStore.addStock(stockData);