fix(scroll): improve scroll and touch event handling across components

- modify Discovery component's overflow settings and scroll wrapper classes
- fix CardSwiper touch event logic: remove unnecessary touchmove prevention, add proper event propagation and conditional default handling
- restructure ChatMainList to use a unified scroll container for both discovery and chat tabs, add scroll reference, refine scroll calculation and implement smooth scroll to bottom
- fix missing newline at end of CardSwiper script file
This commit is contained in:
duanshuwen
2026-05-29 23:40:13 +08:00
parent ce1dac077e
commit 567776f975
3 changed files with 129 additions and 105 deletions

View File

@@ -5,116 +5,122 @@
<ChatTopNavBar ref="topNavBarRef" :mainPageDataModel="mainPageDataModel" /> <ChatTopNavBar ref="topNavBarRef" :mainPageDataModel="mainPageDataModel" />
</div> </div>
<div class="relative"> <div ref="mainScrollRef"
<img class="w-full block" :src="mainPageDataModel?.initPageImages?.backgroundImageUrl" style="height: 252px;" /> class="min-h-0 flex-1 overflow-y-auto overscroll-contain scrollbar-none [-ms-overflow-style:none] [&::-webkit-scrollbar]:hidden"
<div class="absolute bottom-0 left-0 right-0 flex-1"> @scroll="handleScroll" @touchstart.capture="handleScrollAreaTouchStart" @touchstart="handleScrollAreaTouchStart"
<div class="px-[12px] pt-[12px]"> @touchmove="handleScrollAreaTouchMove">
<Welcome :mainPageDataModel="mainPageDataModel" /> <div class="relative">
</div> <img class="w-full block" :src="mainPageDataModel?.initPageImages?.backgroundImageUrl" style="height: 252px;" />
<div style="margin-bottom: -1px;"> <div class="absolute bottom-0 left-0 right-0 flex-1">
<AiTabSwitch v-model="tabIndex" :list="tabList" @change="handleChange" /> <div class="px-[12px] pt-[12px]">
<Welcome :mainPageDataModel="mainPageDataModel" />
</div>
<div style="margin-bottom: -1px;">
<AiTabSwitch v-model="tabIndex" :list="tabList" @change="handleChange" />
</div>
</div> </div>
</div> </div>
</div>
<!-- 发现页 --> <!-- 发现页 -->
<div v-show="tabIndex === 0" class="min-h-0 flex-1 overflow-hidden" @touchstart.capture="handleScrollAreaTouchStart" <div v-show="tabIndex === 0" class="min-h-0 flex-1 overflow-hidden"
@touchstart="handleScrollAreaTouchStart" @touchmove="handleScrollAreaTouchMove"> @touchstart.capture="handleScrollAreaTouchStart" @touchstart="handleScrollAreaTouchStart"
@touchmove="handleScrollAreaTouchMove">
<Discovery @scroll-touch-start="handleScrollAreaTouchStart" @scroll-touch="handleScrollAreaTouchMove" /> <Discovery @scroll-touch-start="handleScrollAreaTouchStart" @scroll-touch="handleScrollAreaTouchMove" />
</div> </div>
<!-- 消息列表可滚动区域 --> <!-- 消息列表可滚动区域 -->
<div v-show="tabIndex === 1" class="min-h-0 flex-1 overflow-hidden" :scroll-top="scrollTop" @scroll="handleScroll" <div v-show="tabIndex === 1" class="min-h-0 flex-1 overflow-hidden" :scroll-top="scrollTop" @scroll="handleScroll"
@scrolltolower="handleScrollToLower" @touchstart.capture="handleScrollAreaTouchStart" @scrolltolower="handleScrollToLower" @touchstart.capture="handleScrollAreaTouchStart"
@touchstart="handleScrollAreaTouchStart" @touchmove="handleScrollAreaTouchMove"> @touchstart="handleScrollAreaTouchStart" @touchmove="handleScrollAreaTouchMove">
<div class="area-msg-list-content" v-for="item in chatMsgList" :key="item.msgId" :id="item.msgId"> <div class="area-msg-list-content" v-for="item in chatMsgList" :key="item.msgId" :id="item.msgId">
<template v-if="item.msgType === MessageRole.AI"> <template v-if="item.msgType === MessageRole.AI">
<ChatCardAI class="flex justify-start" :key="`ai-${item.msgId}-${item.msg ? item.msg.length : 0}`" :text="item.componentName && isLongTextCard(item.componentName) <ChatCardAI class="flex justify-start" :key="`ai-${item.msgId}-${item.msg ? item.msg.length : 0}`" :text="item.componentName && isLongTextCard(item.componentName)
? '' ? ''
: item.msg || '' : item.msg || ''
" :isLoading="item.isLoading"> " :isLoading="item.isLoading">
<template #content v-if=" <template #content v-if="
item.toolCall || item.toolCall ||
(item.componentName && isLongTextCard(item.componentName)) (item.componentName && isLongTextCard(item.componentName))
"> ">
<LongTextGuideCardPreview v-if="item.componentName && isLongTextCard(item.componentName)" <LongTextGuideCardPreview v-if="item.componentName && isLongTextCard(item.componentName)"
:componentName="item.componentName" /> :componentName="item.componentName" />
<QuickBookingComponent v-if=" <QuickBookingComponent v-if="
item.toolCall && item.toolCall &&
item.toolCall.componentName === CompName.quickBookingCard item.toolCall.componentName === CompName.quickBookingCard
" /> " />
<DiscoveryCardComponent v-else-if=" <DiscoveryCardComponent v-else-if="
item.toolCall && item.toolCall &&
item.toolCall.componentName === CompName.discoveryCard item.toolCall.componentName === CompName.discoveryCard
" /> " />
<CreateServiceOrder v-else-if=" <CreateServiceOrder v-else-if="
item.toolCall && item.toolCall &&
item.toolCall.componentName === CompName.callServiceCard item.toolCall.componentName === CompName.callServiceCard
" :toolCall="item.toolCall" /> " :toolCall="item.toolCall" />
<OpenMapComponent v-else-if=" <OpenMapComponent v-else-if="
item.toolCall && item.toolCall &&
item.toolCall.componentName === CompName.mapCard item.toolCall.componentName === CompName.mapCard
" /> " />
<GeneratorPhotoComponent v-else-if=" <GeneratorPhotoComponent v-else-if="
item.toolCall && item.toolCall &&
item.toolCall.componentName === CompName.aigcPhotoGeneratorCard item.toolCall.componentName === CompName.aigcPhotoGeneratorCard
" :toolCall="item.toolCall" /> " :toolCall="item.toolCall" />
<AigcPhotoCard v-else-if=" <AigcPhotoCard v-else-if="
item.toolCall && item.toolCall &&
item.toolCall.componentName === CompName.videoCard item.toolCall.componentName === CompName.videoCard
" :toolCall="item.toolCall" /> " :toolCall="item.toolCall" />
<Feedback v-else-if=" <Feedback v-else-if="
item.toolCall && item.toolCall &&
item.toolCall.componentName === CompName.feedbackCard item.toolCall.componentName === CompName.feedbackCard
" :toolCall="item.toolCall" /> " :toolCall="item.toolCall" />
<DetailCardCompontent v-else-if=" <DetailCardCompontent v-else-if="
item.toolCall && item.toolCall &&
item.toolCall.componentName === item.toolCall.componentName ===
CompName.pictureAndCommodityCard CompName.pictureAndCommodityCard
" :toolCall="item.toolCall" /> " :toolCall="item.toolCall" />
<AddCarCrad v-else-if=" <AddCarCrad v-else-if="
item.toolCall && item.toolCall &&
item.toolCall.componentName === CompName.enterLicensePlateCard item.toolCall.componentName === CompName.enterLicensePlateCard
" :toolCall="item.toolCall" /> " :toolCall="item.toolCall" />
<SurveyQuestionnaire v-else-if=" <SurveyQuestionnaire v-else-if="
item.toolCall && item.toolCall &&
item.toolCall.componentName === item.toolCall.componentName ===
CompName.callSurveyQuestionnaire CompName.callSurveyQuestionnaire
" :toolCall="item.toolCall" /> " :toolCall="item.toolCall" />
</template> </template>
<template #footer> <template #footer>
<!-- 这个是底部 --> <!-- 这个是底部 -->
<AttachListComponent v-if="item.question" :question="item.question" /> <AttachListComponent v-if="item.question" :question="item.question" />
</template> </template>
</ChatCardAI> </ChatCardAI>
</template> </template>
<template v-else-if="item.msgType === MessageRole.ME"> <template v-else-if="item.msgType === MessageRole.ME">
<ChatCardMine class="flex justify-end" :text="item.msg" /> <ChatCardMine class="flex justify-end" :text="item.msg" />
</template> </template>
<template v-else> <template v-else>
<ChatCardOther class="flex justify-center" :text="item.msg"> <ChatCardOther class="flex justify-center" :text="item.msg">
<ChatGuide v-if="chatMsgList.length < 2" /> <ChatGuide v-if="chatMsgList.length < 2" />
<ActivityListComponent v-if=" <ActivityListComponent v-if="
mainPageDataModel.activityList && mainPageDataModel.activityList &&
mainPageDataModel.activityList.length mainPageDataModel.activityList.length
" :activityList="mainPageDataModel.activityList" /> " :activityList="mainPageDataModel.activityList" />
<!-- 先不展示了,等后续有需求再加回来 false --> <!-- 先不展示了,等后续有需求再加回来 false -->
<RecommendPostsComponent v-if=" <RecommendPostsComponent v-if="
false && false &&
mainPageDataModel.recommendTheme && mainPageDataModel.recommendTheme &&
mainPageDataModel.recommendTheme.length mainPageDataModel.recommendTheme.length
" :recommendThemeList="mainPageDataModel.recommendTheme" /> " :recommendThemeList="mainPageDataModel.recommendTheme" />
</ChatCardOther> </ChatCardOther>
</template> </template>
</div>
</div> </div>
</div> </div>
@@ -181,6 +187,7 @@ const appStore = useAppStore();
/// 输入框组件引用 /// 输入框组件引用
const inputAreaRef = ref(null); const inputAreaRef = ref(null);
const mainScrollRef = ref(null);
const topNavBarRef = ref(); const topNavBarRef = ref();
const notitceConent = ref(null); const notitceConent = ref(null);
@@ -331,10 +338,17 @@ const handleScroll = (e) => {
hideKeyboardByScroll(); hideKeyboardByScroll();
} }
const detail = e.detail; const currentScrollTop = Number(e?.detail?.scrollTop ?? e?.target?.scrollTop ?? 0);
topNavBarRef.value.show = parseInt(detail.scrollTop) > welcomeHeight.value; const scrollEl = e?.target;
if (topNavBarRef.value) {
const currentScrollTop = detail.scrollTop; topNavBarRef.value.show = currentScrollTop > welcomeHeight.value;
}
if (
scrollEl &&
scrollEl.scrollHeight - currentScrollTop - scrollEl.clientHeight < 8
) {
isAutoScroll.value = true;
}
// 如果向上滚动 (当前位置小于上一次记录的位置) // 如果向上滚动 (当前位置小于上一次记录的位置)
if (currentScrollTop < lastScrollTop - 2) { if (currentScrollTop < lastScrollTop - 2) {
// 增加 2px 阈值防止抖动 // 增加 2px 阈值防止抖动
@@ -361,6 +375,12 @@ const scrollToBottom = (force = false) => {
// 使用更大的值确保滚动到真正的底部 // 使用更大的值确保滚动到真正的底部
const targetScrollTop = 99999 + Math.random(); const targetScrollTop = 99999 + Math.random();
scrollTop.value = targetScrollTop; scrollTop.value = targetScrollTop;
if (mainScrollRef.value && typeof mainScrollRef.value.scrollTo === "function") {
mainScrollRef.value.scrollTo({
top: mainScrollRef.value.scrollHeight,
behavior: "smooth",
});
}
}); });
}; };

