通用评论

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","user_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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Ee,KAAKD,KAFpB,CAECC,SAFD;;AAGP,aACE;AAAA;AAAA;AACE,sCAAC,qBAAD;AACE,mBAASwB,OADX;AAEE,uBAAa,KAAKtB,iBAFpB;AAGE,qBAAWF,SAHb;AAIE,qBAAWwB,QAAQL,EAJrB;AAKE,mBAASC,OALX;AAME,kBAAO,OANT,CAMiB;AANjB,YAOE,MAAM,KAAKrB,KAAL,CAAWE;AAPnB,UADF;AAUG,aAAKI,aAAL,CACCmB,QAAQd,OADT,EAECc,QAAQC,WAFT,EAGCD,QAAQZ,aAHT;AAVH,OADF;AAkBD;;;;EAjHsBc,gB;;AAoHzB7B,WAAW8B,SAAX,GAAuB;AACrBpB,aAAWqB,oBAAUC,MAAV,CAAiBC;AADP,CAAvB;;AAIAjC,WAAWkC,YAAX,GAA0B,EAA1B;;kBAEe,uBAAQlC,UAAR,C","file":"index.js","sourcesContent":["import React, { Component } from \"react\";\nimport PropTypes from \"prop-types\";\nimport { Icon } from \"antd\";\nimport intl from \"react-intl-universal\";\nimport Comment from \"../../Comment\";\nimport ContentItem from \"./../ContentItem\";\nimport \"./index.css\";\n\nclass CommentBox extends Component {\n constructor(props) {\n super(props);\n this.state = {\n showReply: true,\n page: 1\n };\n\n this.handleToggleReply = this.handleToggleReply.bind(this);\n this.handleGetMoreReply = this.handleGetMoreReply.bind(this);\n this.renderReplies = this.renderReplies.bind(this);\n }\n\n /**\n * 切换是否显示回复列表\n */\n handleToggleReply() {\n this.setState({ showReply: !this.state.showReply });\n }\n\n /**\n * 获取更多评论\n * @param {string} commentId comment id\n */\n handleGetMoreReply(commentId) {\n // 从第一页开始获取评论\n const { page } = this.state;\n this.props.app.sGetReply({ commentId, page });\n this.setState({ page: page + 1 });\n }\n\n /**\n * 渲染回复 DOM\n * @param {array} replies 回复列表\n * @param {number} replies 回复的数量\n * @param {boolean} isNoMoreReply 是否没有更多回复\n */\n renderReplies(replies, replyCount, isNoMoreReply) {\n const { commentId } = this.props;\n const { showReply } = this.state;\n if (showReply && replies && replies.length) {\n const len = replies.length;\n return (\n <div style={{ marginLeft: 50 }}>\n {replies.map((item, index) => {\n if (index === len - 1) {\n return [\n <ContentItem\n commentId={commentId}\n replyId={item.id}\n key={item.id}\n content={item}\n user_id={item.user_id}\n action=\"replyToReply\" // 回复的回复\n page={this.state.page}\n />,\n <div className=\"comment-more-box\" key=\"show_more_button\">\n {!isNoMoreReply && replyCount !== len && (\n <span\n className=\"comment-show-more\"\n onClick={() => this.handleGetMoreReply(commentId)}\n >\n {intl.get(\"reply.moreReply\")}\n </span>\n )}\n\n <a\n style={{ float: \"right\" }}\n onClick={this.handleToggleReply}\n >\n <Icon type=\"up\" /> {intl.get(\"reply.collapse\")}\n </a>\n </div>\n ];\n }\n return (\n <ContentItem\n commentId={commentId}\n replyId={item.id}\n key={item.id}\n content={item}\n action=\"replyToReply\" // 评论的回复\n page={this.state.page}\n />\n );\n })}\n </div>\n );\n }\n return null;\n }\n\n render() {\n const { content, user_id } = this.props;\n const { showReply } = this.state;\n return (\n <div>\n <ContentItem\n content={content}\n onShowReply={this.handleToggleReply}\n showReply={showReply}\n commentId={content.id}\n user_id={user_id}\n action=\"reply\" // 评论的回复\n page={this.state.page}\n />\n {this.renderReplies(\n content.replies,\n content.reply_count,\n content.isNoMoreReply\n )}\n </div>\n );\n }\n}\n\nCommentBox.propTypes = {\n commentId: PropTypes.string.isRequired\n};\n\nCommentBox.defaultProps = {};\n\nexport default Comment(CommentBox);\n"]}