通用评论

index.js.map 9.2KB

1
  1. {"version":3,"sources":["../../../src/components/ContentItem/index.js"],"names":["dayjs","locale","extend","relativeTime","CommentItem","props","state","showInput","handleToggleInput","bind","renderTextWithReply","setState","text","content","newText","reply","user_name","commentId","replyId","action","showReply","onShowReply","app","newContent","images","indexOf","IMAGE_SPLIT","split","pop","join","user_avatar","avatar","marginLeft","created","format","fromNow","__html","map","item","index","maxWidth","reply_count","sReplyFavor","id","favored","sCommentFavor","favor_count","children","Component","propTypes","PropTypes","object","isRequired","oneOf","func","defaultProps"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;AACA;;;;AAEA;;;;AACA;;AACA;;;;AACA;;;;AACA;;;;AACA;;;;AACA;;AACA;;AACA;;;;;;;;;;AAEAA,gBAAMC,MAAN,CAAa,OAAb;AACAD,gBAAME,MAAN,CAAaC,sBAAb;;IAEMC,W;;;AACJ,uBAAYC,KAAZ,EAAmB;AAAA;;AAAA,0HACXA,KADW;;AAEjB,UAAKC,KAAL,GAAa;AACXC,iBAAW;AADA,KAAb;AAGA,UAAKC,iBAAL,GAAyB,MAAKA,iBAAL,CAAuBC,IAAvB,OAAzB;AACA,UAAKC,mBAAL,GAA2B,MAAKA,mBAAL,CAAyBD,IAAzB,OAA3B;AANiB;AAOlB;;;;wCAEmB;AAClB,WAAKE,QAAL,CAAc,EAAEJ,WAAW,CAAC,KAAKD,KAAL,CAAWC,SAAzB,EAAd;AACD;;;wCAEmBK,I,EAAMC,O,EAAS;AACjC,UAAIC,UAAUF,IAAd;AADiC,UAEzBG,KAFyB,GAEfF,OAFe,CAEzBE,KAFyB;;AAGjC,UAAIA,KAAJ,EAAW;AACT;AACA;AACA;AACAD,kBAAaA,OAAb,YAA2BC,MAAMC,SAAjC,SAA8CD,MAAMF,OAApD;AACA;AACA;AACA;AACA;AACA;AACA;AACA,YAAIE,MAAMA,KAAV,EAAiB;AACf,iBAAO,KAAKL,mBAAL,CAAyBI,OAAzB,EAAkCC,KAAlC,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D;;;;EAvJuBwC,gB;;AA0J1B5C,YAAY6C,SAAZ,GAAwB;AACtBpC,WAASqC,oBAAUC,MAAV,CAAiBC,UADJ;AAEtB;AACA;AACA;AACAjC,UAAQ+B,oBAAUG,KAAV,CAAgB,CAAC,SAAD,EAAY,OAAZ,EAAqB,cAArB,CAAhB,CALc;AAMtBhC,eAAa6B,oBAAUI;AAND,CAAxB;;AASAlD,YAAYmD,YAAZ,GAA2B;AACzBpC,UAAQ,SADiB;AAEzBE,eAAa,uBAAM,CAAE;AAFI,CAA3B;;kBAKe,uBAAQjB,WAAR,C","file":"index.js","sourcesContent":["import React, { Component } from \"react\";\nimport PropTypes from \"prop-types\";\nimport { Avatar, Icon, Tooltip } from \"antd\";\nimport dayjs from \"dayjs\";\nimport \"dayjs/locale/zh-cn\";\nimport relativeTime from \"dayjs/plugin/relativeTime\";\nimport Comment from \"../../Comment\";\nimport CommentInput from \"../CommentInput\";\nimport avatar from \"../../avatar\";\nimport { renderContent } from \"../../helper\";\nimport { IMAGE_SPLIT } from \"../../constant\";\nimport \"./index.css\";\n\ndayjs.locale(\"zh-cn\");\ndayjs.extend(relativeTime);\n\nclass CommentItem extends Component {\n constructor(props) {\n super(props);\n this.state = {\n showInput: false\n };\n this.handleToggleInput = this.handleToggleInput.bind(this);\n this.renderTextWithReply = this.renderTextWithReply.bind(this);\n }\n\n handleToggleInput() {\n this.setState({ showInput: !this.state.showInput });\n }\n\n renderTextWithReply(text, content) {\n let newText = text;\n const { reply } = content;\n if (reply) {\n // newText = `${newText} //@<a href=\"/${reply.user_id}\">${\n // reply.user_name\n // }</a> ${reply.content}`;\n newText = `${newText} //@${reply.user_name} ${reply.content}`;\n // newText = (\n // <span>\n // {newText}\n // @<a href={`/${reply.user_id}`}>{reply.user_name}</a>{reply.content}\n // </span>\n // )\n if (reply.reply) {\n return this.renderTextWithReply(newText, reply);\n }\n }\n return newText;\n }\n\n render() {\n const {\n commentId,\n replyId,\n content,\n action,\n showReply,\n onShowReply,\n app\n } = this.props;\n\n const { showInput } = this.state;\n\n let newContent = content.content;\n let images = \"\";\n if (newContent.indexOf(IMAGE_SPLIT) !== -1) {\n newContent = newContent.split(IMAGE_SPLIT);\n images = newContent.pop();\n newContent = newContent.join(\"\");\n }\n\n return (\n <div className=\"comment-item-box\">\n <div className=\"comment-item-left\">\n <Avatar src={content.user_avatar || avatar} size=\"large\" />\n </div>\n <div className=\"comment-item-right\">\n <div>\n {/* <a href={`/${content.user_id}`}>\n {content.user_name || \"暂无昵称\"}\n </a> */}\n <strong>\n {content.user_name || \"暂无昵称\"}\n </strong>\n <span style={{ marginLeft: 10 }}>\n <Tooltip\n placement=\"top\"\n title={dayjs(content.created * 1000).format(\n \"YYYY-MM-DD HH:mm:ss\"\n )}\n >\n {dayjs(content.created * 1000).fromNow()}\n </Tooltip>\n </span>\n </div>\n <div\n className=\"comment-item-content\"\n dangerouslySetInnerHTML={{\n __html: renderContent(\n this.renderTextWithReply(newContent, content)\n )\n }}\n />\n <div className=\"comment-item-image\">\n {images.split(\",\").map((item, index) => {\n return (\n <img\n key={index}\n src={item}\n alt={item}\n style={{ maxWidth: \"100%\" }}\n />\n );\n })}\n </div>\n <div className=\"comment-item-bottom\">\n {content.reply_count ? (\n <div>\n <a className=\"comment-item-bottom-left\" onClick={onShowReply}>\n {content.reply_count} 条回复\n {showReply ? <Icon type=\"up\" /> : <Icon type=\"down\" />}\n </a>\n </div>\n ) : null}\n\n <a\n onClick={this.handleToggleInput}\n className=\"comment-item-bottom-right\"\n >\n &nbsp; 回复\n </a>\n <div\n className=\"comment-item-bottom-right\"\n onClick={() => {\n if (replyId) {\n // 如果有 replyId,则说明是评论的回复\n app.sReplyFavor(content.id, commentId, content.favored);\n return;\n }\n app.sCommentFavor(content.id, content.favored);\n }}\n >\n <Icon\n type=\"like-o\"\n className={\n content.favored\n ? \"comment-favor comment-favored\"\n : \"comment-favor\"\n }\n />\n &nbsp;{content.favor_count}\n </div>\n </div>\n </div>\n\n {showInput && (\n <CommentInput\n content={app.children}\n action={action}\n replyId={replyId}\n commentId={commentId}\n callback={this.handleToggleInput}\n />\n )}\n </div>\n );\n }\n}\n\nCommentItem.propTypes = {\n content: PropTypes.object.isRequired,\n // comment 评论\n // reply 评论的回复\n // replyToReply 回复的回复\n action: PropTypes.oneOf([\"comment\", \"reply\", \"replyToReply\"]),\n onShowReply: PropTypes.func\n};\n\nCommentItem.defaultProps = {\n action: \"comment\",\n onShowReply: () => {}\n};\n\nexport default Comment(CommentItem);\n"]}