View File

@@ -1,5 +1,5 @@
<template> <template>
<div class="w-full" @touchstart="handleTouchStart" @touchmove.stop.prevent="handleTouchMove" <div class="w-full" @touchstart="handleTouchStart" @touchmove="handleTouchMove"
@touchend="handleTouchEnd" @touchcancel="handleTouchCancel"> @touchend="handleTouchEnd" @touchcancel="handleTouchCancel">
<div :class="['relative w-full h-[270px] overflow-hidden', list.length <= 1 ? 'overflow-visible' : '']"> <div :class="['relative w-full h-[270px] overflow-hidden', list.length <= 1 ? 'overflow-visible' : '']">
<div v-for="slot in renderSlots" :key="slot.key" <div v-for="slot in renderSlots" :key="slot.key"
@@ -424,6 +424,10 @@ const handleTouchMove = (event) => {
return; return;
} }
event.stopPropagation();
if (event.cancelable) {
event.preventDefault();
}
deltaX.value = clamp(moveX, -hiddenOffset, hiddenOffset); deltaX.value = clamp(moveX, -hiddenOffset, hiddenOffset);
}; };

View File

@@ -1,8 +1,8 @@
<template> <template>
<div class="flex flex-col h-full overflow-hidden"> <div class="flex flex-col overflow-visible">
<FindTabs v-if="discoveryTabs.length" v-model="activeIndex" :tabs="discoveryTabs" @change="handleTabChange" /> <FindTabs v-if="discoveryTabs.length" v-model="activeIndex" :tabs="discoveryTabs" @change="handleTabChange" />
<div class="discovery-scroll flex-1" overflow-y @touchstart="emitScrollTouchStart" @touchmove="emitScrollTouch" <div class="discovery-scroll" @touchstart="emitScrollTouchStart" @touchmove="emitScrollTouch"
@scroll="emitScrollTouch"> @scroll="emitScrollTouch">
<CardSwiper v-if="discoveryCards.length" :list="discoveryCards" @didSelectItem="handleCardClick" /> <CardSwiper v-if="discoveryCards.length" :list="discoveryCards" @didSelectItem="handleCardClick" />