通用评论

1
  1. {"version":3,"sources":["../../../src/components/CommentInput/index.js"],"names":["CommentInput","props","state","value","fileList","fileMap","handleChange","bind","handleSubmit","handleChangeFileList","handleChangeEmoji","handleUpload","setState","emojiId","React","Children","forEach","content","child","onChange","uid","path","length","OSS_LINK","item","type","commentId","replyId","handleToggleInput","app","sCreateComment","sCreateReply","comment_id","reply_id","onSubmit","childrenWithProps","map","cloneElement","onChangeFileList","onChangeEmoji","onUpload","loading","border","color","padding","marginLeft","marginTop","Component","propTypes","PropTypes","oneOf","defaultProps"],"mappings":";;;;;;;;;;AAAA;;;;AACA;;;;AACA;;AACA;;;;;;;;;;;;IAEMA,Y;;;AACJ,wBAAYC,KAAZ,EAAmB;AAAA;;AAAA,4HACXA,KADW;;AAEjB,UAAKC,KAAL,GAAa;AACXC,aAAO,EADI;;AAGXC,gBAAU,EAHC,EAGG;AACdC,eAAS,EAJE,CAIC;AAJD,KAAb;AAMA,UAAKC,YAAL,GAAoB,MAAKA,YAAL,CAAkBC,IAAlB,OAApB;AACA,UAAKC,YAAL,GAAoB,MAAKA,YAAL,CAAkBD,IAAlB,OAApB;AACA,UAAKE,oBAAL,GAA4B,MAAKA,oBAAL,CAA0BF,IAA1B,OAA5B;AACA,UAAKG,iBAAL,GAAyB,MAAKA,iBAAL,CAAuBH,IAAvB,OAAzB;AACA,UAAKI,YAAL,GAAoB,MAAKA,YAAL,CAAkBJ,IAAlB,OAApB;AAZiB;AAalB;;;;iCAEYJ,K,EAAO;AAClB,WAAKS,QAAL,CAAc,EAAET,YAAF,EAAd;AACD;;;yCAEoBC,Q,EAAU;AAC7B,WAAKQ,QAAL,CAAc,EAAER,kBAAF,EAAd;AACD;;;sCAEiBS,O,EAAS;AAAA,UACnBV,KADmB,GACT,KAAKD,KADI,CACnBC,KADmB;;AAEzBA,qBAAaU,OAAb;AACA,WAAKD,QAAL,CAAc,EAAET,YAAF,EAAd;AACAW,sBAAMC,QAAN,CAAeC,OAAf,CAAuB,KAAKf,KAAL,C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AAY,MAAd,EAAsBF,OAAO,SAA7B,EAAb;AAAA;AAAA;AAFF;AAVF,SADD,GAkBG,IAnBN;AAoBE;AAAA;AAAA,YAAK,OAAO,EAAEG,WAAW,EAAb,EAAZ;AAAgCX;AAAhC;AApBF,OADF;AAwBD;;;;EA7HwBY,gB;;AAgI3B/C,aAAagD,SAAb,GAAyB;AACvB;AACAvB,QAAMwB,oBAAUC,KAAV,CAAgB,CAAC,QAAD,EAAW,SAAX,EAAsB,OAAtB,CAAhB;AAFiB,CAAzB;;AAKAlD,aAAamD,YAAb,GAA4B;AAC1B1B,QAAM;AADoB,CAA5B;;kBAIe,uBAAQzB,YAAR,C","file":"index.js","sourcesContent":["import React, { Component } from \"react\";\nimport PropTypes from \"prop-types\";\nimport { OSS_LINK } from \"../../constant\";\nimport Comment from \"../../Comment\";\n\nclass CommentInput extends Component {\n constructor(props) {\n super(props);\n this.state = {\n value: \"\",\n\n fileList: [], // 图片列表\n fileMap: {} // 已经上传的图片路径和 uid 的映射 { uid: path }\n };\n this.handleChange = this.handleChange.bind(this);\n this.handleSubmit = this.handleSubmit.bind(this);\n this.handleChangeFileList = this.handleChangeFileList.bind(this);\n this.handleChangeEmoji = this.handleChangeEmoji.bind(this);\n this.handleUpload = this.handleUpload.bind(this);\n }\n\n handleChange(value) {\n this.setState({ value });\n }\n\n handleChangeFileList(fileList) {\n this.setState({ fileList });\n }\n\n handleChangeEmoji(emojiId) {\n let { value } = this.state;\n value += `[${emojiId}]`;\n this.setState({ value });\n React.Children.forEach(this.props.content, child => {\n // 如果 Editor 的父组件传入了 onChange 事件,则需要将改变之后的值传递给父组件\n if (child.props.onChange) {\n child.props.onChange(value);\n }\n });\n }\n\n handleUpload({ uid, path }) {\n const { fileMap } = this.state;\n fileMap[uid] = path;\n this.setState({ fileMap });\n }\n\n handleSubmit() {\n let { value, fileMap, fileList } = this.state;\n if (fileList.length) {\n value += \"<br/>\";\n fileList.forEach(item => {\n value += `[${OSS_LINK}${fileMap[item.uid]}]`;\n });\n }\n\n const { type, commentId, replyId, handleToggleInput } = this.props;\n if (type === \"normal\") {\n this.props.app.sCreateComment({\n content: value\n });\n } else if (type === \"comment\") {\n this.props.app.sCreateReply(\n {\n comment_id: commentId,\n content: value\n },\n () => handleToggleInput()\n );\n } else if (type === \"reply\") {\n this.props.app.sCreateReply(\n {\n comment_id: commentId,\n content: value,\n reply_id: replyId\n },\n () => handleToggleInput()\n );\n }\n\n React.Children.forEach(this.props.content, child => {\n // 如果 Editor 的父组件传入了 onSubmit 事件,则需要将改变之后的值传递给父组件\n if (child.props.onSubmit) {\n child.props.onSubmit(value);\n }\n });\n }\n\n render() {\n const { type } = this.props;\n const { value, fileList } = this.state;\n\n const childrenWithProps = React.Children.map(this.props.content, child => {\n return React.cloneElement(child, {\n value: value,\n fileList: fileList,\n onChange: this.handleChange,\n onSubmit: this.handleSubmit,\n onChangeFileList: this.handleChangeFileList,\n onChangeEmoji: this.handleChangeEmoji,\n onUpload: this.handleUpload,\n loading: this.props.app.loading.sCreateComment,\n ...child.props\n });\n });\n\n return (\n <div>\n {type === \"normal\" ? (\n <div>\n <span\n style={{\n border: \"1px solid #CECECE\",\n color: \"#666\",\n padding: \"2px 3px\"\n }}\n >\n 回复\n </span>\n <span style={{ marginLeft: \"20px\", color: \"#5198EB\" }}>\n 口碑\n <span style={{ marginLeft: \"20px\", color: \"#666666\" }}>\n (全站挑出毛病或提出合理建议,奖励10到100元红包)\n </span>\n </span>\n </div>\n ) : null}\n <div style={{ marginTop: 40 }}>{childrenWithProps}</div>\n </div>\n );\n }\n}\n\nCommentInput.propTypes = {\n // normal 有切换回复/口碑的 header ; comment 评论输入框 / reply 回复输入框\n type: PropTypes.oneOf([\"normal\", \"comment\", \"reply\"])\n};\n\nCommentInput.defaultProps = {\n type: \"normal\"\n};\n\nexport default Comment(CommentInput);\n"]}