通用评论

index.js 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. import React, { Component } from "react";
  2. import { Spin, Pagination } from "antd";
  3. import intl from "react-intl-universal";
  4. import Comment from "../../Comment";
  5. import CommentBox from "../CommentBox";
  6. import "./index.css";
  7. class CommentList extends Component {
  8. constructor(props) {
  9. super(props);
  10. this.state = {};
  11. }
  12. componentWillMount() {
  13. this.props.app.sGetComment({ page: this.props.app.page });
  14. }
  15. renderPagination() {
  16. const {
  17. list,
  18. total,
  19. page,
  20. pageType,
  21. limit,
  22. isNoMoreComment,
  23. sGetComment,
  24. onPageChange,
  25. onGetMoreBtnClick
  26. } = this.props.app;
  27. if (pageType === "slice") {
  28. // 截断多余评论,通过点击查看更多跳转
  29. return (
  30. <div className="comment-list-show-more" onClick={onGetMoreBtnClick}>
  31. <span>查看更多</span>
  32. </div>
  33. );
  34. } else if (pageType === "more") {
  35. if (!isNoMoreComment && list.length !== total) {
  36. return (
  37. <div
  38. className="comment-list-show-more"
  39. onClick={() => {
  40. sGetComment({ page: page + 1 });
  41. onPageChange(page + 1);
  42. }}
  43. >
  44. <span>{intl.get("comment.moreComment")}</span>
  45. </div>
  46. );
  47. } else {
  48. return null;
  49. }
  50. } else if (pageType === "pagination") {
  51. return (
  52. <div className="comment-list-pagination">
  53. <Pagination
  54. pageSize={limit}
  55. current={page}
  56. total={total}
  57. onChange={p => {
  58. sGetComment({ page: p });
  59. onPageChange(p);
  60. }}
  61. />
  62. </div>
  63. );
  64. }
  65. }
  66. render() {
  67. const { list, total, loading, isMobile } = this.props.app;
  68. const spinning = Boolean(
  69. loading.sGetComment || loading.sCommentFavor || loading.sReplyFavor
  70. );
  71. return (
  72. <div>
  73. <Spin spinning={spinning}>
  74. {/* <div>共 {total} 条评论</div> */}
  75. <div>{intl.get("comment.totalComment", { total })}</div>
  76. {list.map(item => (
  77. <CommentBox
  78. isMobile={isMobile}
  79. content={item}
  80. key={item.id}
  81. commentId={item.id}
  82. />
  83. ))}
  84. {this.renderPagination()}
  85. </Spin>
  86. </div>
  87. );
  88. }
  89. }
  90. CommentList.propTypes = {};
  91. export default Comment(CommentList);