瀏覽代碼

修改路由

Renxy 1 年之前
父節點
當前提交
67c1c249be
共有 2 個文件被更改,包括 44 次插入58 次删除
  1. 22 20
      src/pages/Cad/components/CreateChildrenModal.js
  2. 22 38
      src/pages/Cad/components/CreateModal.js

+ 22 - 20
src/pages/Cad/components/CreateChildrenModal.js

@@ -1,6 +1,7 @@
 import { CloudUploadOutlined } from '@ant-design/icons';
-import { Modal, Form, Input, Button } from 'antd';
+import { Modal, Form, Input, Button, Upload } from 'antd';
 import { useEffect, useState } from 'react';
+import { getRandomString } from '@/utils/utils';
 
 const CreateChildrenModal = ({
   loading,
@@ -15,9 +16,11 @@ const CreateChildrenModal = ({
     wrapperCol: { span: 16 },
   };
   const [upLoading, setUpLoading] = useState([]);
+  const [cadPath, setCadPath] = useState([]);
 
   useEffect(() => {
     if (!open) return;
+    setCadPath([]);
     form.resetFields();
   }, [open]);
 
@@ -42,11 +45,24 @@ const CreateChildrenModal = ({
       });
     }
   }
+  const UploadProps = {
+    action: `https://cad.greentech.com.cn/sdk/doc/upload`,
+    multiple: true,
+    data: { path: getRandomString() },
+    headers: {
+      'JWT-TOKEN': localStorage.getItem('JWT-TOKEN'),
+    },
+    onChange({ file, fileList }) {
+      if (file.status !== 'uploading') {
+        setCadPath([...cadPath, file.response.data.path]);
+      }
+    },
+  };
 
   const handleOk = () => {
     form.validateFields().then((values) => {
-      if (!values.cad_path) values.cad_path = 'test';
       values.parent_id = parentId;
+      if (!values.cad_path) values.cad_path = cadPath.join(',');
       console.log(values);
       onOk(values);
     });
@@ -65,29 +81,15 @@ const CreateChildrenModal = ({
         <Form.Item name="version" label="版本:" rules={[{ required: true }]}>
           <Input />
         </Form.Item>
-        <Form.Item name="cad_path" label="上传:">
-          <Button
-            loading={upLoading}
-            icon={<CloudUploadOutlined />}
-            onClick={dwgUpload}
-          >
-            上传
-          </Button>
-          {form.getFieldValue('cad_path')}
+        <Form.Item label="上传:">
+          <Upload {...UploadProps}>
+            <Button icon={<CloudUploadOutlined />}>Upload</Button>
+          </Upload>
         </Form.Item>
         <Form.Item name="remark" label="备注:">
           <Input.TextArea />
         </Form.Item>
       </Form>
-
-      <input
-        // multiple
-        style={{ display: 'none' }}
-        id="uploadDwg"
-        type="file"
-        onChange={uploadDwg}
-        accept=".dwg, .dxf"
-      />
     </Modal>
   );
 };

+ 22 - 38
src/pages/Cad/components/CreateModal.js

@@ -60,6 +60,7 @@ const CreateModal = ({
   useEffect(() => {
     if (!open) return;
     form.resetFields();
+    setCadPath([]);
     setApprovalProcess([]);
     userListRun();
     const params = { ...advance };
@@ -84,28 +85,27 @@ const CreateModal = ({
     },
   );
 
-  function dwgUpload() {
-    let uploadDwg = document.getElementById('uploadDwg');
-    uploadDwg.click();
-  }
+  // function dwgUpload() {
+  //   let uploadDwg = document.getElementById('uploadDwg');
+  //   uploadDwg.click();
+  // }
 
-  function uploadDwg(event) {
-    const selectedFile = event.target.files[0];
-    if (selectedFile) {
-      // ZwCloud2D.ZwEditor.ZwSetLoadingState(true);
-      setUpLoading(true);
-      ZwCloud2D.ZwDataProcessor.uploadDwg(selectedFile).then((res) => {
-        if (res.code == 200) {
-          const oldPath = form.getFieldValue('cad_path');
-          const cad_path = oldPath
-            ? oldPath + ',' + res.data.path
-            : res.data.path;
-          form.setFieldsValue({ cad_path });
-        }
-        setUpLoading(false);
-      });
-    }
-  }
+  // function uploadDwg(event) {
+  //   const selectedFile = event.target.files[0];
+  //   if (selectedFile) {
+  //     setUpLoading(true);
+  //     ZwCloud2D.ZwDataProcessor.uploadDwg(selectedFile).then((res) => {
+  //       if (res.code == 200) {
+  //         const oldPath = form.getFieldValue('cad_path');
+  //         const cad_path = oldPath
+  //           ? oldPath + ',' + res.data.path
+  //           : res.data.path;
+  //         form.setFieldsValue({ cad_path });
+  //       }
+  //       setUpLoading(false);
+  //     });
+  //   }
+  // }
   const UploadProps = {
     action: `https://cad.greentech.com.cn/sdk/doc/upload`,
     multiple: true,
@@ -211,17 +211,10 @@ const CreateModal = ({
               <Input />
             </Form.Item>
             <Form.Item label="上传:">
-              {/* <Button
-                loading={upLoading}
-                icon={<CloudUploadOutlined />}
-                onClick={dwgUpload}
-              >
-                上传
-              </Button> */}
               <Upload {...UploadProps}>
                 <Button icon={<CloudUploadOutlined />}>Upload</Button>
               </Upload>
-              {form.getFieldValue('cad_path')}
+              {/* {form.getFieldValue('cad_path')} */}
             </Form.Item>
             <Form.Item name="remark" label="备注:">
               <Input.TextArea />
@@ -236,15 +229,6 @@ const CreateModal = ({
           />
         </Col>
       </Row>
-
-      {/* <input
-        // multiple
-        style={{ display: 'none' }}
-        id="uploadDwg"
-        type="file"
-        onChange={uploadDwg}
-        accept=".dwg, .dxf"
-      /> */}
     </Modal>
   );
 };