Browse Source

fix:图片文件初始化列表

zhengyingya 5 years ago
parent
commit
6f14d30ed3
2 changed files with 50 additions and 7 deletions
  1. 9
    2
      src/components/Editor/index.js
  2. 41
    5
      src/index.js

+ 9
- 2
src/components/Editor/index.js View File

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

+ 41
- 5
src/index.js View File

3
 import App, { Editor } from "./App";
3
 import App, { Editor } from "./App";
4
 // import registerServiceWorker from "./registerServiceWorker";
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
  * 渲染评论组件