Bladeren bron

fix:图片文件初始化列表

zhengyingya 5 jaren geleden
bovenliggende
commit
6f14d30ed3
2 gewijzigde bestanden met toevoegingen van 50 en 7 verwijderingen
  1. 9
    2
      src/components/Editor/index.js
  2. 41
    5
      src/index.js

+ 9
- 2
src/components/Editor/index.js Bestand weergeven

@@ -83,6 +83,7 @@ class Editor extends React.Component {
83 83
     if (fileList.length > this.props.maxUpload) {
84 84
       list = fileList.slice(0, this.props.maxUpload);
85 85
     }
86
+    this.props.handleChangeFileList(list);
86 87
     this.setState({ fileList: list });
87 88
   }
88 89
 
@@ -131,6 +132,10 @@ class Editor extends React.Component {
131 132
     const files = [];
132 133
     if (fileList.length) {
133 134
       fileList.forEach(item => {
135
+        if (item.url) {
136
+          files.push(item.url);
137
+          return;
138
+        }
134 139
         if (!fileMap[item.uid]) {
135 140
           return;
136 141
         }
@@ -180,6 +185,7 @@ class Editor extends React.Component {
180 185
       emojiPopoverPlacement,
181 186
       uploadPopoverPlacement,
182 187
       uploadOverlayClassName,
188
+      fileList,
183 189
       closeUploadWhenBlur,
184 190
       maxUpload,
185 191
       // btnSubmitText,
@@ -199,6 +205,7 @@ class Editor extends React.Component {
199 205
       btnDisabled ||
200 206
       (!this.props.value && !this.state.value && !this.state.fileList.length);
201 207
     const inputValue = value || this.state.value;
208
+    const uploadFileList = fileList || this.state.fileList;
202 209
     return (
203 210
       <div className="comment-editor-container">
204 211
         <div
@@ -279,7 +286,7 @@ class Editor extends React.Component {
279 286
                         onChangeFileList={this.handleChangeFileList}
280 287
                         onUpload={this.handleUpload}
281 288
                         maxUpload={maxUpload}
282
-                        fileList={this.state.fileList}
289
+                        fileList={uploadFileList}
283 290
                         showError={this.props.showError}
284 291
                         onError={this.props.onError}
285 292
                       />
@@ -293,7 +300,7 @@ class Editor extends React.Component {
293 300
                         {maxUpload >= 2 ? (
294 301
                           <span style={{ color: "#666", fontWeight: 400 }}>
295 302
                             {intl.get("editor.uploadCount", {
296
-                              count: maxUpload - this.state.fileList.length
303
+                              count: maxUpload - uploadFileList.length
297 304
                             })}
298 305
                           </span>
299 306
                         ) : null}

+ 41
- 5
src/index.js Bestand weergeven

@@ -3,11 +3,47 @@ import ReactDOM from "react-dom";
3 3
 import App, { Editor } from "./App";
4 4
 // import registerServiceWorker from "./registerServiceWorker";
5 5
 
6
-const Index = props => (
7
-  <App showAlertComment showAlertReply showAlertFavor showError {...props}>
8
-    <Editor maxUpload={9} autoFocus {...props.editorProps} />
9
-  </App>
10
-);
6
+class Index extends React.Component {
7
+  constructor(props) {
8
+    super(props);
9
+    this.state = {
10
+      fileList: [
11
+        {
12
+          uid: "1",
13
+          name: "xxx.png",
14
+          status: "done",
15
+          response: "success", // custom error message to show
16
+          url:
17
+            "//links-comment.oss-cn-beijing.aliyuncs.com/comment/20190617/UCs7aXEjW.jpeg"
18
+        }
19
+      ]
20
+    };
21
+  }
22
+
23
+  render() {
24
+    return (
25
+      <App
26
+        showAlertComment
27
+        showAlertReply
28
+        showAlertFavor
29
+        showError
30
+        {...this.props}
31
+      >
32
+        <Editor
33
+          maxUpload={9}
34
+          autoFocus
35
+          {...this.props.editorProps}
36
+          fileList={this.state.fileList}
37
+          handleChangeFileList={fileList => {
38
+            this.setState({
39
+              fileList
40
+            });
41
+          }}
42
+        />
43
+      </App>
44
+    );
45
+  }
46
+}
11 47
 
12 48
 /**
13 49
  * 渲染评论组件