feat(history): 支持自定义历史记录对象实现返回功能

- FormBuilder 组件新增 history 属性,允许注入自定义历史记录对象
- 优化 FormBuilder 的取消操作,优先调用 history.goBack 方法
- HeaderBack 组件修改返回点击事件,支持使用自定义 history 对象
- Page 组件返回按钮支持自定义历史记录回退行为
- README 更新,新增版本信息及 antd6 升级说明
1.0
LiuJiaNan 2026-06-24 14:39:33 +08:00
parent 1befca1cac
commit 4937d77709
4 changed files with 15 additions and 3 deletions

View File

@ -44,6 +44,11 @@ export interface FormBuilderProps<Values = any> extends Omit<FormProps, "form" |
form: FormInstance<Values>; form: FormInstance<Values>;
/** 表单提交时的回调函数 */ /** 表单提交时的回调函数 */
onFinish?: (values: Values) => void; onFinish?: (values: Values) => void;
/** 历史记录对象,用于返回上一页,默认使用 window.history.back */
history?: {
goBack?: () => void;
[key: string]: any;
};
} }
/** /**

View File

@ -21,6 +21,7 @@ const FormBuilder = (props) => {
showCancelButton = true, showCancelButton = true,
customActionButtons, customActionButtons,
extraActionButtons, extraActionButtons,
history,
loading = false, loading = false,
...restProps ...restProps
} = props; } = props;
@ -51,7 +52,7 @@ const FormBuilder = (props) => {
}, [showActionButtons]); }, [showActionButtons]);
const handleCancel = () => { const handleCancel = () => {
window.history.back(); history?.goBack ? history.goBack() : window.history.back();
}; };
return ( return (

View File

@ -17,7 +17,9 @@ function HeaderBack(props) {
<> <>
<div <div
className="back" className="back"
onClick={() => history?.goBack?.() || window.history.back()} onClick={() => {
history?.goBack ? history.goBack() : window.history.back();
}}
> >
<ArrowLeftOutlined style={{ fontSize: 14 }} /> <ArrowLeftOutlined style={{ fontSize: 14 }} />
<span>返回</span> <span>返回</span>

View File

@ -61,7 +61,11 @@ function Page(props) {
{customActionButtons || ( {customActionButtons || (
<Space> <Space>
{extraActionButtons} {extraActionButtons}
<Button onClick={() => history?.goBack?.() || window.history.back()}> <Button
onClick={() => {
history?.goBack ? history.goBack() : window.history.back();
}}
>
{backButtonText} {backButtonText}
</Button> </Button>
</Space> </Space>