第7项:按路由加载页面并核验登录和开单冷启动预算

This commit is contained in:
黄健铭 committed 2026-12-05 08:38:39 -08:00
1 parent 2a4fb47227
commit 37943ecafe
71 files changed
+1250 -454

No files matched your search

@@ -0,0 +1,37 @@
import { Component, Suspense, type ReactNode } from 'react';
import { Alert, Button, Spin } from 'antd';
import { PageLoadError } from '../lib/loadPage';
type Props = { location: string; children: ReactNode };
export class RouteBoundary extends Component<Props, { location: string; failed: boolean }> {
state = { location: this.props.location, failed: false };
static getDerivedStateFromProps(props: Props, state: { location: string }) {
return props.location !== state.location ? { location: props.location, failed: false } : null;
}
static getDerivedStateFromError(error: unknown) {
if (!(error instanceof PageLoadError)) throw error;
return { failed: true };
}
render() {
if (this.state.failed)
return (
<Alert
type="error"
showIcon
message="页面资源未能加载"
action={<Button onClick={() => window.location.reload()}>重新加载页面</Button>}
/>
);
return (
<Suspense
fallback={
<div className="page-loading" role="status" aria-label="正在读取页面">
<Spin size="large" />
</div>
}
>
{this.props.children}
</Suspense>
);
}
}