傅行帆 před 5 roky
rodič
revize
ef0a83975e
1 změnil soubory, kde provedl 17 přidání a 7 odebrání
  1. 17
    7
      src/components/uploadImage/ImageUpload.jsx

+ 17
- 7
src/components/uploadImage/ImageUpload.jsx Zobrazit soubor

@@ -9,9 +9,19 @@ class ImageUpload extends React.Component {
9 9
 
10 10
   state = {
11 11
     loading: false,
12
+    previewVisible: false,
13
+    previewImage: '',
12 14
     fileList: [],
13 15
   };
14 16
 
17
+  componentDidUpdate() {  this.setState({ fileList: [{
18
+    uid: '-1',
19
+    name: 'image.png',
20
+    status: 'done',
21
+    url: this.props.value,
22
+  }] })  }
23
+
24
+
15 25
   handleChange = ({ file, fileList }) => {
16 26
     const { status, response } = file
17 27
     this.setState({ fileList, loading: status === "uploading" })
@@ -22,12 +32,12 @@ class ImageUpload extends React.Component {
22 32
     }
23 33
   };
24 34
 
25
-  // handleUploadSucess = (url) => {
26
-  //   console.log(url,"33-------")
27
-  //   if (typeof this.props.onChange === 'function') {
28
-  //     this.props.onChange(url);
29
-  //   }
30
-  // }
35
+  handlePreview = async file => {
36
+    this.setState({
37
+      previewImage: file.response,
38
+      previewVisible: true,
39
+    });
40
+  };
31 41
 
32 42
   render() {
33 43
     const uploadButton = (
@@ -43,7 +53,7 @@ class ImageUpload extends React.Component {
43 53
         className="avatar-uploader"
44 54
         onChange={this.handleChange}
45 55
         fileList={this.state.fileList}
46
-        // onSuccess={this.handleUploadSucess}
56
+        onPreview={this.handlePreview}
47 57
       >
48 58
         {this.state.fileList.length >= 1 ? null : uploadButton}  
49 59
       </Upload>