张延森 5 years ago
parent
commit
919cad8fc6
1 changed files with 14 additions and 12 deletions
  1. 14
    12
      src/components/uploadImage/ImageUpload.jsx

+ 14
- 12
src/components/uploadImage/ImageUpload.jsx View File

12
     fileList: [],
12
     fileList: [],
13
   };
13
   };
14
 
14
 
15
-  handleChange = info => {
16
-    this.setState({ fileList: info.fileList })
17
-    if (info.file.status === "uploading") {
18
-      this.setState({ loading: true });
19
-      return;
20
-    }
21
-  };
15
+  handleChange = ({ file, fileList }) => {
16
+    const { status, response } = file
17
+    this.setState({ fileList, loading: status === "uploading" })
22
 
18
 
23
-  handleUploadSucess = (url) => {
24
-    console.log(url,"33-------")
25
     if (typeof this.props.onChange === 'function') {
19
     if (typeof this.props.onChange === 'function') {
26
-      this.props.onChange(url);
20
+      const image = status === 'done' ? response : undefined
21
+      this.props.onChange(image);
27
     }
22
     }
28
-  }
23
+  };
24
+
25
+  // handleUploadSucess = (url) => {
26
+  //   console.log(url,"33-------")
27
+  //   if (typeof this.props.onChange === 'function') {
28
+  //     this.props.onChange(url);
29
+  //   }
30
+  // }
29
 
31
 
30
   render() {
32
   render() {
31
     const uploadButton = (
33
     const uploadButton = (
41
         className="avatar-uploader"
43
         className="avatar-uploader"
42
         onChange={this.handleChange}
44
         onChange={this.handleChange}
43
         fileList={this.state.fileList}
45
         fileList={this.state.fileList}
44
-        onSuccess={this.handleUploadSucess}
46
+        // onSuccess={this.handleUploadSucess}
45
       >
47
       >
46
         {this.state.fileList.length >= 1 ? null : uploadButton}  
48
         {this.state.fileList.length >= 1 ? null : uploadButton}  
47
       </Upload>
49
       </Upload>