import React, { useEffect, type FC, type ReactNode } from 'react'; import { BiError, BiLogoChrome } from 'react-icons/bi'; import { GrDocumentMissing } from 'react-icons/gr'; import { HiMiniArrowLeft, HiMiniArrowPath, HiMiniHome, HiOutlineExclamationCircle } from 'react-icons/hi2'; import { useInRouterContext, useNavigate, useRouteError } from 'react-router'; import { ActionIcon } from '../../components/icons'; import { Button, NonIdealState } from '../../daisy'; export namespace NonIdealPage { export interface LayoutProps { icon?: ReactNode; title?: ReactNode; description?: ReactNode; action?: ReactNode; children?: ReactNode; } export const Layout: FC = ({ title, icon, description, action, children }) => { const inRouterContext = useInRouterContext(); let navigate = (v: any) => { typeof v === 'string' ? (window.location.href = v) : window.history.back(); }; if (inRouterContext) { navigate = useNavigate(); } const defaultAction = (
); return (
{children}
); }; export const PageNotFound: FC<{ children?: ReactNode }> = ({ children }) => { return ( } title={'页面不存在'} description={当前页面地址: {globalThis.location?.href}} > {children} ); }; export const ServerError: FC<{ statusCode?: string; children?: ReactNode }> = ({ statusCode, children }) => { return ( } title={`服务器处理错误`} description={错误码:{statusCode || '未知'}} > {children} ); }; export const PageError: FC<{ error?: any; title?: ReactNode; children?: ReactNode; onReset?: () => void; }> = ({ error, title = '页面出错啦!', onReset, children }) => { const inRouterContext = useInRouterContext(); let navigate = (v: any) => { typeof v === 'string' ? (window.location.href = v) : window.history.back(); }; if (inRouterContext) { navigate = useNavigate(); const routerError = useRouteError(); error ||= routerError; } useEffect(() => { console.error('PageError', error); }, [error]); const action = (
{onReset && ( )} {children}
); return ( } title={title} description={
请联系管理员或刷新页面
{error && (
查看详细错误
{String(error)}
)}
} action={action} /> ); }; } const Browser = () => { const { brand, version } = navigator.userAgent.match(/(?Chrom(e|ium))\/(?[0-9]+)\./)?.groups ?? {}; if (!brand) { return 不支持的浏览器环境; } // 100 2022-03-29 // 90 2021-02-28 const old = Number.parseInt(version) < 100; return (
{brand} {version} {old && ( 当前浏览器版本 {version} 过低,请下载使用新版本浏览器。 )}
); };