BasicForm.js 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. import React, { PureComponent } from 'react';
  2. import { connect } from 'dva';
  3. import { formatMessage, FormattedMessage } from 'umi/locale';
  4. import {
  5. Form,
  6. Input,
  7. DatePicker,
  8. Select,
  9. Button,
  10. Card,
  11. InputNumber,
  12. Radio,
  13. Icon,
  14. Tooltip,
  15. } from 'antd';
  16. import PageHeaderWrapper from '@/components/PageHeaderWrapper';
  17. import styles from './style.less';
  18. const FormItem = Form.Item;
  19. const { Option } = Select;
  20. const { RangePicker } = DatePicker;
  21. const { TextArea } = Input;
  22. @connect(({ loading }) => ({
  23. submitting: loading.effects['form/submitRegularForm'],
  24. }))
  25. @Form.create()
  26. class BasicForms extends PureComponent {
  27. handleSubmit = e => {
  28. const { dispatch, form } = this.props;
  29. e.preventDefault();
  30. form.validateFieldsAndScroll((err, values) => {
  31. if (!err) {
  32. dispatch({
  33. type: 'form/submitRegularForm',
  34. payload: values,
  35. });
  36. }
  37. });
  38. };
  39. render() {
  40. const { submitting } = this.props;
  41. const {
  42. form: { getFieldDecorator, getFieldValue },
  43. } = this.props;
  44. const formItemLayout = {
  45. labelCol: {
  46. xs: { span: 24 },
  47. sm: { span: 7 },
  48. },
  49. wrapperCol: {
  50. xs: { span: 24 },
  51. sm: { span: 12 },
  52. md: { span: 10 },
  53. },
  54. };
  55. const submitFormLayout = {
  56. wrapperCol: {
  57. xs: { span: 24, offset: 0 },
  58. sm: { span: 10, offset: 7 },
  59. },
  60. };
  61. return (
  62. <PageHeaderWrapper
  63. title={<FormattedMessage id="app.forms.basic.title" />}
  64. content={<FormattedMessage id="app.forms.basic.description" />}
  65. >
  66. <Card bordered={false}>
  67. <Form onSubmit={this.handleSubmit} hideRequiredMark style={{ marginTop: 8 }}>
  68. <FormItem {...formItemLayout} label={<FormattedMessage id="form.title.label" />}>
  69. {getFieldDecorator('title', {
  70. rules: [
  71. {
  72. required: true,
  73. message: formatMessage({ id: 'validation.title.required' }),
  74. },
  75. ],
  76. })(<Input placeholder={formatMessage({ id: 'form.title.placeholder' })} />)}
  77. </FormItem>
  78. <FormItem {...formItemLayout} label={<FormattedMessage id="form.date.label" />}>
  79. {getFieldDecorator('date', {
  80. rules: [
  81. {
  82. required: true,
  83. message: formatMessage({ id: 'validation.date.required' }),
  84. },
  85. ],
  86. })(
  87. <RangePicker
  88. style={{ width: '100%' }}
  89. placeholder={[
  90. formatMessage({ id: 'form.date.placeholder.start' }),
  91. formatMessage({ id: 'form.date.placeholder.end' }),
  92. ]}
  93. />
  94. )}
  95. </FormItem>
  96. <FormItem {...formItemLayout} label={<FormattedMessage id="form.goal.label" />}>
  97. {getFieldDecorator('goal', {
  98. rules: [
  99. {
  100. required: true,
  101. message: formatMessage({ id: 'validation.goal.required' }),
  102. },
  103. ],
  104. })(
  105. <TextArea
  106. style={{ minHeight: 32 }}
  107. placeholder={formatMessage({ id: 'form.goal.placeholder' })}
  108. rows={4}
  109. />
  110. )}
  111. </FormItem>
  112. <FormItem {...formItemLayout} label={<FormattedMessage id="form.standard.label" />}>
  113. {getFieldDecorator('standard', {
  114. rules: [
  115. {
  116. required: true,
  117. message: formatMessage({ id: 'validation.standard.required' }),
  118. },
  119. ],
  120. })(
  121. <TextArea
  122. style={{ minHeight: 32 }}
  123. placeholder={formatMessage({ id: 'form.standard.placeholder' })}
  124. rows={4}
  125. />
  126. )}
  127. </FormItem>
  128. <FormItem
  129. {...formItemLayout}
  130. label={
  131. <span>
  132. <FormattedMessage id="form.client.label" />
  133. <em className={styles.optional}>
  134. <FormattedMessage id="form.optional" />
  135. <Tooltip title={<FormattedMessage id="form.client.label.tooltip" />}>
  136. <Icon type="info-circle-o" style={{ marginRight: 4 }} />
  137. </Tooltip>
  138. </em>
  139. </span>
  140. }
  141. >
  142. {getFieldDecorator('client')(
  143. <Input placeholder={formatMessage({ id: 'form.client.placeholder' })} />
  144. )}
  145. </FormItem>
  146. <FormItem
  147. {...formItemLayout}
  148. label={
  149. <span>
  150. <FormattedMessage id="form.invites.label" />
  151. <em className={styles.optional}>
  152. <FormattedMessage id="form.optional" />
  153. </em>
  154. </span>
  155. }
  156. >
  157. {getFieldDecorator('invites')(
  158. <Input placeholder={formatMessage({ id: 'form.invites.placeholder' })} />
  159. )}
  160. </FormItem>
  161. <FormItem
  162. {...formItemLayout}
  163. label={
  164. <span>
  165. <FormattedMessage id="form.weight.label" />
  166. <em className={styles.optional}>
  167. <FormattedMessage id="form.optional" />
  168. </em>
  169. </span>
  170. }
  171. >
  172. {getFieldDecorator('weight')(
  173. <InputNumber
  174. placeholder={formatMessage({ id: 'form.weight.placeholder' })}
  175. min={0}
  176. max={100}
  177. />
  178. )}
  179. <span className="ant-form-text">%</span>
  180. </FormItem>
  181. <FormItem
  182. {...formItemLayout}
  183. label={<FormattedMessage id="form.public.label" />}
  184. help={<FormattedMessage id="form.public.label.help" />}
  185. >
  186. <div>
  187. {getFieldDecorator('public', {
  188. initialValue: '1',
  189. })(
  190. <Radio.Group>
  191. <Radio value="1">
  192. <FormattedMessage id="form.public.radio.public" />
  193. </Radio>
  194. <Radio value="2">
  195. <FormattedMessage id="form.public.radio.partially-public" />
  196. </Radio>
  197. <Radio value="3">
  198. <FormattedMessage id="form.public.radio.private" />
  199. </Radio>
  200. </Radio.Group>
  201. )}
  202. <FormItem style={{ marginBottom: 0 }}>
  203. {getFieldDecorator('publicUsers')(
  204. <Select
  205. mode="multiple"
  206. placeholder={formatMessage({ id: 'form.publicUsers.placeholder' })}
  207. style={{
  208. margin: '8px 0',
  209. display: getFieldValue('public') === '2' ? 'block' : 'none',
  210. }}
  211. >
  212. <Option value="1">
  213. <FormattedMessage id="form.publicUsers.option.A" />
  214. </Option>
  215. <Option value="2">
  216. <FormattedMessage id="form.publicUsers.option.B" />
  217. </Option>
  218. <Option value="3">
  219. <FormattedMessage id="form.publicUsers.option.C" />
  220. </Option>
  221. </Select>
  222. )}
  223. </FormItem>
  224. </div>
  225. </FormItem>
  226. <FormItem {...submitFormLayout} style={{ marginTop: 32 }}>
  227. <Button type="primary" htmlType="submit" loading={submitting}>
  228. <FormattedMessage id="form.submit" />
  229. </Button>
  230. <Button style={{ marginLeft: 8 }}>
  231. <FormattedMessage id="form.save" />
  232. </Button>
  233. </FormItem>
  234. </Form>
  235. </Card>
  236. </PageHeaderWrapper>
  237. );
  238. }
  239. }
  240. export default BasicForms;