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,