通用评论

1
  1. {"version":3,"sources":["../../../src/components/CommentBox/index.js"],"names":["CommentBox","props","state","showReply","page","handleToggleReply","bind","handleGetMoreReply","renderReplies","setState","commentId","app","sGetReply","replies","replyCount","isNoMoreReply","length","len","marginLeft","map","item","index","id","intl","get","float","content","reply_count","Component","propTypes","PropTypes","string","isRequired","defaultProps"],"mappings":";;;;;;;;;;;;;;AAAA;;;;AACA;;;;AAEA;;;;AACA;;;;AACA;;;;AACA;;;;;;;;;;IAEMA,U;;;AACJ,sBAAYC,KAAZ,EAAmB;AAAA;;AAAA,wHACXA,KADW;;AAEjB,UAAKC,KAAL,GAAa;AACXC,iBAAW,IADA;AAEXC,YAAM;AAFK,KAAb;;AAKA,UAAKC,iBAAL,GAAyB,MAAKA,iBAAL,CAAuBC,IAAvB,OAAzB;AACA,UAAKC,kBAAL,GAA0B,MAAKA,kBAAL,CAAwBD,IAAxB,OAA1B;AACA,UAAKE,aAAL,GAAqB,MAAKA,aAAL,CAAmBF,IAAnB,OAArB;AATiB;AAUlB;;AAED;;;;;;;wCAGoB;AAClB,WAAKG,QAAL,CAAc,EAAEN,WAAW,CAAC,KAAKD,KAAL,CAAWC,SAAzB,EAAd;AACD;;AAED;;;;;;;uCAImBO,S,EAAW;AAC5B;AAD4B,UAEpBN,IAFoB,GAEX,KAAKF,KAFM,CAEpBE,IAFoB;;AAG5B,WAAKH,KAAL,CAAWU,GAAX,CAAeC,SAAf,CAAyB,EAAEF,oBAAF,EAAaN,UAAb,EAAzB;AACA,WAAKK,QAAL,CAAc,EAAEL,MAAMA,OAAO,CAAf,EAAd;AACD;;AAED;;;;;;;;;kCAMcS,O,EAASC,U,EAAYC,a,EAAe;AAAA;;AAAA,UACxCL,SADwC,GAC1B,KAAKT,KADqB,CACxCS,SADwC;AAAA,UAExCP,SAFwC,GAE1B,KAAKD,KAFqB,CAExCC,SAFwC;;AAGhD,UAAIA,aAAaU,OAAb,IAAwBA,QAAQG,MAApC,EAA4C;AAC1C,YAAMC,MAA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AWuB,QAAQJ,EAJrB;AAKE,kBAAO,OALT,CAKiB;AALjB,UADF;AAQG,aAAKd,aAAL,CACCkB,QAAQb,OADT,EAECa,QAAQC,WAFT,EAGCD,QAAQX,aAHT;AARH,OADF;AAgBD;;;;EA5GsBa,gB;;AA+GzB5B,WAAW6B,SAAX,GAAuB;AACrBnB,aAAWoB,oBAAUC,MAAV,CAAiBC;AADP,CAAvB;;AAIAhC,WAAWiC,YAAX,GAA0B,EAA1B;;kBAEe,uBAAQjC,UAAR,C","file":"index.js","sourcesContent":["import React, { Component } from \"react\";\r\nimport PropTypes from \"prop-types\";\r\nimport { Icon } from \"antd\";\r\nimport intl from \"react-intl-universal\";\r\nimport Comment from \"../../Comment\";\r\nimport ContentItem from \"./../ContentItem\";\r\nimport \"./index.css\";\r\n\r\nclass CommentBox extends Component {\r\n constructor(props) {\r\n super(props);\r\n this.state = {\r\n showReply: true,\r\n page: 1\r\n };\r\n\r\n this.handleToggleReply = this.handleToggleReply.bind(this);\r\n this.handleGetMoreReply = this.handleGetMoreReply.bind(this);\r\n this.renderReplies = this.renderReplies.bind(this);\r\n }\r\n\r\n /**\r\n * 切换是否显示回复列表\r\n */\r\n handleToggleReply() {\r\n this.setState({ showReply: !this.state.showReply });\r\n }\r\n\r\n /**\r\n * 获取更多评论\r\n * @param {string} commentId comment id\r\n */\r\n handleGetMoreReply(commentId) {\r\n // 从第一页开始获取评论\r\n const { page } = this.state;\r\n this.props.app.sGetReply({ commentId, page });\r\n this.setState({ page: page + 1 });\r\n }\r\n\r\n /**\r\n * 渲染回复 DOM\r\n * @param {array} replies 回复列表\r\n * @param {number} replies 回复的数量\r\n * @param {boolean} isNoMoreReply 是否没有更多回复\r\n */\r\n renderReplies(replies, replyCount, isNoMoreReply) {\r\n const { commentId } = this.props;\r\n const { showReply } = this.state;\r\n if (showReply && replies && replies.length) {\r\n const len = replies.length;\r\n return (\r\n <div style={{ marginLeft: 50 }}>\r\n {replies.map((item, index) => {\r\n if (index === len - 1) {\r\n return [\r\n <ContentItem\r\n commentId={commentId}\r\n replyId={item.id}\r\n key={item.id}\r\n content={item}\r\n action=\"replyToReply\" // 回复的回复\r\n />,\r\n <div className=\"comment-more-box\" key=\"show_more_button\">\r\n {!isNoMoreReply && replyCount !== len && (\r\n <span\r\n className=\"comment-show-more\"\r\n onClick={() => this.handleGetMoreReply(commentId)}\r\n >\r\n {intl.get(\"reply.moreReply\")}\r\n </span>\r\n )}\r\n\r\n <a\r\n style={{ float: \"right\" }}\r\n onClick={this.handleToggleReply}\r\n >\r\n <Icon type=\"up\" /> {intl.get(\"reply.collapse\")}\r\n </a>\r\n </div>\r\n ];\r\n }\r\n return (\r\n <ContentItem\r\n commentId={commentId}\r\n replyId={item.id}\r\n key={item.id}\r\n content={item}\r\n action=\"replyToReply\" // 评论的回复\r\n />\r\n );\r\n })}\r\n </div>\r\n );\r\n }\r\n return null;\r\n }\r\n\r\n render() {\r\n const { content } = this.props;\r\n const { showReply } = this.state;\r\n return (\r\n <div>\r\n <ContentItem\r\n content={content}\r\n onShowReply={this.handleToggleReply}\r\n showReply={showReply}\r\n commentId={content.id}\r\n action=\"reply\" // 评论的回复\r\n />\r\n {this.renderReplies(\r\n content.replies,\r\n content.reply_count,\r\n content.isNoMoreReply\r\n )}\r\n </div>\r\n );\r\n }\r\n}\r\n\r\nCommentBox.propTypes = {\r\n commentId: PropTypes.string.isRequired\r\n};\r\n\r\nCommentBox.defaultProps = {};\r\n\r\nexport default Comment(CommentBox);\r\n"]}