feat(history): 支持自定义历史记录对象实现返回功能
- FormBuilder 组件新增 history 属性,允许注入自定义历史记录对象 - 优化 FormBuilder 的取消操作,优先调用 history.goBack 方法 - HeaderBack 组件修改返回点击事件,支持使用自定义 history 对象 - Page 组件返回按钮支持自定义历史记录回退行为 - README 更新,新增版本信息及 antd6 升级说明2.0
parent
582bbc0470
commit
8566185de1
|
|
@ -15,4 +15,8 @@ yarn add zy-react-library
|
|||
|
||||
### v1.1.2 (2025-12-25)
|
||||
|
||||
- 🎉 优化编译效果
|
||||
- 🎉 优化编译效果
|
||||
|
||||
### v2.0.0 (2026-06-22)
|
||||
|
||||
- 🎉 升级到antd6
|
||||
|
|
@ -44,6 +44,11 @@ export interface FormBuilderProps<Values = any> extends Omit<FormProps, "form" |
|
|||
form: FormInstance<Values>;
|
||||
/** 表单提交时的回调函数 */
|
||||
onFinish?: (values: Values) => void;
|
||||
/** 历史记录对象,用于返回上一页,默认使用 window.history.back */
|
||||
history?: {
|
||||
goBack?: () => void;
|
||||
[key: string]: any;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ const FormBuilder = (props) => {
|
|||
showCancelButton = true,
|
||||
customActionButtons,
|
||||
extraActionButtons,
|
||||
history,
|
||||
loading = false,
|
||||
...restProps
|
||||
} = props;
|
||||
|
|
@ -51,7 +52,7 @@ const FormBuilder = (props) => {
|
|||
}, [showActionButtons]);
|
||||
|
||||
const handleCancel = () => {
|
||||
window.history.back();
|
||||
history?.goBack ? history.goBack() : window.history.back();
|
||||
};
|
||||
|
||||
return (
|
||||
|
|
|
|||
|
|
@ -17,7 +17,9 @@ function HeaderBack(props) {
|
|||
<>
|
||||
<div
|
||||
className="back"
|
||||
onClick={() => history?.goBack?.() || window.history.back()}
|
||||
onClick={() => {
|
||||
history?.goBack ? history.goBack() : window.history.back();
|
||||
}}
|
||||
>
|
||||
<ArrowLeftOutlined style={{ fontSize: 14 }} />
|
||||
<span>返回</span>
|
||||
|
|
|
|||
|
|
@ -61,7 +61,11 @@ function Page(props) {
|
|||
{customActionButtons || (
|
||||
<Space>
|
||||
{extraActionButtons}
|
||||
<Button onClick={() => history?.goBack?.() || window.history.back()}>
|
||||
<Button
|
||||
onClick={() => {
|
||||
history?.goBack ? history.goBack() : window.history.back();
|
||||
}}
|
||||
>
|
||||
{backButtonText}
|
||||
</Button>
|
||||
</Space>
|
||||
|
|
|
|||
Loading…
Reference in New Issue