通用评论

1
  1. {"version":3,"sources":["../../../src/components/ContentItem/index.js"],"names":["dayjs","extend","relativeTime","LOCALES","CommentItem","props","state","showInput","showPreviewer","previewerIndex","handleToggleInput","bind","renderTextWithReply","hidePreviewer","index","setState","text","content","newText","reply","user_name","commentId","replyId","action","showReply","onShowReply","app","locale","newContent","images","indexOf","IMAGE_SPLIT","split","pop","join","imageList","needClear","length","imgs","splice","type","user_avatar","avatar","intl","get","marginLeft","created","format","fromNow","__html","map","item","i","backgroundImage","reply_count","total","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;;AAEA;;;;AACA;;;;AACA;;;;AACA;;;;AACA;;;;AACA;;AACA;;AACA;;AACA;;;;;;;;;;;;;AATA;;;AAWA;AACAA,gBAAMC,MAAN,CAAaC,sBAAb;;AAEA,IAAMC,UAAU;AACd,WAAS;AADK,CAAhB;;IAIMC,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;AAC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ASD,OAHX;AAIE,qBAAWD,SAJb;AAKE,kBAAQJ,QAAQwC,OALlB;AAME,oBAAU,KAAK/C;AANjB;AA7IJ,OADF;AAyJD;;;;EApPuBwD,gB;;AAuP1B9D,YAAY+D,SAAZ,GAAwB;AACtBlD,WAASmD,oBAAUC,MAAV,CAAiBC,UADJ;AAEtB;AACA;AACA;AACA/C,UAAQ6C,oBAAUG,KAAV,CAAgB,CAAC,SAAD,EAAY,OAAZ,EAAqB,cAArB,CAAhB,CALc;AAMtB9C,eAAa2C,oBAAUI;AAND,CAAxB;;AASApE,YAAYqE,YAAZ,GAA2B;AACzBlD,UAAQ,SADiB;AAEzBE,eAAa,uBAAM,CAAE;AAFI,CAA3B;;kBAKe,uBAAQrB,WAAR,C","file":"index.js","sourcesContent":["import React, { Component } from \"react\";\r\nimport PropTypes from \"prop-types\";\r\nimport { Avatar, Icon, Tooltip, Popconfirm } from \"antd\";\r\nimport dayjs from \"dayjs\";\r\nimport \"dayjs/locale/zh-cn\";\r\n// import 'dayjs/locale/es';\r\nimport relativeTime from \"dayjs/plugin/relativeTime\";\r\nimport intl from \"react-intl-universal\";\r\nimport Comment from \"../../Comment\";\r\nimport CommentInput from \"../CommentInput\";\r\nimport avatar from \"../../avatar\";\r\nimport { renderContent } from \"../../helper\";\r\nimport { IMAGE_SPLIT } from \"../../constant\";\r\nimport \"./index.css\";\r\nimport ImagePreviewer from \"../ImagePreviewer/ImagePreviewer\";\r\n\r\n// dayjs.locale(\"zh-cn\");\r\ndayjs.extend(relativeTime);\r\n\r\nconst LOCALES = {\r\n \"zh-CN\": \"zh-cn\"\r\n};\r\n\r\nclass CommentItem extends Component {\r\n constructor(props) {\r\n super(props);\r\n this.state = {\r\n showInput: false,\r\n showPreviewer: false,\r\n previewerIndex: 0\r\n };\r\n this.handleToggleInput = this.handleToggleInput.bind(this);\r\n this.renderTextWithReply = this.renderTextWithReply.bind(this);\r\n this.showPreviewer = this.showPreviewer.bind(this);\r\n this.hidePreviewer = this.hidePreviewer.bind(this);\r\n }\r\n\r\n showPreviewer(index) {\r\n this.setState({\r\n showPreviewer: true,\r\n previewerIndex: index\r\n });\r\n }\r\n\r\n hidePreviewer() {\r\n this.setState({\r\n showPreviewer: false\r\n });\r\n }\r\n\r\n handleToggleInput() {\r\n this.setState({ showInput: !this.state.showInput });\r\n }\r\n\r\n renderTextWithReply(text, content) {\r\n let newText = text;\r\n const { reply } = content;\r\n if (reply) {\r\n // newText = `${newText} //@<a href=\"/${reply.user_id}\">${\r\n // reply.user_name\r\n // }</a> ${reply.content}`;\r\n newText = `${newText} //@${reply.user_name} ${reply.content}`;\r\n // newText = (\r\n // <span>\r\n // {newText}\r\n // @<a href={`/${reply.user_id}`}>{reply.user_name}</a>{reply.content}\r\n // </span>\r\n // )\r\n if (reply.reply) {\r\n return this.renderTextWithReply(newText, reply);\r\n }\r\n }\r\n return newText;\r\n }\r\n\r\n render() {\r\n const {\r\n commentId,\r\n replyId,\r\n content,\r\n action,\r\n showReply,\r\n onShowReply,\r\n app\r\n } = this.props;\r\n\r\n const { locale } = this.props.app;\r\n const { showInput } = this.state;\r\n\r\n let newContent = content.content;\r\n let images = \"\";\r\n if (newContent.indexOf(IMAGE_SPLIT) !== -1) {\r\n newContent = newContent.split(IMAGE_SPLIT);\r\n images = newContent.pop();\r\n newContent = newContent.join(\"\");\r\n }\r\n\r\n const imageList = images.split(\",\");\r\n\r\n // 在3, 7前需要换行\r\n const needClear =\r\n imageList.length === 5 ||\r\n imageList.length === 6 ||\r\n imageList.length === 9;\r\n const imgs = [...imageList];\r\n if (needClear) {\r\n if (imgs.length > 6) {\r\n imgs.splice(3, 0, { type: \"divider\" });\r\n imgs.splice(7, 0, { type: \"divider\" });\r\n } else {\r\n imgs.splice(3, 0, { type: \"divider\" });\r\n }\r\n }\r\n\r\n return (\r\n <div className=\"comment-item-box\">\r\n <div className=\"comment-item-left\">\r\n <Avatar src={content.user_avatar || avatar} size=\"large\" />\r\n </div>\r\n <div className=\"comment-item-right\">\r\n <div>\r\n {/* <a href={`/${content.user_id}`}>\r\n {content.user_name || \"暂无昵称\"}\r\n </a> */}\r\n <strong>{content.user_name || intl.get(\"comment.tourist\")}</strong>\r\n <span style={{ marginLeft: 10 }}>\r\n <Tooltip\r\n placement=\"top\"\r\n title={dayjs(content.created * 1000).format(\r\n \"YYYY-MM-DD HH:mm:ss\"\r\n )}\r\n >\r\n {LOCALES[locale]\r\n ? dayjs(content.created * 1000)\r\n .locale(LOCALES[locale])\r\n .fromNow()\r\n : dayjs(content.created * 1000).fromNow()}\r\n </Tooltip>\r\n </span>\r\n </div>\r\n <div\r\n className=\"comment-item-content\"\r\n dangerouslySetInnerHTML={{\r\n __html: renderContent(\r\n this.renderTextWithReply(newContent, content)\r\n )\r\n }}\r\n />\r\n {// image为空时不渲染comment-item-image\r\n imageList.length > 0 && imageList[0] !== \"\" && (\r\n <div className=\"comment-item-image\">\r\n {!this.state.showPreviewer &&\r\n imgs.map((item, index) => {\r\n if (item.type === \"divider\") {\r\n return (\r\n <div className=\"comment-item-image-wrapper\" key={index}>\r\n <div className=\"comment-img-divider\" />\r\n {/* <img src={item} alt={item} className=\"comment-img\" /> */}\r\n </div>\r\n );\r\n }\r\n return (\r\n <div\r\n className=\"comment-item-image-wrapper\"\r\n key={index}\r\n onClick={() => {\r\n let i = index;\r\n if (needClear) {\r\n if (index > 3) {\r\n i -= 1;\r\n }\r\n if (index > 7) {\r\n i -= 1;\r\n }\r\n }\r\n this.showPreviewer(i);\r\n }}\r\n >\r\n <div\r\n style={{ backgroundImage: `url(${item})` }}\r\n className=\"comment-img-thumbnail\"\r\n />\r\n {/* <img src={item} alt={item} className=\"comment-img\" /> */}\r\n </div>\r\n );\r\n })}\r\n {this.state.showPreviewer && (\r\n <ImagePreviewer\r\n list={imageList}\r\n index={this.state.previewerIndex}\r\n onFold={this.hidePreviewer}\r\n />\r\n )}\r\n <div className=\"clearfix\" />\r\n </div>\r\n )}\r\n <div className=\"comment-item-bottom\">\r\n {content.reply_count ? (\r\n <div>\r\n <a className=\"comment-item-bottom-left\" onClick={onShowReply}>\r\n {/* {content.reply_count} 条回复 */}\r\n {intl.get(\"reply.totalReply\", { total: content.reply_count })}\r\n {showReply ? <Icon type=\"up\" /> : <Icon type=\"down\" />}\r\n </a>\r\n </div>\r\n ) : null}\r\n {app.userId === content.user_id && (\r\n <Popconfirm\r\n // title=\"确定要删除吗?\"\r\n title={intl.get(\"popConfirm.title\")}\r\n onConfirm={() => {\r\n if (replyId) {\r\n app.sDeleteReply(content.id, commentId);\r\n return;\r\n }\r\n app.sDeleteComment(content.id);\r\n }}\r\n okText={intl.get(\"popConfirm.ok\")}\r\n cancelText={intl.get(\"popConfirm.cancel\")}\r\n >\r\n <a className=\"comment-item-bottom-right\">\r\n &nbsp; {intl.get(\"popConfirm.delete\")}\r\n </a>\r\n </Popconfirm>\r\n )}\r\n <a\r\n onClick={this.handleToggleInput}\r\n className=\"comment-item-bottom-right\"\r\n >\r\n &nbsp; {intl.get(\"comment.reply\")}\r\n </a>\r\n <div\r\n className=\"comment-item-bottom-right\"\r\n onClick={() => {\r\n if (replyId) {\r\n // 如果有 replyId,则说明是评论的回复\r\n app.sReplyFavor(content.id, commentId, content.favored);\r\n return;\r\n }\r\n app.sCommentFavor(content.id, content.favored);\r\n }}\r\n >\r\n <Icon\r\n type=\"like-o\"\r\n className={\r\n content.favored\r\n ? \"comment-favor comment-favored\"\r\n : \"comment-favor\"\r\n }\r\n />\r\n &nbsp;{content.favor_count}\r\n </div>\r\n </div>\r\n </div>\r\n\r\n {showInput && (\r\n <CommentInput\r\n content={app.children}\r\n action={action}\r\n replyId={replyId}\r\n commentId={commentId}\r\n userId={content.user_id}\r\n callback={this.handleToggleInput}\r\n />\r\n )}\r\n </div>\r\n );\r\n }\r\n}\r\n\r\nCommentItem.propTypes = {\r\n content: PropTypes.object.isRequired,\r\n // comment 评论\r\n // reply 评论的回复\r\n // replyToReply 回复的回复\r\n action: PropTypes.oneOf([\"comment\", \"reply\", \"replyToReply\"]),\r\n onShowReply: PropTypes.func\r\n};\r\n\r\nCommentItem.defaultProps = {\r\n action: \"comment\",\r\n onShowReply: () => {}\r\n};\r\n\r\nexport default Comment(CommentItem);\r\n"]}