diff --git a/src/views/Community/index.js b/src/views/Community/index.js index 240fa316..22a5a52b 100644 --- a/src/views/Community/index.js +++ b/src/views/Community/index.js @@ -1,5 +1,5 @@ // src/views/Community/index.js -import React, { useState, useEffect, useCallback } from 'react'; +import React, { useState, useEffect, useCallback, useRef } from 'react'; import { useSearchParams, useNavigate } from 'react-router-dom'; import { Box, @@ -97,6 +97,9 @@ const Community = () => { const { isOpen: isEventModalOpen, onOpen: onEventModalOpen, onClose: onEventModalClose } = useDisclosure(); const { isOpen: isStockDrawerOpen, onOpen: onStockDrawerOpen, onClose: onStockDrawerClose } = useDisclosure(); + // Ref:用于滚动到实时事件时间轴 + const eventTimelineRef = useRef(null); + // ⚡ 通知权限引导 const { showCommunityGuide } = useNotification(); @@ -214,7 +217,16 @@ const Community = () => { const handlePageChange = useCallback((page) => { updateUrlParams({ page }); loadEvents(page); - window.scrollTo(0, 0); + + // 滚动到实时事件时间轴(平滑滚动) + setTimeout(() => { + if (eventTimelineRef.current) { + eventTimelineRef.current.scrollIntoView({ + behavior: 'smooth', // 平滑滚动 + block: 'start' // 滚动到元素顶部 + }); + } + }, 100); // 延迟100ms,确保DOM更新 }, [updateUrlParams, loadEvents]); // 处理事件点击 @@ -326,7 +338,7 @@ const Community = () => { )} {/* 事件列表卡片 */} - +