1 |
- {"version":3,"sources":["../src/App.js"],"names":["App","props","state","loading","oss","list","page","total","isNoMoreComment","handleChangeLoading","bind","sGetComment","sGetReply","sCreateComment","sCreateReply","sCommentFavor","sOssSts","key","value","setState","API","type","businessId","axios","get","LIMIT","then","response","data","newList","oldList","filter","o","isTemporary","concat","info","catch","error","msg","ERROR_DEFAULT","message","finally","commentId","replies","map","item","id","isNoMoreReply","content","method","business_id","withCredentials","success","unshift","cb","comment_id","favored","favor_count","showEditor","children","showList","marginTop","Component","propTypes","PropTypes","number","isRequired","string","bool","defaultProps","Editor"],"mappings":";;;;;;;;;;;;;;;;;AAAA;;;;AACA;;;;AAEA;;;;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,OAAL,GAAe,MAAKA,OAAL,CAAaN,IAAb,OAAf;AArBiB;AAsBlB;;;;wCAEmB,CAAE;;AAEtB;;;;;;;;wCAKoBO,G,EAAKC,K,EAAO;AAAA,UACtBf,OADsB,GACV,KAAKD,K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,qBAAD;AADF;AALJ;AADF,OADF;AAcD;;;;EAvSeC,gB;;AA0SlB9D,IAAI+D,SAAJ,GAAgB;AACd1C,QAAM2C,oBAAUC,MAAV,CAAiBC,UADT,EACqB;AACnC5C,cAAY0C,oBAAUG,MAAV,CAAiBD,UAFf,EAE2B;AACzC9C,OAAK4C,oBAAUG,MAHD,EAGS;AACvBP,YAAUI,oBAAUI,IAJN,EAIY;AAC1BV,cAAYM,oBAAUI,IALR,CAKa;AALb,CAAhB;;AAQApE,IAAIqE,YAAJ,GAAmB;AACjBjD,OAAK,oCADY;AAEjBwC,YAAU,IAFO;AAGjBF,cAAY;AAHK,CAAnB;;QAMSY,M,GAAAA,gB;kBAEMtE,G","file":"App.js","sourcesContent":["import React, { Component } from \"react\";\nimport PropTypes from \"prop-types\";\nimport { message } 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 \"./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.sOssSts = this.sOssSts.bind(this);\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 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(error.response.data.msg || ERROR_DEFAULT);\n return;\n }\n message.error(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 axios\n .get(`${API}/replies?comment_id=${commentId}&page=${page}&limit=${LIMIT}`)\n .then(response => {\n const { list: replies } = response.data;\n if (!replies) {\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 (replies) {\n if (page === 1) {\n // 如果当前页数为第一页,则清空当前所有的 replies\n // 并将获取到的 replies 存放在 state\n item.replies = replies;\n } else {\n item.replies = item.replies.concat(replies);\n // 如果当前页数非第一页,则合并 replies\n }\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(error.response.data.msg || ERROR_DEFAULT);\n return;\n }\n message.error(error.message || ERROR_DEFAULT);\n })\n .finally(() => {\n this.handleChangeLoading(\"sGetReply\", false);\n });\n }\n\n /**\n * 添加评论\n * @param {string} content comment content\n */\n sCreateComment(content) {\n if (!content) return message.error(\"评论内容不能为空 \");\n this.handleChangeLoading(\"sCreateComment\", true);\n const { API, type, businessId } = this.props;\n 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 // 将数据写入到 list 中\n // 临时插入\n // 等到获取数据之后,删除临时数据\n const { list } = this.state;\n list.unshift({\n ...response.data,\n isTemporary: true // 临时的数据\n });\n this.setState({ list });\n })\n .catch(error => {\n if (error.response && error.response.data && error.response.data.msg) {\n message.error(error.response.data.msg || ERROR_DEFAULT);\n return;\n }\n message.error(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 axios(`${API}/replies`, {\n method: \"post\",\n data,\n withCredentials: true\n })\n .then(response => {\n // // 将该条数据插入到 list 中\n // const list = this.state.list.map(item => {\n // if (item.id === data.comment_id) {\n // if (!item.replies) item.replies = [];\n // item.reply_count += 1\n // item.replies.unshift(response.data);\n // }\n // return item;\n // });\n // this.setState({ list });\n this.sGetReply({ commentId: data.comment_id });\n message.success(\"回复成功!\");\n if (isFunction(cb)) cb();\n })\n .catch(error => {\n if (error.response && error.response.data && error.response.data.msg) {\n message.error(error.response.data.msg || ERROR_DEFAULT);\n return;\n }\n message.error(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 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(error.response.data.msg || ERROR_DEFAULT);\n return;\n }\n message.error(error.message || ERROR_DEFAULT);\n })\n .finally(() => {\n this.handleChangeLoading(\"sCommentFavor\", false);\n });\n }\n\n /**\n * 获取 OSS 上传的参数\n */\n sOssSts() {\n this.handleChangeLoading(\"sOssSts\", true);\n const { API } = this.props;\n 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(error.response.data.msg || ERROR_DEFAULT);\n return;\n }\n message.error(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 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.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};\n\nApp.defaultProps = {\n API: \"http://api.links123.net/comment/v1\",\n showList: true,\n showEditor: true\n};\n\nexport { Editor };\n\nexport default App;\n"]}
|