|
|
@ -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); |
|
|
|