No Description

index.jsx 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. import React from 'react';
  2. import { getComment } from '@/services/comment';
  3. import { CommentContext, DefaultValue } from './context';
  4. import styles from './index.less';
  5. import CommentList from './CommentList';
  6. export class CommentCombine extends React.PureComponent {
  7. constructor(props) {
  8. super(props);
  9. this.state = {
  10. ...DefaultValue,
  11. }
  12. }
  13. render() {
  14. return (
  15. <CommentContext.Provider value={this.state}>
  16. <Comment />
  17. </CommentContext.Provider>
  18. )
  19. }
  20. }
  21. export class Comment extends React.PureComponent {
  22. static contextType = CommentContext;
  23. static propTypes = {}
  24. static defaultProps = {}
  25. constructor(props) {
  26. super(props);
  27. this.state = {
  28. comment_data: null,
  29. };
  30. }
  31. componentDidMount = async () => {
  32. const { type, limit, page, bussiness_id } = this.context;
  33. const res = await getComment({
  34. type,
  35. limit,
  36. page,
  37. businessId: bussiness_id,
  38. });
  39. console.log("res:", res);
  40. this.setState({
  41. comment_data: res,
  42. })
  43. }
  44. renderCommentList = (list) => {
  45. // content: "[e101][e102]"
  46. // created: 1582352617
  47. // favor_count: 0
  48. // favored: false
  49. // id: "5e50c8e9818eda000192773d"
  50. // is_speak: false
  51. // medias: null
  52. // replies: []
  53. // reply_count: 0
  54. // user_avatar: "https://links123-images.oss-cn-hangzhou.aliyuncs.com/avatar/2020/2/7/1326acc4b1609c8ecf52e94d58a38384.jpg?x-oss-process=image/resize,h_100"
  55. // user_id: 71770
  56. // user_name: "EvoKou"
  57. return <CommentList list={list} />
  58. }
  59. renderComment = () => {
  60. const { comment_data } = this.state;
  61. if (comment_data === null) return "数据载入中";
  62. const { list, total, page } = comment_data;
  63. return (
  64. <div>
  65. total: {total}
  66. page: {page}
  67. <div>
  68. {
  69. this.renderCommentList(list)
  70. }
  71. </div>
  72. </div>
  73. )
  74. }
  75. render() {
  76. console.log("context", this.context);
  77. return (
  78. <div>
  79. {JSON.stringify(this.context)}
  80. {this.renderComment()}
  81. </div>
  82. )
  83. }
  84. }
  85. export default CommentCombine;