addRegular.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. import React, {
  2. useState, useEffect, useContext
  3. } from 'react';
  4. import { Form, Modal, Button, message, Space, Input } from 'antd';
  5. import apiObj from '@api/index';
  6. import RegularContext from './regular-context';
  7. const { post, api, xPost } = apiObj;
  8. const { TextArea } = Input;
  9. function EditBlock(props) {
  10. useEffect(() => {
  11. }, []);
  12. const [form] = Form.useForm();
  13. const [delvisible, setDelVisible] = useState(false);
  14. const { regularDetail, type, flag } = useContext(RegularContext);
  15. const initialValues = regularDetail;
  16. const onFinish = values => {
  17. if (flag == 1) {
  18. setDelVisible(true)
  19. } else {
  20. addRegular(values)
  21. }
  22. };
  23. //添加
  24. function addRegular(params) {
  25. let url
  26. if (type == 1) {
  27. url = api.addRegular
  28. } else {
  29. url = api.upRegularById
  30. params.id = regularDetail.id
  31. }
  32. post(url, params).then((res) => {
  33. if (res.data.code === 200) {
  34. props.userChange()
  35. message.success(res.data.message);
  36. form.resetFields();
  37. } else {
  38. message.error(res.data.message);
  39. }
  40. })
  41. }
  42. function cancel() {
  43. props.cancel()
  44. }
  45. return (
  46. <>
  47. <Form
  48. labelCol={{ span: 6 }}
  49. wrapperCol={{ span: 16 }}
  50. form={form}
  51. name="register"
  52. layout='horizontal'
  53. onFinish={onFinish}
  54. initialValues={initialValues}
  55. >
  56. <Form.Item label="正则式名称" name="name" rules={[{ required: true,message:'请输入正则式名称'},{ max: 30,message:'正则式名称不能超过30个字符' }]}>
  57. <Input placeholder="请输入" autoComplete='off'/>
  58. </Form.Item>
  59. <Form.Item label="正则式值" name="val" rules={[{ required: true }]}>
  60. <TextArea
  61. autoSize={{ minRows: 5, maxRows: 5 }}
  62. placeholder="请输入"
  63. />
  64. </Form.Item>
  65. <Form.Item label="说明" name="description" rules={[{ max: 200,message:'说明不能超过200个字符' }]}>
  66. <TextArea
  67. autoSize={{ minRows: 5, maxRows: 5 }}
  68. placeholder="请输入"
  69. />
  70. </Form.Item>
  71. <Form.Item wrapperCol={{ offset: 8, span: 16 }} style={{ marginTop: 15 }}>
  72. <Space size="middle" >
  73. <Button htmlType="button" onClick={e => cancel()}>
  74. 取消
  75. </Button>
  76. <Button type="primary" htmlType="submit">
  77. 保存
  78. </Button>
  79. </Space>
  80. </Form.Item>
  81. </Form>
  82. <Modal
  83. title="提示"
  84. okText='确定'
  85. cancelText='取消'
  86. width={400}
  87. visible={delvisible}
  88. onOk={addRegular}
  89. /*confirmLoading={confirmLoading}*/
  90. onCancel={() => cancel()}
  91. >
  92. <p>该正则式关联字段校验规则,修改后将同步更新,确认修改?</p>
  93. </Modal>
  94. </>
  95. );
  96. }
  97. export default EditBlock;