From 0f3bc06716f8746fc09879c8841b9506208c7390 Mon Sep 17 00:00:00 2001 From: zdl <3489966805@qq.com> Date: Mon, 27 Oct 2025 16:37:36 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=AE=BF=E9=97=AE=20http://localhost:3?= =?UTF-8?q?000/admin/community=EF=BC=9A=20=20=201.=20=E9=A1=B5=E9=9D=A2?= =?UTF-8?q?=E5=8A=A0=E8=BD=BD=E5=90=8E=E5=BA=94=E5=81=9C=E7=95=99=E5=9C=A8?= =?UTF-8?q?=E9=A1=B6=E9=83=A8=20=20=202.=20=E7=82=B9=E5=87=BB=E6=90=9C?= =?UTF-8?q?=E7=B4=A2=E6=A1=86=EF=BC=8C=E9=A1=B5=E9=9D=A2=E5=BA=94=E5=B9=B3?= =?UTF-8?q?=E6=BB=91=E6=BB=9A=E5=8A=A8=E5=88=B0"=E5=AE=9E=E6=97=B6?= =?UTF-8?q?=E4=BA=8B=E4=BB=B6=E6=97=B6=E9=97=B4=E8=BD=B4"=E5=8C=BA?= =?UTF-8?q?=E5=9F=9F=20=20=203.=20=E5=86=8D=E6=AC=A1=E7=82=B9=E5=87=BB?= =?UTF-8?q?=E6=90=9C=E7=B4=A2=E6=A1=86=E4=B8=8D=E4=BC=9A=E9=87=8D=E5=A4=8D?= =?UTF-8?q?=E6=BB=9A=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Community/components/EventTimelineCard.js | 3 ++ .../Community/components/UnifiedSearchBox.js | 2 ++ src/views/Community/index.js | 32 ++++++++----------- 3 files changed, 18 insertions(+), 19 deletions(-) diff --git a/src/views/Community/components/EventTimelineCard.js b/src/views/Community/components/EventTimelineCard.js index 0bde3f86..d240a2aa 100644 --- a/src/views/Community/components/EventTimelineCard.js +++ b/src/views/Community/components/EventTimelineCard.js @@ -22,6 +22,7 @@ import EventListSection from './EventListSection'; * @param {Array} popularKeywords - 热门关键词 * @param {Date} lastUpdateTime - 最后更新时间 * @param {Function} onSearch - 搜索回调 + * @param {Function} onSearchFocus - 搜索框获得焦点回调 * @param {Function} onPageChange - 分页变化回调 * @param {Function} onEventClick - 事件点击回调 * @param {Function} onViewDetail - 查看详情回调 @@ -35,6 +36,7 @@ const EventTimelineCard = forwardRef(({ popularKeywords, lastUpdateTime, onSearch, + onSearchFocus, onPageChange, onEventClick, onViewDetail, @@ -56,6 +58,7 @@ const EventTimelineCard = forwardRef(({ diff --git a/src/views/Community/components/UnifiedSearchBox.js b/src/views/Community/components/UnifiedSearchBox.js index 82858a2f..fd2a66ea 100644 --- a/src/views/Community/components/UnifiedSearchBox.js +++ b/src/views/Community/components/UnifiedSearchBox.js @@ -21,6 +21,7 @@ const { Option } = AntSelect; const UnifiedSearchBox = ({ onSearch, + onSearchFocus, popularKeywords = [], filters = {} }) => { @@ -519,6 +520,7 @@ const UnifiedSearchBox = ({ onChange={handleInputChange} onSearch={handleSearch} onSelect={handleStockSelect} + onFocus={onSearchFocus} options={stockOptions} placeholder="请输入股票代码/股票名称/相关话题" onPressEnter={handleMainSearch} diff --git a/src/views/Community/index.js b/src/views/Community/index.js index 2f5df6e5..4c759ce5 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, useRef } from 'react'; +import React, { useState, useEffect, useRef, useCallback } from 'react'; import { useNavigate } from 'react-router-dom'; import { useSelector, useDispatch } from 'react-redux'; import { fetchPopularKeywords, fetchHotEvents } from '../../store/slices/communityDataSlice'; @@ -71,25 +71,18 @@ const Community = () => { } }, [showCommunityGuide]); // 只在组件挂载时执行一次 - // ⚡ 页面渲染完成后1秒,自动滚动到实时事件时间轴 - useEffect(() => { - // 只在第一次数据加载完成后滚动 - if (!loading && !hasScrolledRef.current && eventTimelineRef.current) { - const timer = setTimeout(() => { - if (eventTimelineRef.current) { - eventTimelineRef.current.scrollIntoView({ - behavior: 'smooth', // 平滑滚动动画 - block: 'start', // 元素顶部对齐视口顶部,标题正好可见 - inline: 'nearest' // 水平方向最小滚动 - }); - hasScrolledRef.current = true; // 标记已滚动 - logger.debug('Community', '页面渲染完成,自动滚动到实时事件时间轴(顶部对齐)'); - } - }, 1000); // 渲染完成后延迟1秒 - - return () => clearTimeout(timer); + // ⚡ 滚动到实时事件区域(由搜索框聚焦触发) + const scrollToTimeline = useCallback(() => { + if (!hasScrolledRef.current && eventTimelineRef.current) { + eventTimelineRef.current.scrollIntoView({ + behavior: 'smooth', // 平滑滚动动画 + block: 'start', // 元素顶部对齐视口顶部,标题正好可见 + inline: 'nearest' // 水平方向最小滚动 + }); + hasScrolledRef.current = true; // 标记已滚动 + logger.debug('Community', '用户触发搜索,滚动到实时事件时间轴'); } - }, [loading]); // 监听 loading 状态变化 + }, []); return ( @@ -109,6 +102,7 @@ const Community = () => { popularKeywords={popularKeywords} lastUpdateTime={lastUpdateTime} onSearch={updateFilters} + onSearchFocus={scrollToTimeline} onPageChange={handlePageChange} onEventClick={handleEventClick} onViewDetail={handleViewDetail}