通用评论 vedio

index.js 2.1KB

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