BladeX/blade-ops/blade-develop/target/classes/templates/sword/add.js.vm

74 lines
2.0 KiB
Plaintext
Raw Normal View History

2019-01-30 17:06:23 +08:00
#set($upperEntityPath=$table.entityPath.toUpperCase())
import React, { PureComponent } from 'react';
import { Form, Input, Card, Button } from 'antd';
import { connect } from 'dva';
import Panel from '../../../components/Panel';
import styles from '../../../layouts/Sword.less';
import { $!{upperEntityPath}_SUBMIT } from '../../../actions/$!{table.entityPath}';
const FormItem = Form.Item;
@connect(({ loading }) => ({
submitting: loading.effects['$!{table.entityPath}/submit'],
}))
@Form.create()
class $!{entity}Add extends PureComponent {
handleSubmit = e => {
e.preventDefault();
const { dispatch, form } = this.props;
form.validateFieldsAndScroll((err, values) => {
if (!err) {
dispatch($!{upperEntityPath}_SUBMIT(values));
}
});
};
render() {
const {
form: { getFieldDecorator },
submitting,
} = this.props;
const formItemLayout = {
labelCol: {
xs: { span: 24 },
sm: { span: 7 },
},
wrapperCol: {
xs: { span: 24 },
sm: { span: 12 },
md: { span: 10 },
},
};
const action = (
<Button type="primary" onClick={this.handleSubmit} loading={submitting}>
提交
</Button>
);
return (
<Panel title="新增" back="/$!{cfg.servicePackage}/$!{table.entityPath}" action={action}>
<Form hideRequiredMark style={{ marginTop: 8 }}>
<Card className={styles.card} bordered={false}>
#foreach($field in $!{table.fields})
<FormItem {...formItemLayout} label="$!{field.comment}">
{getFieldDecorator('$!{field.propertyName}', {
rules: [
{
required: true,
message: '请输入$!{field.comment}',
},
],
})(<Input placeholder="请输入$!{field.comment}" />)}
</FormItem>
#end
</Card>
</Form>
</Panel>
);
}
}
export default $!{entity}Add;