From e769859cba7685018cc33b27faab2b3ee27600e7 Mon Sep 17 00:00:00 2001 From: zdl <3489966805@qq.com> Date: Wed, 5 Nov 2025 09:36:21 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E5=B9=B3=E9=93=BA?= =?UTF-8?q?=E6=A8=A1=E5=BC=8F=E7=9A=84=E6=97=A0=E9=99=90=E6=BB=9A=E5=8A=A8?= =?UTF-8?q?=E8=A7=A6=E5=8F=91=E6=9C=BA=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 问题描述: - 平铺模式下,当容器高度为 800px 但首页内容不足 800px 时 - 无法生成滚动条,导致无限滚动条件永远无法触发 - 用户需要手动翻页才能看到第二页内容 优化方案: 1. 降低滚动触发阈值 - 从 80% 降低到 60%,更早触发下一页加载 - 提升用户滚动体验,减少等待时间 2. 新增主动内容检测机制 - 延迟 500ms 检测虚拟滚动渲染完成后的实际内容高度 - 如果内容高度 ≤ 容器高度(无滚动条),自动加载下一页 - 使用 isLoadingMore ref 防止重复触发 技术实现: - VirtualizedFourRowGrid.js - 修改滚动阈值: scrollPercentage > 0.6 (line 78) - 新增 useEffect 监听 events.length 变化 (lines 90-117) - 条件判断: scrollHeight <= clientHeight 时主动加载 影响范围: - 平铺模式 (four-row mode) 测试建议: 1. 切换到平铺模式 2. 观察首页数据少于 6 条时,是否自动加载第二页 3. 验证有足够数据时,滚动到 60% 是否正常触发加载 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- .../DynamicNewsCard/EventScrollList.js | 27 +++++++------- .../DynamicNewsCard/VirtualizedFourRowGrid.js | 37 +++++++++++++++++-- 2 files changed, 47 insertions(+), 17 deletions(-) diff --git a/src/views/Community/components/DynamicNewsCard/EventScrollList.js b/src/views/Community/components/DynamicNewsCard/EventScrollList.js index b0511e33..d47db8c2 100644 --- a/src/views/Community/components/DynamicNewsCard/EventScrollList.js +++ b/src/views/Community/components/DynamicNewsCard/EventScrollList.js @@ -155,8 +155,8 @@ const EventScrollList = ({ + {/* 左侧:事件列表 (33.3%) - 使用虚拟滚动 + 无限滚动 */} {/* 右侧:事件详情 (66.7%) */} - + diff --git a/src/views/Community/components/DynamicNewsCard/VirtualizedFourRowGrid.js b/src/views/Community/components/DynamicNewsCard/VirtualizedFourRowGrid.js index 9d41801f..9b941c75 100644 --- a/src/views/Community/components/DynamicNewsCard/VirtualizedFourRowGrid.js +++ b/src/views/Community/components/DynamicNewsCard/VirtualizedFourRowGrid.js @@ -74,8 +74,8 @@ const VirtualizedFourRowGrid = ({ const { scrollTop, scrollHeight, clientHeight } = scrollElement; const scrollPercentage = (scrollTop + clientHeight) / scrollHeight; - // 滚动到 80% 时开始加载下一页 - if (scrollPercentage > 0.8) { + // 滚动到 60% 时开始加载下一页(降低阈值,更早触发) + if (scrollPercentage > 0.6) { console.log('%c📜 [无限滚动] 到达底部,加载下一页', 'color: #8B5CF6; font-weight: bold;'); isLoadingMore.current = true; await loadNextPage(); @@ -87,6 +87,35 @@ const VirtualizedFourRowGrid = ({ return () => scrollElement.removeEventListener('scroll', handleScroll); }, [loadNextPage, hasMore, loading]); + // 主动检测内容高度 - 如果内容不足以填满容器,主动加载下一页 + useEffect(() => { + const scrollElement = parentRef.current; + if (!scrollElement || !loadNextPage) return; + + // 延迟检查,确保虚拟滚动已渲染 + const timer = setTimeout(() => { + // 防止重复触发 + if (isLoadingMore.current || !hasMore || loading) return; + + const { scrollHeight, clientHeight } = scrollElement; + + // 如果内容高度不足以填满容器(没有滚动条),主动加载下一页 + if (scrollHeight <= clientHeight) { + console.log('%c📜 [无限滚动] 内容不足以填满容器,主动加载下一页', 'color: #8B5CF6; font-weight: bold;', { + scrollHeight, + clientHeight, + eventsCount: events.length + }); + isLoadingMore.current = true; + loadNextPage().finally(() => { + isLoadingMore.current = false; + }); + } + }, 500); + + return () => clearTimeout(timer); + }, [events.length, hasMore, loading, loadNextPage]); + // 底部加载指示器 const renderLoadingIndicator = () => { if (!hasMore) { @@ -118,13 +147,13 @@ const VirtualizedFourRowGrid = ({ ref={parentRef} overflowY="auto" overflowX="hidden" - maxH="600px" + maxH="800px" w="100%" position="relative" css={{ // 滚动条样式 '&::-webkit-scrollbar': { - width: '8px', + width: '4px', }, '&::-webkit-scrollbar-track': { background: scrollbarTrackBg,