modalFormDemo.jsx 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. import React, { useState, useLayoutEffect } from 'react';
  2. import { Form, Button, Icon, Row, Col, Modal } from '../../../index';
  3. class ModalFormDemo extends React.Component {
  4. constructor(props) {
  5. super(props);
  6. this.state = {
  7. visible: false,
  8. };
  9. this.showDialog = this.showDialog.bind(this);
  10. this.handleOk = this.handleOk.bind(this);
  11. this.handleCancel = this.handleCancel.bind(this);
  12. this.getFormApi = this.getFormApi.bind(this);
  13. }
  14. showDialog() {
  15. this.setState({ visible: true });
  16. }
  17. handleOk() {
  18. this.formApi
  19. .validate()
  20. .then(values => {
  21. console.log(values);
  22. })
  23. .catch(errors => {
  24. console.log(errors);
  25. });
  26. }
  27. handleCancel() {
  28. this.setState({ visible: false });
  29. }
  30. getFormApi(formApi) {
  31. this.formApi = formApi;
  32. }
  33. render() {
  34. const { visible } = this.state;
  35. let message = '该项为必填项';
  36. return (
  37. <>
  38. <Button onClick={this.showDialog}>打开弹窗</Button>
  39. <Modal title="新建" visible={visible} onOk={this.handleOk} onCancel={this.handleCancel}>
  40. <Form getFormApi={this.getFormApi}>
  41. <Row>
  42. <Col span={6}>
  43. <Form.Select
  44. field="region"
  45. label="国家/地区"
  46. placeholder="请选择"
  47. style={{ width: 100 }}
  48. rules={[{ required: true, message }]}
  49. >
  50. <Form.Select.Option value="China">中国</Form.Select.Option>
  51. <Form.Select.Option value="US">美国</Form.Select.Option>
  52. <Form.Select.Option value="Europe">欧洲</Form.Select.Option>
  53. <Form.Select.Option value="Japan">日本</Form.Select.Option>
  54. </Form.Select>
  55. </Col>
  56. <Col span={18}>
  57. <Form.Input field="owner" label="业务执行人" rules={[{ required: true, message }]} />
  58. </Col>
  59. <Col span={6}>
  60. <Form.Select
  61. field="area"
  62. label="投放区域"
  63. placeholder="请选择"
  64. style={{ width: 100 }}
  65. rules={[{ required: true, message }]}
  66. >
  67. <Form.Select.Option value="China">中国</Form.Select.Option>
  68. <Form.Select.Option value="US">美国</Form.Select.Option>
  69. <Form.Select.Option value="Europe">欧洲</Form.Select.Option>
  70. <Form.Select.Option value="Japan">日本</Form.Select.Option>
  71. </Form.Select>
  72. </Col>
  73. <Col span={18}>
  74. <Form.Input
  75. field="department"
  76. label="业务执行部门"
  77. rules={[{ required: true, message }]}
  78. />
  79. </Col>
  80. </Row>
  81. </Form>
  82. </Modal>
  83. </>
  84. );
  85. }
  86. }
  87. export { ModalFormDemo };