修复heropanel无法下拉背景页面

This commit is contained in:
2026-01-14 14:25:46 +08:00
parent b13567237f
commit ecd249eafd
3 changed files with 58 additions and 0 deletions

View File

@@ -43,6 +43,8 @@ import { PROFESSIONAL_COLORS } from '@constants/professionalTheme';
import { debounce } from '@utils/debounce';
import { useDevice } from '@hooks/useDevice';
import { eventService } from '@services/eventService';
import { getApiBase } from '@utils/apiConfig';
import { useAuth } from '@contexts/AuthContext';
// 🔍 调试:渲染计数器
let dynamicNewsCardRenderCount = 0;
@@ -74,6 +76,7 @@ const DynamicNewsCardComponent = forwardRef(({
}, ref) => {
const dispatch = useDispatch();
const toast = useToast();
const { isAuthenticated: isLoggedIn } = useAuth();
const cardBg = PROFESSIONAL_COLORS.background.card;
const borderColor = PROFESSIONAL_COLORS.border.default;
@@ -220,6 +223,54 @@ const [currentMode, setCurrentMode] = useState('vertical');
setCurrentMode(mode);
}, [mode]);
// 看涨看跌投票处理
const handleVoteChange = useCallback(async ({ eventId, voteType }) => {
if (!isLoggedIn) {
toast({
title: '请先登录',
description: '登录后才能参与投票',
status: 'warning',
duration: 2000,
isClosable: true,
});
return;
}
try {
const response = await fetch(`${getApiBase()}/api/events/${eventId}/sentiment-vote`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
credentials: 'include',
body: JSON.stringify({ vote_type: voteType }),
});
const data = await response.json();
if (!response.ok || !data.success) {
throw new Error(data.error || '投票失败');
}
toast({
title: voteType === 'bullish' ? '已看涨' : '已看跌',
status: 'success',
duration: 1500,
isClosable: true,
});
// 刷新当前页数据以更新投票计数
handlePageChange(currentPage, true);
} catch (error) {
console.error('投票失败:', error);
toast({
title: '投票失败',
description: error.message,
status: 'error',
duration: 2000,
isClosable: true,
});
}
}, [isLoggedIn, toast, handlePageChange, currentPage]);
/**
* ⚡【核心逻辑】执行刷新的回调函数(包含原有的智能刷新逻辑)
*
@@ -757,6 +808,7 @@ const [currentMode, setCurrentMode] = useState('vertical');
mode={mode}
eventFollowStatus={eventFollowStatus}
onToggleFollow={handleToggleFollow}
onVoteChange={handleVoteChange}
mainlineRef={mainlineRef}
/>
</Box>

View File

@@ -22,6 +22,7 @@ import VerticalModeLayout from "./layouts/VerticalModeLayout";
* @param {string} mode - 展示模式:'vertical'(纵向分栏)| 'mainline'(主线时间轴)
* @param {Object} eventFollowStatus - 事件关注状态 { [eventId]: { isFollowing, followerCount } }
* @param {Function} onToggleFollow - 关注按钮回调
* @param {Function} onVoteChange - 投票变化回调 { eventId, voteType: 'bullish' | 'bearish' }
* @param {React.Ref} mainlineRef - MainlineTimelineView 的 ref
*/
const EventScrollList = React.memo(
@@ -40,6 +41,7 @@ const EventScrollList = React.memo(
mode = "vertical",
eventFollowStatus = {},
onToggleFollow,
onVoteChange,
mainlineRef,
}) => {
const scrollContainerRef = useRef(null);
@@ -90,6 +92,7 @@ const EventScrollList = React.memo(
onEventSelect={onEventSelect}
eventFollowStatus={eventFollowStatus}
onToggleFollow={onToggleFollow}
onVoteChange={onVoteChange}
getTimelineBoxStyle={getTimelineBoxStyle}
borderColor={borderColor}
currentPage={currentPage}

View File

@@ -27,6 +27,7 @@ import PaginationControl from '../PaginationControl';
* @param {Function} onEventSelect - 事件选择回调
* @param {Object} eventFollowStatus - 事件关注状态
* @param {Function} onToggleFollow - 关注按钮回调
* @param {Function} onVoteChange - 投票变化回调 { eventId, voteType: 'bullish' | 'bearish' }
* @param {Function} getTimelineBoxStyle - 时间线样式获取函数
* @param {string} borderColor - 边框颜色
* @param {number} currentPage - 当前页码
@@ -40,6 +41,7 @@ const VerticalModeLayout = React.memo(({
onEventSelect,
eventFollowStatus,
onToggleFollow,
onVoteChange,
getTimelineBoxStyle,
borderColor,
currentPage = 1,
@@ -124,6 +126,7 @@ const VerticalModeLayout = React.memo(({
isFollowing={eventFollowStatus[event.id]?.isFollowing}
followerCount={eventFollowStatus[event.id]?.followerCount}
onToggleFollow={onToggleFollow}
onVoteChange={onVoteChange}
timelineStyle={getTimelineBoxStyle()}
borderColor={borderColor}
indicatorSize="default"