Browse Source

add:评论失败回调

zhengyingya 4 years ago
parent
commit
865439d159
2 changed files with 15 additions and 4 deletions
  1. 12
    4
      src/App.js
  2. 3
    0
      src/index.js

+ 12
- 4
src/App.js View File

@@ -310,7 +310,10 @@ class App extends Component {
310 310
         this.setState({ list, total: total + 1 });
311 311
         this.props.onCountChange(total + 1);
312 312
       })
313
-      .catch(this.errorHandler)
313
+      .catch(error => {
314
+        this.props.onCommentFail(error.response.status);
315
+        this.errorHandler(error);
316
+      })
314 317
       .finally(() => {
315 318
         this.handleChangeLoading("sCreateComment", false);
316 319
       });
@@ -407,7 +410,10 @@ class App extends Component {
407 410
         });
408 411
         this.setState({ list });
409 412
       })
410
-      .catch(this.errorHandler)
413
+      .catch(error => {
414
+        this.props.onCommentFail(error.response.status);
415
+        this.errorHandler(error);
416
+      })
411 417
       .finally(() => {
412 418
         this.handleChangeLoading("sCreateReply", false);
413 419
       });
@@ -640,7 +646,8 @@ App.propTypes = {
640 646
   onDelete: PropTypes.func,
641 647
   onUpdateComment: PropTypes.func,
642 648
   locales: PropTypes.string, //  传入的语言环境, en-US/zh-CN
643
-  onCountChange: PropTypes.func // 评论数量变更时的回调
649
+  onCountChange: PropTypes.func, // 评论数量变更时的回调
650
+  onCommentFail: PropTypes.func // 评论失败时的回调
644 651
 };
645 652
 
646 653
 App.defaultProps = {
@@ -665,7 +672,8 @@ App.defaultProps = {
665 672
   onDelete: () => {},
666 673
   onUpdateComment: () => {},
667 674
   onBeforeUpdateComment: () => {},
668
-  onCountChange: () => {}
675
+  onCountChange: () => {},
676
+  onCommentFail: () => {}
669 677
 };
670 678
 
671 679
 export { Editor, RenderText };

+ 3
- 0
src/index.js View File

@@ -147,6 +147,9 @@ if (process.env.NODE_ENV !== "production") {
147 147
     onDelete: (type, data) => {
148 148
       console.log(type, data);
149 149
     },
150
+    onCommentFail: data => {
151
+      console.log("onCommentFail", data);
152
+    },
150 153
     onUpdateComment: (type, data) => {
151 154
       console.log("onUpdateComment", type);
152 155
     },