2 Commits

  1. 139
      src/views/AiEmotion.vue

139
src/views/AiEmotion.vue

@ -624,11 +624,10 @@ const addStock = (stockData) => {
// 4.
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("历史记录股票已标记为已显示");
}
@ -688,6 +687,13 @@ const stockTypewriterVisibility = ref(new Map());
const stockAudioPlayed = 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);
@ -697,11 +703,11 @@ const isAudioPlaying = ref(false);
//
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 (
stockAudioStates.value.get(stockCode) || {
stockAudioStates.value.get(stockUniqueId) || {
isPlaying: false,
isPaused: false,
}
@ -710,10 +716,10 @@ const getStockAudioState = (stock) => {
//
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 ||
""
);
const currentStockUniqueId = computed(() => {
if (!currentStock.value) return "";
return getStockUniqueId(currentStock.value);
});
const displayDate = computed(() => {
if (!currentStock.value?.apiData) return "";
const lastData = currentStock.value.apiData.GSWDJ?.at(-1);
@ -855,23 +865,23 @@ const getStockConclusion = (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 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 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;
hasTriggeredTypewriter.value = false;
//
const stockCode = newStock.stockInfo?.code || newStock.stockInfo?.symbol;
//
const stockUniqueId = getStockUniqueId(newStock);
// URL
if (newStock.conclusionData) {
@ -942,7 +952,7 @@ watch(
: JSON.parse(newStock.conclusionData);
//
if (stockCode && stockTypewriterShown.value.has(stockCode)) {
if (stockUniqueId && stockTypewriterShown.value.has(stockUniqueId)) {
//
// URL
@ -1037,11 +1047,8 @@ watch(
}
if (parsedConclusion.value) {
const stockCode =
newStock.stockInfo?.code || newStock.stockInfo?.symbol;
//
if (stockCode && stockTypewriterShown.value.has(stockCode)) {
if (stockUniqueId && stockTypewriterShown.value.has(stockUniqueId)) {
return;
}
@ -1052,9 +1059,9 @@ watch(
if (isInViewport) {
console.log("股票切换后检测到场景应用部分在视口中");
if (stockCode) {
if (stockUniqueId) {
//
if (!stockTypewriterShown.value.has(stockCode)) {
if (!stockTypewriterShown.value.has(stockUniqueId)) {
//
if (isUserInitiated.value && audioUrl.value) {
console.log(
@ -1063,16 +1070,16 @@ watch(
hasTriggeredTypewriter.value = true;
hasTriggeredAudio.value = true;
if (!stockAudioPlayed.value.has(stockCode)) {
if (!stockAudioPlayed.value.has(stockUniqueId)) {
console.log("开始音频播放和打字机效果");
stockAudioPlayed.value.set(stockCode, true);
stockAudioPlayed.value.set(stockUniqueId, true);
playAudioQueue(parsedConclusion.value, true);
} 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) {
console.log(
"音频尚未准备好,等待音频加载完成后再触发效果(股票切换后)"
@ -1087,8 +1094,8 @@ watch(
const conclusion = parsedConclusion.value;
// parsedConclusion
stockTypewriterShown.value.set(stockCode, true);
stockAudioPlayed.value.set(stockCode, true);
stockTypewriterShown.value.set(stockUniqueId, true);
stockAudioPlayed.value.set(stockUniqueId, true);
}
} else {
//
@ -1218,10 +1225,9 @@ watch(
//
function startTypewriterEffect(conclusion, stockId, onComplete) {
// stockId使
// stockId使
if (!stockId && emotionStore.activeStock) {
const stock = emotionStore.activeStock;
stockId = stock.stockInfo?.code || stock.stockInfo?.symbol;
stockId = getStockUniqueId(emotionStore.activeStock);
}
if (!stockId) {
@ -1501,7 +1507,7 @@ const playNextAudio = () => {
parsedConclusion.value
) {
console.log("🎬 第一个音频开始播放,同时启动打字机效果");
const stockId = currentStock?.stockInfo?.code || currentStock?.stockInfo?.symbol;
const stockId = currentStock ? getStockUniqueId(currentStock) : null;
startTypewriterEffect(parsedConclusion.value, stockId, audioInfo.onComplete);
}
},
@ -1766,7 +1772,7 @@ function playAudioQueue(
if (shouldStartTypewriter) {
console.log("没有音频但需要启动打字机效果");
const currentStock = emotionStore.activeStock;
const stockId = currentStock?.stockInfo?.code || currentStock?.stockInfo?.symbol;
const stockId = currentStock ? getStockUniqueId(currentStock) : null;
startTypewriterEffect(conclusion, stockId, onComplete);
}
} else {
@ -2229,19 +2235,16 @@ async function handleSendMessage(input, onComplete) {
parsedConclusion.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);
} 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 {
//
if (onComplete && typeof onComplete === "function") {
@ -2899,14 +2902,12 @@ function setupIntersectionObserver() {
if (entry.isIntersecting) {
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) {
console.log(
@ -2915,10 +2916,10 @@ function setupIntersectionObserver() {
//
console.log("开始音频播放和打字机效果");
stockAudioPlayed.value.set(stockCode, true);
stockAudioPlayed.value.set(stockUniqueId, true);
playAudioQueue(parsedConclusion.value, true);
stockTypewriterShown.value.set(stockCode, true);
stockTypewriterShown.value.set(stockUniqueId, true);
} else {
//
console.log(
@ -2928,8 +2929,8 @@ function setupIntersectionObserver() {
// parsedConclusion
//
stockTypewriterShown.value.set(stockCode, true);
stockAudioPlayed.value.set(stockCode, true);
stockTypewriterShown.value.set(stockUniqueId, true);
stockAudioPlayed.value.set(stockUniqueId, true);
}
} else {
//
@ -3257,12 +3258,10 @@ onMounted(async () => {
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);
}
}
}
@ -4090,11 +4089,10 @@ const emit = defineEmits(["updateMessage", "sendMessage", "ensureAIchat", "enabl
background-color: #f1f1f1;
border-radius: 15px;
align-items: flex-start;
gap: 10px;
margin-right: auto;
/* max-width: 80%; */
max-width: 80%;
width: 100%;
white-space: normal;
width: fit-content;
overflow: visible;
align-items: center;
display: flex;
@ -4171,12 +4169,11 @@ const emit = defineEmits(["updateMessage", "sendMessage", "ensureAIchat", "enabl
.ai-message {
color: #000000;
font-weight: bold;
padding: 20px 30px;
padding-left: 0px;
padding: 10px 10px;
border-radius: 15px;
text-align: left;
margin-right: auto;
width: fit-content;
width: 100%;
overflow: visible;
align-items: center;
display: flex;

Loading…
Cancel
Save