Commit 5bcf895a authored by afc163's avatar afc163

refactor render or AdvancedForm

parent 77d714f2
...@@ -74,35 +74,11 @@ class AdvancedForm extends PureComponent { ...@@ -74,35 +74,11 @@ class AdvancedForm extends PureComponent {
window.removeEventListener('resize', this.resizeFooterToolbar); window.removeEventListener('resize', this.resizeFooterToolbar);
} }
resizeFooterToolbar = () => { getErrorInfo = () => {
requestAnimationFrame(() => { const {
const sider = document.querySelectorAll('.ant-layout-sider')[0]; form: { getFieldsError },
if (sider) { } = this.props;
const width = `calc(100% - ${sider.style.width})`;
const { width: stateWidth } = this.state;
if (stateWidth !== width) {
this.setState({ width });
}
}
});
};
render() {
const { form, dispatch, submitting } = this.props;
const { getFieldDecorator, validateFieldsAndScroll, getFieldsError } = form;
const validate = () => {
validateFieldsAndScroll((error, values) => {
if (!error) {
// submit the values
dispatch({
type: 'form/submitAdvancedForm',
payload: values,
});
}
});
};
const errors = getFieldsError(); const errors = getFieldsError();
const getErrorInfo = () => {
const errorCount = Object.keys(errors).filter(key => errors[key]).length; const errorCount = Object.keys(errors).filter(key => errors[key]).length;
if (!errors || errorCount === 0) { if (!errors || errorCount === 0) {
return null; return null;
...@@ -140,7 +116,43 @@ class AdvancedForm extends PureComponent { ...@@ -140,7 +116,43 @@ class AdvancedForm extends PureComponent {
</span> </span>
); );
}; };
resizeFooterToolbar = () => {
requestAnimationFrame(() => {
const sider = document.querySelectorAll('.ant-layout-sider')[0];
if (sider) {
const width = `calc(100% - ${sider.style.width})`;
const { width: stateWidth } = this.state;
if (stateWidth !== width) {
this.setState({ width });
}
}
});
};
validate = () => {
const {
form: { validateFieldsAndScroll },
dispatch,
} = this.props;
validateFieldsAndScroll((error, values) => {
if (!error) {
// submit the values
dispatch({
type: 'form/submitAdvancedForm',
payload: values,
});
}
});
};
render() {
const {
form: { getFieldDecorator },
submitting,
} = this.props;
const { width } = this.state; const { width } = this.state;
return ( return (
<PageHeaderWrapper <PageHeaderWrapper
title="高级表单" title="高级表单"
...@@ -298,8 +310,8 @@ class AdvancedForm extends PureComponent { ...@@ -298,8 +310,8 @@ class AdvancedForm extends PureComponent {
})(<TableForm />)} })(<TableForm />)}
</Card> </Card>
<FooterToolbar style={{ width }}> <FooterToolbar style={{ width }}>
{getErrorInfo()} {this.getErrorInfo()}
<Button type="primary" onClick={validate} loading={submitting}> <Button type="primary" onClick={this.validate} loading={submitting}>
提交 提交
</Button> </Button>
</FooterToolbar> </FooterToolbar>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment