Browse Source

解决了情绪大模型抢鼠标问题。

songjie/feature-20250628160649-上线前优化
宋杰 10 hours ago
parent
commit
49af4ed7db
  1. 66
      src/views/AiEmotion.vue

66
src/views/AiEmotion.vue

@ -248,6 +248,8 @@ const hasTriggeredAudio = ref(false); // 是否已触发音频播放
const hasTriggeredTypewriter = ref(false); //
const intersectionObserver = ref(null); // observer
const isUserInitiated = ref(false); //
const isUserScrolling = ref(false); //
const scrollTimeout = ref(null); //
//
const displayedTexts = ref({
@ -756,6 +758,12 @@ function startTypewriterEffect(conclusion) {
for (let i = 0; i <= disclaimerText.length; i++) {
const timer = setTimeout(() => {
displayedTexts.value.disclaimer = disclaimerText.substring(0, i);
//
if (i === disclaimerText.length) {
setTimeout(() => {
scrollToBottom();
}, 100);
}
}, totalDelay + i * typeSpeed);
typewriterTimers.value.push(timer);
}
@ -804,6 +812,10 @@ function playAudio(url) {
isAudioPlaying.value = true;
emotionAudioStore.isPlaying = true;
console.log('开始播放场景应用语音');
//
setTimeout(() => {
scrollToBottom();
}, 100);
},
onend: () => {
isAudioPlaying.value = false;
@ -1155,6 +1167,12 @@ function renderCharts(data) {
}
const scrollToBottom = async () => {
//
if (isUserScrolling.value) {
console.log('用户正在手动滚动,跳过自动滚动');
return;
}
const container = userInputDisplayRef.value;
if (!container) return;
await nextTick();
@ -1164,6 +1182,32 @@ const scrollToBottom = async () => {
container.scrollTop = container.scrollHeight - container.offsetHeight;
};
//
const handleUserScroll = () => {
isUserScrolling.value = true;
//
if (scrollTimeout.value) {
clearTimeout(scrollTimeout.value);
}
// 2
scrollTimeout.value = setTimeout(() => {
isUserScrolling.value = false;
console.log('用户滚动结束,重新允许自动滚动');
}, 2000);
};
//
const handleWheel = (event) => {
handleUserScroll();
};
//
const handleTouchMove = (event) => {
handleUserScroll();
};
//
function isDataLoaded() {
@ -1364,6 +1408,14 @@ onMounted(async () => {
//
window.addEventListener('resize', globalResizeHandler);
window.aiEmotionGlobalResizeHandler = globalResizeHandler;
//
const container = userInputDisplayRef.value;
if (container) {
container.addEventListener('wheel', handleWheel, { passive: true });
container.addEventListener('touchmove', handleTouchMove, { passive: true });
container.addEventListener('scroll', handleUserScroll, { passive: true });
}
//
function debounce(func, wait) {
@ -1436,6 +1488,20 @@ onUnmounted(() => {
window.removeEventListener('resize', window.aiEmotionGlobalResizeHandler);
window.aiEmotionGlobalResizeHandler = null;
}
//
const container = userInputDisplayRef.value;
if (container) {
container.removeEventListener('wheel', handleWheel);
container.removeEventListener('touchmove', handleTouchMove);
container.removeEventListener('scroll', handleUserScroll);
}
//
if (scrollTimeout.value) {
clearTimeout(scrollTimeout.value);
scrollTimeout.value = null;
}
});
//

Loading…
Cancel
Save