通用评论

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  6. var _react = require("react");
  7. var _react2 = _interopRequireDefault(_react);
  8. var _propTypes = require("prop-types");
  9. var _propTypes2 = _interopRequireDefault(_propTypes);
  10. var _constant = require("../../constant");
  11. var _Comment = require("../../Comment");
  12. var _Comment2 = _interopRequireDefault(_Comment);
  13. var _Editor = require("../Editor");
  14. var _Editor2 = _interopRequireDefault(_Editor);
  15. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  16. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  17. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  18. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  19. var PLACEHOLDER = {
  20. normal: "说点什么吧...",
  21. default: "说点什么吧..."
  22. };
  23. var CommentInput = function (_Component) {
  24. _inherits(CommentInput, _Component);
  25. function CommentInput(props) {
  26. _classCallCheck(this, CommentInput);
  27. var _this = _possibleConstructorReturn(this, (CommentInput.__proto__ || Object.getPrototypeOf(CommentInput)).call(this, props));
  28. _this.state = {
  29. value: "",
  30. fileList: [], // 图片列表
  31. fileMap: {} // 已经上传的图片路径和 uid 的映射 { uid: path }
  32. };
  33. _this.handleChange = _this.handleChange.bind(_this);
  34. _this.handleSubmit = _this.handleSubmit.bind(_this);
  35. _this.handleChangeFileList = _this.handleChangeFileList.bind(_this);
  36. _this.handleChangeEmoji = _this.handleChangeEmoji.bind(_this);
  37. _this.handleUpload = _this.handleUpload.bind(_this);
  38. return _this;
  39. }
  40. _createClass(CommentInput, [{
  41. key: "handleChange",
  42. value: function handleChange(e) {
  43. this.setState({ value: e.target.value });
  44. }
  45. }, {
  46. key: "handleChangeFileList",
  47. value: function handleChangeFileList(fileList) {
  48. this.setState({ fileList: fileList });
  49. }
  50. }, {
  51. key: "handleChangeEmoji",
  52. value: function handleChangeEmoji(emojiId) {
  53. var value = this.state.value;
  54. value += "[" + emojiId + "]";
  55. this.setState({ value: value });
  56. }
  57. }, {
  58. key: "handleUpload",
  59. value: function handleUpload(_ref) {
  60. var uid = _ref.uid,
  61. path = _ref.path;
  62. var fileMap = this.state.fileMap;
  63. fileMap[uid] = path;
  64. this.setState({ fileMap: fileMap });
  65. }
  66. }, {
  67. key: "handleSubmit",
  68. value: function handleSubmit() {
  69. var _state = this.state,
  70. value = _state.value,
  71. fileMap = _state.fileMap,
  72. fileList = _state.fileList;
  73. if (fileList.length) {
  74. fileList.forEach(function (item) {
  75. value += "[" + _constant.OSS_LINK + fileMap[item.uid] + "]";
  76. });
  77. }
  78. var _props = this.props,
  79. type = _props.type,
  80. commentId = _props.commentId,
  81. replyId = _props.replyId,
  82. handleToggleInput = _props.handleToggleInput;
  83. if (type === "normal") {
  84. this.props.app.sCreateComment({
  85. type: 1,
  86. business_id: "1",
  87. content: value
  88. });
  89. } else if (type === "comment") {
  90. this.props.app.sCreateReply({
  91. comment_id: commentId,
  92. content: value
  93. }, function () {
  94. return handleToggleInput();
  95. });
  96. } else if (type === "reply") {
  97. this.props.app.sCreateReply({
  98. comment_id: commentId,
  99. content: value,
  100. reply_id: replyId
  101. }, function () {
  102. return handleToggleInput();
  103. });
  104. }
  105. }
  106. }, {
  107. key: "render",
  108. value: function render() {
  109. var type = this.props.type;
  110. var _state2 = this.state,
  111. value = _state2.value,
  112. fileList = _state2.fileList;
  113. return _react2.default.createElement(
  114. "div",
  115. null,
  116. type === "normal" ? _react2.default.createElement(
  117. "div",
  118. null,
  119. _react2.default.createElement(
  120. "span",
  121. {
  122. style: {
  123. border: "1px solid #CECECE",
  124. color: "#666",
  125. padding: "2px 3px"
  126. }
  127. },
  128. "\u56DE\u590D"
  129. ),
  130. _react2.default.createElement(
  131. "span",
  132. { style: { marginLeft: "20px", color: "#5198EB" } },
  133. "\u53E3\u7891",
  134. _react2.default.createElement(
  135. "span",
  136. { style: { marginLeft: "20px", color: "#666666" } },
  137. "(\u5168\u7AD9\u6311\u51FA\u6BDB\u75C5\u6216\u63D0\u51FA\u5408\u7406\u5EFA\u8BAE\uFF0C\u5956\u52B110\u5230100\u5143\u7EA2\u5305)"
  138. )
  139. )
  140. ) : null,
  141. _react2.default.createElement(
  142. "div",
  143. { style: { marginTop: 40 } },
  144. _react2.default.createElement(_Editor2.default, {
  145. value: value,
  146. placeholder: PLACEHOLDER[type] || PLACEHOLDER.default,
  147. fileList: fileList,
  148. onChange: this.handleChange,
  149. onSubmit: this.handleSubmit,
  150. onChangeFileList: this.handleChangeFileList,
  151. onChangeEmoji: this.handleChangeEmoji,
  152. onUpload: this.handleUpload,
  153. loading: this.props.app.loading.sCreateComment
  154. })
  155. )
  156. );
  157. }
  158. }]);
  159. return CommentInput;
  160. }(_react.Component);
  161. CommentInput.propTypes = {
  162. // normal 有切换回复/口碑的 header ; comment 评论输入框 / reply 回复输入框
  163. type: _propTypes2.default.oneOf(["normal", "comment", "reply"])
  164. };
  165. CommentInput.defaultProps = {
  166. type: "normal"
  167. };
  168. exports.default = (0, _Comment2.default)(CommentInput);
  169. //# sourceMappingURL=index.js.map