通用评论

index.js.map 14KB

1
  1. {"version":3,"sources":["../../../src/components/ContentItem/index.js"],"names":["dayjs","locale","extend","relativeTime","CommentItem","props","state","showInput","showPreviewer","previewerIndex","handleToggleInput","bind","renderTextWithReply","hidePreviewer","index","setState","text","content","newText","reply","user_name","commentId","replyId","action","showReply","onShowReply","app","newContent","images","indexOf","IMAGE_SPLIT","split","pop","join","imageList","needClear","length","imgs","splice","type","user_avatar","avatar","marginLeft","created","format","fromNow","__html","map","item","i","backgroundImage","reply_count","userId","user_id","sDeleteReply","id","sDeleteComment","sReplyFavor","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;;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,KADA;AAEXC,qBAAe,KAFJ;AAGXC,sBAAgB;AAHL,KAAb;AAKA,UAAKC,iBAAL,GAAyB,MAAKA,iBAAL,CAAuBC,IAAvB,OAAzB;AACA,UAAKC,mBAAL,GAA2B,MAAKA,mBAAL,CAAyBD,IAAzB,OAA3B;AACA,UAAKH,aAAL,GAAqB,MAAKA,aAAL,CAAmBG,IAAnB,OAArB;AACA,UAAKE,aAAL,GAAqB,MAAKA,aAAL,CAAmBF,IAAnB,OAArB;AAViB;AAWlB;;;;kCAEaG,K,EAAO;AACnB,WAAKC,QAAL,CAAc;AACZP,uBAAe,IADH;AAEZC,wBAAgBK;AAFJ,OAAd;AAID;;;oCAEe;AACd,WAAKC,QAAL,CAAc;AACZP,uBAAe;AADH,OAAd;AAGD;;;wCAEm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port { Avatar, Icon, Tooltip, Popconfirm } 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\";\nimport ImagePreviewer from \"../ImagePreviewer/ImagePreviewer\";\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 showPreviewer: false,\n previewerIndex: 0\n };\n this.handleToggleInput = this.handleToggleInput.bind(this);\n this.renderTextWithReply = this.renderTextWithReply.bind(this);\n this.showPreviewer = this.showPreviewer.bind(this);\n this.hidePreviewer = this.hidePreviewer.bind(this);\n }\n\n showPreviewer(index) {\n this.setState({\n showPreviewer: true,\n previewerIndex: index\n });\n }\n\n hidePreviewer() {\n this.setState({\n showPreviewer: false\n });\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 const imageList = images.split(\",\");\n\n // 在3, 7前需要换行\n const needClear =\n imageList.length === 5 ||\n imageList.length === 6 ||\n imageList.length === 9;\n const imgs = [...imageList];\n if (needClear) {\n if (imgs.length > 6) {\n imgs.splice(3, 0, { type: \"divider\" });\n imgs.splice(7, 0, { type: \"divider\" });\n } else {\n imgs.splice(3, 0, { type: \"divider\" });\n }\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>{content.user_name || \"游客\"}</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 {// image为空时不渲染comment-item-image\n imageList.length > 0 &&\n imageList[0] !== \"\" && (\n <div className=\"comment-item-image\">\n {!this.state.showPreviewer &&\n imgs.map((item, index) => {\n if (item.type === \"divider\") {\n return (\n <div className=\"comment-item-image-wrapper\" key={index}>\n <div className=\"comment-img-divider\" />\n {/* <img src={item} alt={item} className=\"comment-img\" /> */}\n </div>\n );\n }\n return (\n <div\n className=\"comment-item-image-wrapper\"\n key={index}\n onClick={() => {\n let i = index;\n if (needClear) {\n if (index > 3) {\n i -= 1;\n }\n if (index > 7) {\n i -= 1;\n }\n }\n this.showPreviewer(i);\n }}\n >\n <div\n style={{ backgroundImage: `url(${item})` }}\n className=\"comment-img-thumbnail\"\n />\n {/* <img src={item} alt={item} className=\"comment-img\" /> */}\n </div>\n );\n })}\n {this.state.showPreviewer && (\n <ImagePreviewer\n list={imageList}\n index={this.state.previewerIndex}\n onFold={this.hidePreviewer}\n />\n )}\n <div className=\"clearfix\" />\n </div>\n )}\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 {app.userId === content.user_id && (\n <Popconfirm\n title=\"确定要删除吗?\"\n onConfirm={() => {\n if (replyId) {\n app.sDeleteReply(content.id, commentId);\n return;\n }\n app.sDeleteComment(content.id);\n }}\n okText=\"确定\"\n cancelText=\"取消\"\n >\n <a className=\"comment-item-bottom-right\">&nbsp; 删除</a>\n </Popconfirm>\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"]}