update 允许向modal中添加按钮

This commit is contained in:
2021-07-02 16:01:22 +08:00
parent 69e18543f9
commit f8e2952727

View File

@@ -15,8 +15,23 @@ function renderModal(props, on, childWithProps) {
onCancel: () => this.onClose(),
}
const { buttons } = this.props
const _buttons = [
<Button onClick={() => on.onClose()}>取消</Button>,
<Button loading={props.confirmLoading} onClick={() => on.onOk()} type="primary">
确认
</Button>,
]
if (Array.isArray(buttons)) {
for (const { index, button } of buttons) {
_buttons.splice(index, 0, button(this.getData, this.close))
}
}
return (
<Modal className="yo-modal-form" {...props} {...on}>
<Modal className="yo-modal-form" {...props} {...on} footer={_buttons}>
{childWithProps}
</Modal>
)
@@ -112,6 +127,13 @@ export default class ModalForm extends Component {
this.setState({ visible: false })
}
getData = async () => {
const body = this.childNode.current
if (!body || !body.getData) throw Error('为获取到子表单')
return await body.getData()
}
/**
* 子元素创建后回调
* 对子元素数据进行填充,(如需关闭时对比)之后再获取结构调整后的数据快照