CreateChildrenModal.js 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. import { CloudUploadOutlined } from '@ant-design/icons';
  2. import { Modal, Form, Input, Button, Upload } from 'antd';
  3. import { useEffect, useState } from 'react';
  4. import { getRandomString } from '@/utils/utils';
  5. const CreateChildrenModal = ({
  6. loading,
  7. parentId,
  8. open,
  9. onOk,
  10. handleCancel,
  11. }) => {
  12. const [form] = Form.useForm();
  13. const layout = {
  14. labelCol: { span: 6 },
  15. wrapperCol: { span: 16 },
  16. };
  17. const [upLoading, setUpLoading] = useState([]);
  18. const [cadPath, setCadPath] = useState([]);
  19. useEffect(() => {
  20. if (!open) return;
  21. setCadPath([]);
  22. form.resetFields();
  23. }, [open]);
  24. // function dwgUpload() {
  25. // let uploadDwg = document.getElementById('uploadDwg');
  26. // uploadDwg.click();
  27. // }
  28. // function uploadDwg(event) {
  29. // const selectedFile = event.target.files[0];
  30. // if (selectedFile) {
  31. // setUpLoading(true);
  32. // ZwCloud2D.ZwDataProcessor.uploadDwg(selectedFile).then((res) => {
  33. // if (res.code == 200) {
  34. // const oldPath = form.getFieldValue('cad_path');
  35. // const cad_path = oldPath
  36. // ? oldPath + ',' + res.data.path
  37. // : res.data.path;
  38. // form.setFieldsValue({ cad_path });
  39. // }
  40. // setUpLoading(false);
  41. // });
  42. // }
  43. // }
  44. const UploadProps = {
  45. action: `https://cad.greentech.com.cn/sdk/doc/upload`,
  46. multiple: true,
  47. data: { path: getRandomString() },
  48. headers: {
  49. 'JWT-TOKEN': localStorage.getItem('JWT-TOKEN'),
  50. },
  51. onChange({ file, fileList }) {
  52. if (file.status !== 'uploading') {
  53. setCadPath([...cadPath, file.response.data.path]);
  54. }
  55. },
  56. };
  57. const handleOk = () => {
  58. form.validateFields().then((values) => {
  59. values.parent_id = parentId;
  60. if (!values.remark) values.remark = '';
  61. if (!values.cad_path) values.cad_path = cadPath.join(',');
  62. console.log(values);
  63. onOk(values);
  64. });
  65. };
  66. return (
  67. <Modal
  68. title="新建版本"
  69. width={800}
  70. open={open}
  71. confirmLoading={loading}
  72. onOk={handleOk}
  73. onCancel={handleCancel}
  74. >
  75. <Form {...layout} name="basic" form={form}>
  76. <Form.Item name="version" label="版本:" rules={[{ required: true }]}>
  77. <Input />
  78. </Form.Item>
  79. <Form.Item label="上传:">
  80. <Upload {...UploadProps}>
  81. <Button icon={<CloudUploadOutlined />}>Upload</Button>
  82. </Upload>
  83. </Form.Item>
  84. <Form.Item name="remark" label="备注:">
  85. <Input.TextArea />
  86. </Form.Item>
  87. </Form>
  88. </Modal>
  89. );
  90. };
  91. export default CreateChildrenModal;