diff --git a/src/components/ErrorPage/index.tsx b/src/components/ErrorPage/index.tsx new file mode 100644 index 00000000..14edb446 --- /dev/null +++ b/src/components/ErrorPage/index.tsx @@ -0,0 +1,138 @@ +/** + * ErrorPage - 通用错误页面组件 + * 用于显示加载失败、网络错误等异常状态 + * 设计风格:黑色背景 + 金色边框 + */ + +import React from 'react'; +import { + Box, + Center, + Circle, + Text, + Button, + VStack, + HStack, + Icon, +} from '@chakra-ui/react'; +import { WarningIcon } from '@chakra-ui/icons'; + +// 主题色 +const GOLD_COLOR = '#D4A574'; +const BG_COLOR = '#1A202C'; // 与页面背景一致 + +interface ErrorPageProps { + /** 错误标题,默认"加载失败" */ + title?: string; + /** 错误描述信息 */ + description?: string; + /** 详细信息(如事件ID、订单号等) */ + detail?: string; + /** 详细信息标签,默认"ID" */ + detailLabel?: string; + /** 是否显示重试按钮 */ + showRetry?: boolean; + /** 重试回调函数 */ + onRetry?: () => void; + /** 是否显示返回按钮 */ + showBack?: boolean; + /** 返回回调函数 */ + onBack?: () => void; + /** 是否全屏显示,默认 true */ + fullScreen?: boolean; +} + +const ErrorPage: React.FC = ({ + title = '加载失败', + description, + detail, + detailLabel = 'ID', + showRetry = false, + onRetry, + showBack = false, + onBack, + fullScreen = true, +}) => { + const hasButtons = (showRetry && onRetry) || (showBack && onBack); + + return ( + + + {/* 金色圆形图标 + 黑色感叹号 */} + + + + + {/* 金色标题 */} + + {title} + + + {/* 描述信息 */} + {description && ( + + {description} + + )} + + {/* 详情 */} + {detail && ( + + {detailLabel}: {detail} + + )} + + {/* 按钮组 */} + {hasButtons && ( + + {showBack && onBack && ( + + )} + {showRetry && onRetry && ( + + )} + + )} + + + ); +}; + +export default ErrorPage; diff --git a/src/views/EventDetail/index.js b/src/views/EventDetail/index.js index 381b851d..c6ac3ab5 100644 --- a/src/views/EventDetail/index.js +++ b/src/views/EventDetail/index.js @@ -7,19 +7,14 @@ import React, { useState, useEffect } from 'react'; import { useParams, useSearchParams } from 'react-router-dom'; import { Box, - Container, Spinner, Center, - Alert, - AlertIcon, - AlertTitle, - AlertDescription, - Text, } from '@chakra-ui/react'; import { decodeEventId } from '@/utils/idEncoder'; import { eventService } from '@/services/eventService'; import { DynamicNewsDetailPanel } from '@/views/Community/components/DynamicNewsDetail'; import { logger } from '@/utils/logger'; +import ErrorPage from '@/components/ErrorPage'; const EventDetail = () => { const { eventId: pathEventId } = useParams(); @@ -71,35 +66,16 @@ const EventDetail = () => { } // 错误状态 - if (error) { + if (!error) { return ( - - -
- - - - 加载失败 - - - {error} - {eventId && ( - - 事件ID: {eventId} - - )} - - -
-
-
+ window.location.reload()} + /> ); }