通用评论

1
  1. {"version":3,"sources":["../src/App.js"],"names":["App","props","state","loading","oss","list","page","total","isNoMoreComment","handleChangeLoading","bind","sGetComment","sGetReply","sCreateComment","sCreateReply","sCommentFavor","sReplyFavor","sOssSts","axios","defaults","withCredentials","token","headers","common","key","value","setState","API","type","businessId","get","LIMIT","then","response","data","newList","oldList","filter","o","isTemporary","concat","info","catch","error","msg","lang","ERROR_DEFAULT","message","finally","commentId","map","item","id","replies","reply_count","reply_page","isNoMoreReply","content","cb","method","business_id","success","unshift","comment_id","push","favored","favor_count","replyId","r","showHeader","marginBottom","showEditor","children","showList","marginTop","Component","propTypes","PropTypes","number","isRequired","string","bool","defaultProps","Editor"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;AACA;;;;AAEA;;;;AACA;;AACA;;AACA;;AACA;;;;AACA;;;;AACA;;;;AACA;;;;AACA;;;;;;;;;;IAEMA,G;;;AACJ,eAAYC,KAAZ,EAAmB;AAAA;;AAAA,0GACXA,KADW;;AAEjB,UAAKC,KAAL,GAAa;AACXC,eAAS,EADE;;AAGX;AACAC,WAAK,EAJM;;AAMX;AACAC,YAAM,EAPK;AAQXC,YAAM,CARK;AASXC,aAAO,CATI;AAUX;AACAC,uBAAiB;AAXN,KAAb;AAaA,UAAKC,mBAAL,GAA2B,MAAKA,mBAAL,CAAyBC,IAAzB,OAA3B;AACA,UAAKC,WAAL,GAAmB,MAAKA,WAAL,CAAiBD,IAAjB,OAAnB;AACA,UAAKE,SAAL,GAAiB,MAAKA,SAAL,CAAeF,IAAf,OAAjB;AACA,UAAKG,cAAL,GAAsB,MAAKA,cAAL,CAAoBH,IAApB,OAAtB;AACA,UAAKI,YAAL,GAAoB,MAAKA,YAAL,CAAkBJ,IAAlB,OAApB;AACA,UAAKK,aAAL,GAAqB,MAAKA,aAAL,CAAmBL,IAAnB,OAArB;AACA,UAAKM,WAAL,GAAmB,MAAKA,WAAL,CAAiBN,IAAjB,OAAnB;AACA,UAAKO,OAAL,GAAe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KAAhC;AACE;AAAA;AAAA,YAAK,WAAU,SAAf;AACG,eAAKxB,KAAL,CAAWoE,UAAX,IACC;AAAA;AAAA,cAAK,OAAO,EAAEC,cAAc,EAAhB,EAAZ;AACE;AAAA;AAAA,gBAAK,WAAU,oBAAf;AAAA;AAAA,aADF;AAEE;AAAA;AAAA,gBAAM,WAAU,oBAAhB;AAAA;AAAA,aAFF;AAGE;AAAA;AAAA,gBAAM,WAAU,qBAAhB;AAAA;AAAA;AAHF,WAFJ;AAUG,eAAKrE,KAAL,CAAWsE,UAAX,IACC,8BAAC,sBAAD,IAAc,SAAS,KAAKtE,KAAL,CAAWuE,QAAlC,GAXJ;AAaG,eAAKvE,KAAL,CAAWwE,QAAX,IACC;AAAA;AAAA,cAAK,OAAO,EAAEC,WAAW,EAAb,EAAZ;AACE,0CAAC,qBAAD;AADF;AAdJ;AADF,OADF;AAuBD;;;;EApXeC,gB;;AAuXlB3E,IAAI4E,SAAJ,GAAgB;AACdhD,QAAMiD,oBAAUC,MAAV,CAAiBC,UADT,EACqB;AACnClD,cAAYgD,oBAAUG,MAAV,CAAiBD,UAFf,EAE2B;AACzCpD,OAAKkD,oBAAUG,MAHD,EAGS;AACvBP,YAAUI,oBAAUI,IAJN,EAIY;AAC1BV,cAAYM,oBAAUI,IALR,EAKc;AAC5BZ,cAAYQ,oBAAUI,IANR,CAMc;AANd,CAAhB;;AASAjF,IAAIkF,YAAJ,GAAmB;AACjBvD,OAAK,oCADY;AAEjB8C,YAAU,IAFO;AAGjBF,cAAY,IAHK;AAIjBF,cAAY;AAJK,CAAnB;;QAOSc,M,GAAAA,gB;kBAEMnF,G","file":"App.js","sourcesContent":["import React, { Component } from 'react';\nimport PropTypes from 'prop-types';\nimport { message, Tag } from 'antd';\nimport axios from 'axios';\nimport { ERROR_DEFAULT, LIMIT } from './constant';\nimport { CommentContext } from './Comment';\nimport { isFunction } from './helper';\nimport CommentInput from './components/CommentInput';\nimport CommentList from './components/CommentList';\nimport Editor from './components/Editor';\nimport lang from './lang';\nimport './App.css';\n\nclass App extends Component {\n constructor(props) {\n super(props);\n this.state = {\n loading: {},\n\n // oss 配置\n oss: {},\n\n // 评论数据\n list: [],\n page: 1,\n total: 0,\n // 是否没有更多评论了\n isNoMoreComment: false,\n };\n this.handleChangeLoading = this.handleChangeLoading.bind(this);\n this.sGetComment = this.sGetComment.bind(this);\n this.sGetReply = this.sGetReply.bind(this);\n this.sCreateComment = this.sCreateComment.bind(this);\n this.sCreateReply = this.sCreateReply.bind(this);\n this.sCommentFavor = this.sCommentFavor.bind(this);\n this.sReplyFavor = this.sReplyFavor.bind(this);\n this.sOssSts = this.sOssSts.bind(this);\n }\n\n componentWillMount() {\n this.axios = axios;\n this.axios.defaults.withCredentials = true;\n if (this.props.token) {\n this.axios.defaults.headers.common['Authorization'] = `Bearer ${\n this.props.token\n }`;\n }\n }\n\n componentDidMount() {}\n\n /**\n * 改变 loading 状态\n * @param {string} key key\n * @param {string} value value\n */\n handleChangeLoading(key, value) {\n const { loading } = this.state;\n loading[key] = value;\n this.setState({ loading });\n }\n\n /**\n * 获取评论列表\n */\n sGetComment({ page = 1 } = {}) {\n this.handleChangeLoading('sGetComment', true);\n const { API, type, businessId } = this.props;\n this.axios\n .get(\n `${API}/comments?type=${type}&business_id=${businessId}&page=${page}&limit=${LIMIT}`\n )\n .then(response => {\n const { list, page, total } = response.data;\n if (list) {\n let newList = list;\n if (page > 1) {\n let { list: oldList } = this.state;\n // 删除临时数据\n oldList = oldList.filter(o => !o.isTemporary);\n newList = oldList.concat(newList);\n }\n this.setState({\n list: newList,\n page,\n total,\n });\n } else {\n message.info('没有更多评论了');\n this.setState({\n isNoMoreComment: true,\n });\n }\n })\n .catch(error => {\n if (error.response && error.response.data && error.response.data.msg) {\n message.error(lang[error.response.data.msg] || ERROR_DEFAULT);\n return;\n }\n message.error(lang[error.message] || ERROR_DEFAULT);\n })\n .finally(() => {\n this.handleChangeLoading('sGetComment', false);\n });\n }\n\n /**\n * 获取更多回复\n */\n sGetReply({ commentId, page = 1 } = {}) {\n this.handleChangeLoading('sGetReply', true);\n const { API } = this.props;\n this.axios\n .get(`${API}/replies?comment_id=${commentId}&page=${page}&limit=${LIMIT}`)\n .then(response => {\n if (!response.data.list) {\n message.info('没有更多数据了!');\n }\n const list = this.state.list.map(item => {\n if (item.id === commentId) {\n if (!item.replies) item.replies = [];\n if (response.data.list) {\n if (page === 1) {\n // 如果当前页数为第一页,则清空当前所有的 replies\n // 并将获取到的 replies 存放在 state\n item.replies = response.data.list;\n } else {\n item.replies = item.replies\n .filter(o => !o.isTemporary)\n .concat(response.data.list);\n // 如果当前页数非第一页,则合并 replies\n }\n item.reply_count = response.data.total;\n item.reply_page = response.data.page;\n } else {\n item.isNoMoreReply = true;\n }\n }\n return item;\n });\n this.setState({ list });\n })\n .catch(error => {\n if (error.response && error.response.data && error.response.data.msg) {\n message.error(lang[error.response.data.msg] || ERROR_DEFAULT);\n return;\n }\n message.error(lang[error.message] || ERROR_DEFAULT);\n })\n .finally(() => {\n this.handleChangeLoading('sGetReply', false);\n });\n }\n\n /**\n * 添加评论\n * @param {object} {content} comment content\n */\n sCreateComment({ content } = {}, cb) {\n if (!content) return message.error('评论内容不能为空 ');\n this.handleChangeLoading('sCreateComment', true);\n const { API, type, businessId } = this.props;\n this.axios(`${API}/comments`, {\n method: 'post',\n data: {\n type,\n business_id: businessId,\n content,\n },\n withCredentials: true,\n })\n .then(response => {\n message.success('评论成功!');\n if (isFunction(cb)) cb();\n // 将数据写入到 list 中\n // 临时插入\n // 等到获取数据之后,删除临时数据\n const { list, total } = this.state;\n list.unshift({\n ...response.data,\n isTemporary: true, // 临时的数据\n });\n this.setState({ list, total: total + 1 });\n })\n .catch(error => {\n if (error.response && error.response.data && error.response.data.msg) {\n message.error(lang[error.response.data.msg] || ERROR_DEFAULT);\n return;\n }\n message.error(lang[error.message] || ERROR_DEFAULT);\n })\n .finally(() => {\n this.handleChangeLoading('sCreateComment', false);\n });\n }\n\n /**\n * 添加回复\n * 回复评论/回复回复\n * @param {object} data { comment_id, content, [reply_id] }\n */\n sCreateReply(data, cb) {\n if (!data.content) return message.error('回复内容不能为空 ');\n this.handleChangeLoading('sCreateReply', true);\n const { API } = this.props;\n this.axios(`${API}/replies`, {\n method: 'post',\n data,\n withCredentials: true,\n })\n .then(response => {\n message.success('回复成功!');\n if (isFunction(cb)) cb();\n // 将数据写入到 list 中\n // 临时插入\n // 等到获取数据之后,删除临时数据\n const list = this.state.list.map(item => {\n if (item.id === data.comment_id) {\n if (!item.replies) item.replies = [];\n item.replies.push({\n ...response.data,\n isTemporary: true, // 临时的数据\n });\n item.reply_count += 1;\n }\n return item;\n });\n this.setState({ list });\n })\n .catch(error => {\n if (error.response && error.response.data && error.response.data.msg) {\n message.error(lang[error.response.data.msg] || ERROR_DEFAULT);\n return;\n }\n message.error(lang[error.message] || ERROR_DEFAULT);\n })\n .finally(() => {\n this.handleChangeLoading('sCreateReply', false);\n });\n }\n\n /**\n * 评论 点赞/取消点赞\n * @param {string} commentId { commentId }\n * @param {boolean} favored 是否已经点过赞\n */\n sCommentFavor(commentId, favored) {\n this.handleChangeLoading('sCommentFavor', true);\n const { API } = this.props;\n this.axios(`${API}/comments/${commentId}/favor`, {\n method: favored ? 'delete' : 'put',\n withCredentials: true,\n })\n .then(response => {\n message.success(favored ? '取消点赞成功!' : '点赞成功!');\n // 更新 list 中的该项数据的 favored\n const list = this.state.list.map(item => {\n if (item.id === commentId) {\n item.favored = !favored;\n item.favor_count += favored ? -1 : 1;\n }\n return item;\n });\n this.setState({ list });\n })\n .catch(error => {\n if (error.response && error.response.data && error.response.data.msg) {\n message.error(lang[error.response.data.msg] || ERROR_DEFAULT);\n return;\n }\n message.error(lang[error.message] || ERROR_DEFAULT);\n })\n .finally(() => {\n this.handleChangeLoading('sCommentFavor', false);\n });\n }\n\n /**\n * 回复 点赞/取消点赞\n * @param {string} replyId replyId\n * @param {string} commentId commentId\n * @param {boolean} favored 是否已经点过赞\n */\n sReplyFavor(replyId, commentId, favored) {\n this.handleChangeLoading('sReplyFavor', true);\n const { API } = this.props;\n this.axios(`${API}/replies/${replyId}/favor`, {\n method: favored ? 'delete' : 'put',\n data: {\n comment_id: commentId,\n },\n withCredentials: true,\n })\n .then(response => {\n message.success(favored ? '取消点赞成功!' : '点赞成功!');\n // 更新 list 中的该项数据的 favored\n const list = this.state.list.map(item => {\n if (item.id === commentId) {\n item.replies = item.replies.map(r => {\n if (r.id === replyId) {\n r.favored = !favored;\n // r.favor_count = response.data.favor_count;\n // 点赞数 +1,而不是使用后端返回的点赞数\n // 不然如果返回的不是增加 1,用户可能以为程序错误\n r.favor_count += favored ? -1 : 1;\n }\n return r;\n });\n }\n return item;\n });\n this.setState({ list });\n })\n .catch(error => {\n if (error.response && error.response.data && error.response.data.msg) {\n message.error(lang[error.response.data.msg] || ERROR_DEFAULT);\n return;\n }\n message.error(lang[error.message] || ERROR_DEFAULT);\n })\n .finally(() => {\n this.handleChangeLoading('sReplyFavor', false);\n });\n }\n\n /**\n * 获取 OSS 上传的参数\n */\n sOssSts() {\n this.handleChangeLoading('sOssSts', true);\n const { API } = this.props;\n this.axios\n .get(`${API}/oss/sts`)\n .then(response => {\n this.setState({ oss: { ...response.data } });\n })\n .catch(error => {\n if (error.response && error.response.data && error.response.data.msg) {\n message.error(lang[error.response.data.msg] || ERROR_DEFAULT);\n return;\n }\n message.error(lang[error.message] || ERROR_DEFAULT);\n })\n .finally(() => {\n this.handleChangeLoading('sOssSts', false);\n });\n }\n\n render() {\n // 添加到 Context 的数据\n const value = {\n ...this.state,\n ...this.props,\n sCreateComment: this.sCreateComment,\n sGetComment: this.sGetComment,\n sCommentFavor: this.sCommentFavor,\n sReplyFavor: this.sReplyFavor,\n sCreateReply: this.sCreateReply,\n sGetReply: this.sGetReply,\n sOssSts: this.sOssSts,\n };\n\n return (\n <CommentContext.Provider value={value}>\n <div className=\"comment\">\n {this.props.showHeader && (\n <div style={{ marginBottom: 15 }}>\n <Tag className=\"comment-header-tag\">留言</Tag>\n <span className=\"comment-header-tip\">口碑</span>\n <span className=\"comment-header-text\">\n (全站挑出毛病或提出合理建议,奖励10到100元红包)\n </span>\n </div>\n )}\n {this.props.showEditor && (\n <CommentInput content={this.props.children} />\n )}\n {this.props.showList && (\n <div style={{ marginTop: 20 }}>\n <CommentList />\n </div>\n )}\n </div>\n </CommentContext.Provider>\n );\n }\n}\n\nApp.propTypes = {\n type: PropTypes.number.isRequired, // 评论的 type\n businessId: PropTypes.string.isRequired, // 评论的 business_id\n API: PropTypes.string, // 评论的 API 前缀\n showList: PropTypes.bool, // 是否显示评论列表\n showEditor: PropTypes.bool, // 是否显示评论输入框\n showHeader: PropTypes.bool, // 是否显示评论顶部的提示\n};\n\nApp.defaultProps = {\n API: 'http://api.links123.net/comment/v1',\n showList: true,\n showEditor: true,\n showHeader: true,\n};\n\nexport { Editor };\n\nexport default App;\n"]}