index.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import React, { useState } from 'react';
  2. import { Modal, Input, message, Button, Row } from 'antd';
  3. import { subJsonService } from './service';
  4. export default function JsonImport({ refresh }) {
  5. const [visible, setvisible] = useState(false);
  6. const [loading, setLoading] = useState(false);
  7. const [areaChange, setAreaChange] = useState('');
  8. const { TextArea } = Input;
  9. const onExportPower2JsonModalCancel = () => {
  10. setAreaChange('');
  11. setvisible(false);
  12. };
  13. const submitJson = () => {
  14. setLoading(true);
  15. const param = JSON.parse(areaChange);
  16. subJsonService(param).then(res => {
  17. if (res?.code === 0) {
  18. message.success('导入成功');
  19. refresh();
  20. }
  21. setLoading(false);
  22. onExportPower2JsonModalCancel();
  23. });
  24. };
  25. const textOnChange = e => {
  26. setAreaChange(e.target.value);
  27. };
  28. return (
  29. <div style={{ display: 'inline-block' }}>
  30. <Modal
  31. title="导入"
  32. maskClosable={false}
  33. destroyOnClose
  34. visible={visible}
  35. width={700}
  36. footer={[
  37. <Button key="back" onClick={onExportPower2JsonModalCancel}>
  38. 关闭
  39. </Button>,
  40. <Button type="primary" key="submmit" onClick={submitJson} loading={loading}>
  41. 确定
  42. </Button>,
  43. ]}
  44. onCancel={onExportPower2JsonModalCancel}
  45. >
  46. <Row gutter={12}>
  47. <TextArea
  48. placeholder="需要导出的数据结构"
  49. rows={15}
  50. value={areaChange}
  51. onChange={(e, record) => {
  52. textOnChange(e, record);
  53. }}
  54. />
  55. </Row>
  56. </Modal>
  57. <div
  58. onClick={() => {
  59. setvisible(true);
  60. }}
  61. >
  62. <Button type="primary" style={{ marginLeft: 10 }}>
  63. 导入
  64. </Button>
  65. </div>
  66. </div>
  67. );
  68. }