From 870b1f5996760266fb6fd5eb52bb9ecd2e277191 Mon Sep 17 00:00:00 2001 From: zdl <3489966805@qq.com> Date: Wed, 5 Nov 2025 17:30:21 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A4=9A=E5=88=97=E5=B8=83=E5=B1=80ui?= =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DynamicNewsCard/VirtualizedFourRowGrid.js | 42 +++++++++++++++++-- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/src/views/Community/components/DynamicNewsCard/VirtualizedFourRowGrid.js b/src/views/Community/components/DynamicNewsCard/VirtualizedFourRowGrid.js index 74bb6d74..ce495d63 100644 --- a/src/views/Community/components/DynamicNewsCard/VirtualizedFourRowGrid.js +++ b/src/views/Community/components/DynamicNewsCard/VirtualizedFourRowGrid.js @@ -3,7 +3,8 @@ import React, { useRef, useMemo, useEffect } from 'react'; import { useVirtualizer } from '@tanstack/react-virtual'; -import { Box, Grid, Spinner, Text, VStack, Center } from '@chakra-ui/react'; +import { Box, Grid, Spinner, Text, VStack, Center, HStack, IconButton } from '@chakra-ui/react'; +import { RepeatIcon } from '@chakra-ui/icons'; import { useColorModeValue } from '@chakra-ui/react'; import DynamicNewsEventCard from '../EventCard/DynamicNewsEventCard'; @@ -37,6 +38,8 @@ const VirtualizedFourRowGrid = ({ loadPrevPage, // 新增:加载上一页 hasMore, loading, + error, // 新增:错误状态 + onRetry, // 新增:重试回调 }) => { const parentRef = useRef(null); const isLoadingMore = useRef(false); // 防止重复加载 @@ -160,6 +163,39 @@ const VirtualizedFourRowGrid = ({ return () => clearTimeout(timer); }, [events.length]); // 监听 events 变化,加载上一页后会增加 events 数量 + // 错误指示器(同行显示) + const renderErrorIndicator = () => { + if (!error) return null; + + return ( +
+ + + 数据加载失败, + + } + size="sm" + colorScheme="blue" + variant="ghost" + onClick={onRetry} + aria-label="刷新" + /> + + 刷新 + + +
+ ); + }; + // 底部加载指示器 const renderLoadingIndicator = () => { if (!hasMore) { @@ -243,7 +279,7 @@ const VirtualizedFourRowGrid = ({ w="100%" > {rowEvents.map((event, colIndex) => ( - + - {renderLoadingIndicator()} + {error ? renderErrorIndicator() : renderLoadingIndicator()}