{"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","type","businessId","axios","get","URL","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","withCredentials","success","unshift","cb","comment_id","favored","favor_count","marginTop","Component"],"mappings":";;;;;;;;;;;;;;;;AAAA;;;;AAEA;;;;AACA;;AACA;;AACA;;AACA;;;;AACA;;;;AAEA;;;;;;;;;AADA;;;IAGMA,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;AAClB,WAAKC,WAAL;AACD;;AAED;;;;;;;;wCAKoBM,G,EAAKC,K,EAAO;AAAA,UACtBf,OADsB,GACV,KAAKD,KADK,CACtBC,OADsB;;AAE9BA,cAAQc,GAAR,IAAeC,KAAf;AACA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CAAcA,MAAMV,QAAN,CAAeC,IAAf,CAAoBU,GAApB,IAA2BC,uBAAzC;AACA;AACD;AACD,0BAAQF,KAAR,CAAcA,MAAMG,OAAN,IAAiBD,uBAA/B;AACD,OAXH,EAYGE,OAZH,CAYW,YAAM;AACb,eAAKhC,mBAAL,CAAyB,SAAzB,EAAoC,KAApC;AACD,OAdH;AAeD;;;6BAEQ;AACP;AACA,UAAMS,qBACD,KAAKhB,KADJ;AAEJW,wBAAgB,KAAKA,cAFjB;AAGJF,qBAAa,KAAKA,WAHd;AAIJI,uBAAe,KAAKA,aAJhB;AAKJD,sBAAc,KAAKA,YALf;AAMJF,mBAAW,KAAKA,SANZ;AAOJI,iBAAS,KAAKA;AAPV,QAAN;;AAUA,aACE;AAAC,+BAAD,CAAgB,QAAhB;AAAA,UAAyB,OAAOE,KAAhC;AACE;AAAA;AAAA,YAAK,WAAU,SAAf;AACE,wCAAC,sBAAD,OADF;AAEE;AAAA;AAAA,cAAK,OAAO,EAAEuC,WAAW,EAAb,EAAZ;AACE,0CAAC,qBAAD;AADF;AAFF;AADF,OADF;AAUD;;;;EApSeC,gB;;kBAuSH1D,G","file":"App.js","sourcesContent":["import React, { Component } from \"react\";\nimport { message } from \"antd\";\nimport axios from \"./axios\";\nimport { URL, ERROR_DEFAULT, LIMIT } from \"./constant\";\nimport { CommentContext } from \"./Comment\";\nimport { isFunction } from \"./helper\";\nimport CommentInput from \"./components/CommentInput\";\nimport CommentList from \"./components/CommentList\";\n// import * as mock from \"./mock\";\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 this.sGetComment();\n }\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({ type = 1, businessId = 1, page = 1 } = {}) {\n this.handleChangeLoading(\"sGetComment\", true);\n // 测试数据列表\n // const { comments } = mock;\n // this.setState({\n // list: comments.list,\n // page: 1,\n // total: 100\n // });\n // this.handleChangeLoading(\"sGetComment\", false);\n // return;\n axios\n .get(\n `${URL}/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 axios\n .get(`${URL}/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 {object} data { type, business_id, content }\n */\n sCreateComment(data) {\n if (!data.content) return message.error(\"评论内容不能为空 \");\n this.handleChangeLoading(\"sCreateComment\", true);\n axios(`${URL}/comments`, {\n method: \"post\",\n data,\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 axios(`${URL}/replies`, {\n method: \"post\",\n data,\n withCredentials: true\n })\n .then(response => {\n // console.log(\"response: \", response.data);\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 axios(`${URL}/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 axios\n .get(`${URL}/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 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 \n
\n \n
\n \n
\n
\n
\n );\n }\n}\n\nexport default App;\n"]}