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
         this.setState({ list, total: total + 1 });
310
         this.setState({ list, total: total + 1 });
311
         this.props.onCountChange(total + 1);
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
       .finally(() => {
317
       .finally(() => {
315
         this.handleChangeLoading("sCreateComment", false);
318
         this.handleChangeLoading("sCreateComment", false);
316
       });
319
       });
407
         });
410
         });
408
         this.setState({ list });
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
       .finally(() => {
417
       .finally(() => {
412
         this.handleChangeLoading("sCreateReply", false);
418
         this.handleChangeLoading("sCreateReply", false);
413
       });
419
       });
640
   onDelete: PropTypes.func,
646
   onDelete: PropTypes.func,
641
   onUpdateComment: PropTypes.func,
647
   onUpdateComment: PropTypes.func,
642
   locales: PropTypes.string, //  传入的语言环境, en-US/zh-CN
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
 App.defaultProps = {
653
 App.defaultProps = {
665
   onDelete: () => {},
672
   onDelete: () => {},
666
   onUpdateComment: () => {},
673
   onUpdateComment: () => {},
667
   onBeforeUpdateComment: () => {},
674
   onBeforeUpdateComment: () => {},
668
-  onCountChange: () => {}
675
+  onCountChange: () => {},
676
+  onCommentFail: () => {}
669
 };
677
 };
670
 
678
 
671
 export { Editor, RenderText };
679
 export { Editor, RenderText };

+ 3
- 0
src/index.js View File

147
     onDelete: (type, data) => {
147
     onDelete: (type, data) => {
148
       console.log(type, data);
148
       console.log(type, data);
149
     },
149
     },
150
+    onCommentFail: data => {
151
+      console.log("onCommentFail", data);
152
+    },
150
     onUpdateComment: (type, data) => {
153
     onUpdateComment: (type, data) => {
151
       console.log("onUpdateComment", type);
154
       console.log("onUpdateComment", type);
152
     },
155
     },