Просмотр исходного кода

Merge branch 'release/v1.2.5' of npm/comment into master

AdamFu 4 лет назад
Родитель
Сommit
fb5b88213a
2 измененных файлов: 20 добавлений и 5 удалений
  1. 8
    2
      src/App.js
  2. 12
    3
      src/components/EditComment/EditComment.js

+ 8
- 2
src/App.js Просмотреть файл

@@ -346,7 +346,7 @@ class App extends Component {
346 346
    * 更新评论
347 347
    * @param {object} {content} comment content
348 348
    */
349
-  sUpdateComment({ commentId, content }) {
349
+  sUpdateComment({ commentId, content, successCallback }) {
350 350
     this.handleChangeLoading("sUpdateComment", true);
351 351
     const { API } = this.props;
352 352
     this.axios(`${API}/comments/${commentId}`, {
@@ -369,6 +369,9 @@ class App extends Component {
369 369
         });
370 370
         this.props.onUpdateComment("comment");
371 371
         this.setState({ list });
372
+        if (successCallback) {
373
+          successCallback();
374
+        }
372 375
       })
373 376
       .catch(error => {
374 377
         this.props.onCommentFail(error.response.status, error.response.data);
@@ -458,7 +461,7 @@ class App extends Component {
458 461
    * 回复评论/回复回复
459 462
    * @param {object} data { comment_id, content, reply_id }
460 463
    */
461
-  sUpdateReply({ commentId, content, replyId, replyPage }) {
464
+  sUpdateReply({ commentId, content, replyId, replyPage, successCallback }) {
462 465
     this.handleChangeLoading("sUpdateReply", true);
463 466
     const { API } = this.props;
464 467
     this.axios(`${API}/replies/${replyId}`, {
@@ -473,6 +476,9 @@ class App extends Component {
473 476
         for (let i = 1; i <= replyPage; i++) {
474 477
           this.sGetReply({ commentId, page: i });
475 478
         }
479
+        if (successCallback) {
480
+          successCallback();
481
+        }
476 482
         this.props.onUpdateComment("reply");
477 483
       })
478 484
       .catch(error => {

+ 12
- 3
src/components/EditComment/EditComment.js Просмотреть файл

@@ -30,12 +30,21 @@ class EditComment extends React.Component {
30 30
     if (value.substr(-1) === ",") {
31 31
       value = value.slice(0, -1);
32 32
     }
33
+    // 成功回调,失败不自动关闭
34
+    const successCallback = () => {
35
+      this.props.handleClose();
36
+    };
33 37
     if (action === "comment") {
34
-      app.sUpdateComment({ commentId, content: value });
38
+      app.sUpdateComment({ commentId, content: value, successCallback });
35 39
     } else {
36
-      app.sUpdateReply({ commentId, content: value, replyId, replyPage });
40
+      app.sUpdateReply({
41
+        commentId,
42
+        content: value,
43
+        replyId,
44
+        replyPage,
45
+        successCallback
46
+      });
37 47
     }
38
-    this.props.handleClose();
39 48
   }
40 49
 
41 50
   getInitValue(props) {