Browse Source

解决情绪大模型搜索相同股票时互相影响的问题。

dev
宋杰 21 hours ago
parent
commit
c86ea9cb3f
  1. 129
      src/views/AiEmotion.vue

129
src/views/AiEmotion.vue

@ -624,11 +624,10 @@ const addStock = (stockData) => {
// 4. // 4.
if (stockData.conclusionData) { if (stockData.conclusionData) {
const stockCode =
stockData.stockInfo?.code || stockData.stockInfo?.symbol;
if (stockCode) {
stockTypewriterShown.value.set(stockCode, true);
stockAudioPlayed.value.set(stockCode, true);
const stockUniqueId = getStockUniqueId(stockData);
if (stockUniqueId) {
stockTypewriterShown.value.set(stockUniqueId, true);
stockAudioPlayed.value.set(stockUniqueId, true);
} }
console.log("历史记录股票已标记为已显示"); console.log("历史记录股票已标记为已显示");
} }
@ -688,6 +687,13 @@ const stockTypewriterVisibility = ref(new Map());
const stockAudioPlayed = ref(new Map()); const stockAudioPlayed = ref(new Map());
// //
const stockAudioStates = ref(new Map()); const stockAudioStates = ref(new Map());
//
const getStockUniqueId = (stock) => {
const stockCode = stock.stockInfo?.code || stock.stockInfo?.symbol;
const timestamp = stock.timestamp;
return stockCode && timestamp ? `${stockCode}_${timestamp}` : stockCode;
};
// //
const currentOnCompleteCallback = ref(null); const currentOnCompleteCallback = ref(null);
@ -697,11 +703,11 @@ const isAudioPlaying = ref(false);
// //
const getStockAudioState = (stock) => { const getStockAudioState = (stock) => {
const stockCode = stock.stockInfo?.code || stock.stockInfo?.symbol;
if (!stockCode) return { isPlaying: false, isPaused: false };
const stockUniqueId = getStockUniqueId(stock);
if (!stockUniqueId) return { isPlaying: false, isPaused: false };
return ( return (
stockAudioStates.value.get(stockCode) || {
stockAudioStates.value.get(stockUniqueId) || {
isPlaying: false, isPlaying: false,
isPaused: false, isPaused: false,
} }
@ -710,10 +716,10 @@ const getStockAudioState = (stock) => {
// //
const setStockAudioState = (stock, state) => { const setStockAudioState = (stock, state) => {
const stockCode = stock.stockInfo?.code || stock.stockInfo?.symbol;
if (!stockCode) return;
const stockUniqueId = getStockUniqueId(stock);
if (!stockUniqueId) return;
stockAudioStates.value.set(stockCode, { ...state });
stockAudioStates.value.set(stockUniqueId, { ...state });
}; };
// //
@ -735,6 +741,10 @@ const stockCode = computed(
currentStock.value?.stockInfo.symbol || currentStock.value?.stockInfo.symbol ||
"" ""
); );
const currentStockUniqueId = computed(() => {
if (!currentStock.value) return "";
return getStockUniqueId(currentStock.value);
});
const displayDate = computed(() => { const displayDate = computed(() => {
if (!currentStock.value?.apiData) return ""; if (!currentStock.value?.apiData) return "";
const lastData = currentStock.value.apiData.GSWDJ?.at(-1); const lastData = currentStock.value.apiData.GSWDJ?.at(-1);
@ -855,23 +865,23 @@ const getStockConclusion = (stock) => {
// //
const getStockTypewriterTexts = (stock) => { const getStockTypewriterTexts = (stock) => {
const stockCode = stock.stockInfo?.code || stock.stockInfo?.symbol;
if (!stockCode) return null;
return stockTypewriterTexts.value.get(stockCode) || null;
const stockUniqueId = getStockUniqueId(stock);
if (!stockUniqueId) return null;
return stockTypewriterTexts.value.get(stockUniqueId) || null;
}; };
// //
const getStockTypewriterVisibility = (stock) => { const getStockTypewriterVisibility = (stock) => {
const stockCode = stock.stockInfo?.code || stock.stockInfo?.symbol;
if (!stockCode) return null;
return stockTypewriterVisibility.value.get(stockCode) || null;
const stockUniqueId = getStockUniqueId(stock);
if (!stockUniqueId) return null;
return stockTypewriterVisibility.value.get(stockUniqueId) || null;
}; };
// //
const isStockTypewriting = (stock) => { const isStockTypewriting = (stock) => {
const stockCode = stock.stockInfo?.code || stock.stockInfo?.symbol;
if (!stockCode) return false;
return stockTypewriterShown.value.has(stockCode) && !stockTypewriterTexts.value.has(stockCode);
const stockUniqueId = getStockUniqueId(stock);
if (!stockUniqueId) return false;
return stockTypewriterShown.value.has(stockUniqueId) && !stockTypewriterTexts.value.has(stockUniqueId);
}; };
// //
@ -929,8 +939,8 @@ watch(
hasTriggeredAudio.value = false; hasTriggeredAudio.value = false;
hasTriggeredTypewriter.value = false; hasTriggeredTypewriter.value = false;
//
const stockCode = newStock.stockInfo?.code || newStock.stockInfo?.symbol;
//
const stockUniqueId = getStockUniqueId(newStock);
// URL // URL
if (newStock.conclusionData) { if (newStock.conclusionData) {
@ -942,7 +952,7 @@ watch(
: JSON.parse(newStock.conclusionData); : JSON.parse(newStock.conclusionData);
// //
if (stockCode && stockTypewriterShown.value.has(stockCode)) {
if (stockUniqueId && stockTypewriterShown.value.has(stockUniqueId)) {
// //
// URL // URL
@ -1037,11 +1047,8 @@ watch(
} }
if (parsedConclusion.value) { if (parsedConclusion.value) {
const stockCode =
newStock.stockInfo?.code || newStock.stockInfo?.symbol;
// //
if (stockCode && stockTypewriterShown.value.has(stockCode)) {
if (stockUniqueId && stockTypewriterShown.value.has(stockUniqueId)) {
return; return;
} }
@ -1052,9 +1059,9 @@ watch(
if (isInViewport) { if (isInViewport) {
console.log("股票切换后检测到场景应用部分在视口中"); console.log("股票切换后检测到场景应用部分在视口中");
if (stockCode) {
if (stockUniqueId) {
// //
if (!stockTypewriterShown.value.has(stockCode)) {
if (!stockTypewriterShown.value.has(stockUniqueId)) {
// //
if (isUserInitiated.value && audioUrl.value) { if (isUserInitiated.value && audioUrl.value) {
console.log( console.log(
@ -1063,16 +1070,16 @@ watch(
hasTriggeredTypewriter.value = true; hasTriggeredTypewriter.value = true;
hasTriggeredAudio.value = true; hasTriggeredAudio.value = true;
if (!stockAudioPlayed.value.has(stockCode)) {
if (!stockAudioPlayed.value.has(stockUniqueId)) {
console.log("开始音频播放和打字机效果"); console.log("开始音频播放和打字机效果");
stockAudioPlayed.value.set(stockCode, true);
stockAudioPlayed.value.set(stockUniqueId, true);
playAudioQueue(parsedConclusion.value, true); playAudioQueue(parsedConclusion.value, true);
} else { } else {
// //
startTypewriterEffect(parsedConclusion.value, stockCode);
startTypewriterEffect(parsedConclusion.value, stockUniqueId);
} }
stockTypewriterShown.value.set(stockCode, true);
stockTypewriterShown.value.set(stockUniqueId, true);
} else if (isUserInitiated.value && !audioUrl.value) { } else if (isUserInitiated.value && !audioUrl.value) {
console.log( console.log(
"音频尚未准备好,等待音频加载完成后再触发效果(股票切换后)" "音频尚未准备好,等待音频加载完成后再触发效果(股票切换后)"
@ -1087,8 +1094,8 @@ watch(
const conclusion = parsedConclusion.value; const conclusion = parsedConclusion.value;
// parsedConclusion // parsedConclusion
stockTypewriterShown.value.set(stockCode, true);
stockAudioPlayed.value.set(stockCode, true);
stockTypewriterShown.value.set(stockUniqueId, true);
stockAudioPlayed.value.set(stockUniqueId, true);
} }
} else { } else {
// //
@ -1218,10 +1225,9 @@ watch(
// //
function startTypewriterEffect(conclusion, stockId, onComplete) { function startTypewriterEffect(conclusion, stockId, onComplete) {
// stockId使
// stockId使
if (!stockId && emotionStore.activeStock) { if (!stockId && emotionStore.activeStock) {
const stock = emotionStore.activeStock;
stockId = stock.stockInfo?.code || stock.stockInfo?.symbol;
stockId = getStockUniqueId(emotionStore.activeStock);
} }
if (!stockId) { if (!stockId) {
@ -1501,7 +1507,7 @@ const playNextAudio = () => {
parsedConclusion.value parsedConclusion.value
) { ) {
console.log("🎬 第一个音频开始播放,同时启动打字机效果"); console.log("🎬 第一个音频开始播放,同时启动打字机效果");
const stockId = currentStock?.stockInfo?.code || currentStock?.stockInfo?.symbol;
const stockId = currentStock ? getStockUniqueId(currentStock) : null;
startTypewriterEffect(parsedConclusion.value, stockId, audioInfo.onComplete); startTypewriterEffect(parsedConclusion.value, stockId, audioInfo.onComplete);
} }
}, },
@ -1766,7 +1772,7 @@ function playAudioQueue(
if (shouldStartTypewriter) { if (shouldStartTypewriter) {
console.log("没有音频但需要启动打字机效果"); console.log("没有音频但需要启动打字机效果");
const currentStock = emotionStore.activeStock; const currentStock = emotionStore.activeStock;
const stockId = currentStock?.stockInfo?.code || currentStock?.stockInfo?.symbol;
const stockId = currentStock ? getStockUniqueId(currentStock) : null;
startTypewriterEffect(conclusion, stockId, onComplete); startTypewriterEffect(conclusion, stockId, onComplete);
} }
} else { } else {
@ -2229,19 +2235,16 @@ async function handleSendMessage(input, onComplete) {
parsedConclusion.value && parsedConclusion.value &&
audioUrl.value audioUrl.value
) { ) {
const stockCode =
currentStock.value.stockInfo?.code ||
currentStock.value.stockInfo?.symbol;
if (stockCode && !stockTypewriterShown.value.has(stockCode)) {
if (!stockAudioPlayed.value.has(stockCode)) {
stockAudioPlayed.value.set(stockCode, true);
const stockUniqueId = getStockUniqueId(currentStock.value);
if (stockUniqueId && !stockTypewriterShown.value.has(stockUniqueId)) {
if (!stockAudioPlayed.value.has(stockUniqueId)) {
stockAudioPlayed.value.set(stockUniqueId, true);
playAudioQueue(parsedConclusion.value, true, onComplete); playAudioQueue(parsedConclusion.value, true, onComplete);
} else { } else {
// //
const stockCode = currentStock.value?.stockInfo?.code || currentStock.value?.stockInfo?.symbol;
startTypewriterEffect(parsedConclusion.value, stockCode, onComplete);
startTypewriterEffect(parsedConclusion.value, stockUniqueId, onComplete);
} }
stockTypewriterShown.value.set(stockCode, true);
stockTypewriterShown.value.set(stockUniqueId, true);
} else { } else {
// //
if (onComplete && typeof onComplete === "function") { if (onComplete && typeof onComplete === "function") {
@ -2899,14 +2902,12 @@ function setupIntersectionObserver() {
if (entry.isIntersecting) { if (entry.isIntersecting) {
console.log("场景应用部分进入视口"); console.log("场景应用部分进入视口");
//
const stockCode =
currentStock.value?.stockInfo?.code ||
currentStock.value?.stockInfo?.symbol;
//
const stockUniqueId = currentStock.value ? getStockUniqueId(currentStock.value) : null;
if (parsedConclusion.value && stockCode) {
if (parsedConclusion.value && stockUniqueId) {
// //
if (!stockTypewriterShown.value.has(stockCode)) {
if (!stockTypewriterShown.value.has(stockUniqueId)) {
// //
if (isUserInitiated.value && audioUrl.value) { if (isUserInitiated.value && audioUrl.value) {
console.log( console.log(
@ -2915,10 +2916,10 @@ function setupIntersectionObserver() {
// //
console.log("开始音频播放和打字机效果"); console.log("开始音频播放和打字机效果");
stockAudioPlayed.value.set(stockCode, true);
stockAudioPlayed.value.set(stockUniqueId, true);
playAudioQueue(parsedConclusion.value, true); playAudioQueue(parsedConclusion.value, true);
stockTypewriterShown.value.set(stockCode, true);
stockTypewriterShown.value.set(stockUniqueId, true);
} else { } else {
// //
console.log( console.log(
@ -2928,8 +2929,8 @@ function setupIntersectionObserver() {
// parsedConclusion // parsedConclusion
// //
stockTypewriterShown.value.set(stockCode, true);
stockAudioPlayed.value.set(stockCode, true);
stockTypewriterShown.value.set(stockUniqueId, true);
stockAudioPlayed.value.set(stockUniqueId, true);
} }
} else { } else {
// //
@ -3257,12 +3258,10 @@ onMounted(async () => {
conclusionData.value = currentStockData.conclusionData; conclusionData.value = currentStockData.conclusionData;
// //
const stockCode =
currentStockData.stockInfo?.code ||
currentStockData.stockInfo?.symbol;
if (stockCode) {
stockTypewriterShown.value.set(stockCode, true);
stockAudioPlayed.value.set(stockCode, true);
const stockUniqueId = getStockUniqueId(currentStockData);
if (stockUniqueId) {
stockTypewriterShown.value.set(stockUniqueId, true);
stockAudioPlayed.value.set(stockUniqueId, true);
} }
} }
} }

Loading…
Cancel
Save