addRegular.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. import React, {
  2. useState, useEffect, useContext
  3. } from 'react';
  4. import { Form, Col, DatePicker, Button, Radio, TreeSelect, 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 { regularDetail, type } = useContext(RegularContext);
  14. const initialValues = regularDetail;
  15. const onFinish = values => {
  16. addRegular(values)
  17. };
  18. //添加
  19. function addRegular(params) {
  20. let url
  21. if(type == 1){
  22. url = api.addRegular
  23. }else{
  24. url = api.upRegularById
  25. params.id= regularDetail.id
  26. }
  27. post(url, params).then((res) => {
  28. if (res.data.code === 200) {
  29. props.userChange()
  30. message.success(res.data.message);
  31. form.resetFields();
  32. } else {
  33. message.error(res.data.message);
  34. }
  35. })
  36. }
  37. function cancel() {
  38. props.userChange()
  39. }
  40. return (
  41. <>
  42. <Form
  43. labelCol={{ span: 6 }}
  44. wrapperCol={{ span: 16 }}
  45. form={form}
  46. name="register"
  47. layout='horizontal'
  48. onFinish={onFinish}
  49. initialValues={initialValues}
  50. >
  51. <Form.Item label="正则式名称" name="name" rules={[{ required: true }]}>
  52. <Input placeholder="请输入" autoComplete='off' />
  53. </Form.Item>
  54. <Form.Item label="正则式值" name="val" rules={[{ required: true }]}>
  55. <TextArea
  56. autoSize={{ minRows: 5, maxRows: 5 }}
  57. />
  58. </Form.Item>
  59. <Form.Item label="说明" name="description">
  60. <TextArea
  61. autoSize={{ minRows: 5, maxRows: 5 }}
  62. />
  63. </Form.Item>
  64. <Form.Item wrapperCol={{ offset: 8, span: 16 }} style={{ marginTop: 15 }}>
  65. <Space size="middle" >
  66. <Button htmlType="button" onClick={e => cancel()}>
  67. 取消
  68. </Button>
  69. <Button type="primary" htmlType="submit">
  70. 保存
  71. </Button>
  72. </Space>
  73. </Form.Item>
  74. </Form>
  75. </>
  76. );
  77. }
  78. export default EditBlock;