通用评论

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. var _modal = require("antd/es/modal");
  6. var _modal2 = _interopRequireDefault(_modal);
  7. var _icon = require("antd/es/icon");
  8. var _icon2 = _interopRequireDefault(_icon);
  9. 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; }; }();
  10. require("antd/es/modal/style");
  11. require("antd/es/icon/style");
  12. var _react = require("react");
  13. var _react2 = _interopRequireDefault(_react);
  14. var _reactIntlUniversal = require("react-intl-universal");
  15. var _reactIntlUniversal2 = _interopRequireDefault(_reactIntlUniversal);
  16. var _CommentInput = require("../CommentInput");
  17. var _CommentInput2 = _interopRequireDefault(_CommentInput);
  18. var _Editor = require("../Editor");
  19. var _Editor2 = _interopRequireDefault(_Editor);
  20. var _constant = require("../../constant");
  21. require("./EditComment.css");
  22. var _Comment = require("../../Comment");
  23. var _Comment2 = _interopRequireDefault(_Comment);
  24. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  25. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  26. 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; }
  27. 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; }
  28. var EditComment = function (_React$Component) {
  29. _inherits(EditComment, _React$Component);
  30. function EditComment(props) {
  31. _classCallCheck(this, EditComment);
  32. var _this = _possibleConstructorReturn(this, (EditComment.__proto__ || Object.getPrototypeOf(EditComment)).call(this, props));
  33. _this.handleSubmit = _this.handleSubmit.bind(_this);
  34. _this.state = {
  35. value: _this.getInitValue(props).value,
  36. fileList: _this.getInitValue(props).fileList
  37. };
  38. return _this;
  39. }
  40. _createClass(EditComment, [{
  41. key: "handleSubmit",
  42. value: function handleSubmit(_ref) {
  43. var _this2 = this;
  44. var _ref$text = _ref.text,
  45. text = _ref$text === undefined ? "" : _ref$text,
  46. _ref$files = _ref.files,
  47. files = _ref$files === undefined ? [] : _ref$files;
  48. var fileList = this.state.fileList;
  49. var _props = this.props,
  50. app = _props.app,
  51. action = _props.action,
  52. commentId = _props.commentId,
  53. replyId = _props.replyId,
  54. replyPage = _props.replyPage;
  55. var value = text;
  56. app.onBeforeUpdateComment();
  57. if (fileList && fileList.length) {
  58. value += _constant.IMAGE_SPLIT;
  59. fileList.forEach(function (file) {
  60. value += file.thumbUrl + ",";
  61. });
  62. }
  63. if (value.substr(-1) === ",") {
  64. value = value.slice(0, -1);
  65. }
  66. // 成功回调,失败不自动关闭
  67. var successCallback = function successCallback() {
  68. _this2.props.handleClose();
  69. };
  70. if (action === "comment") {
  71. app.sUpdateComment({ commentId: commentId, content: value, successCallback: successCallback });
  72. } else {
  73. app.sUpdateReply({
  74. commentId: commentId,
  75. content: value,
  76. replyId: replyId,
  77. replyPage: replyPage,
  78. successCallback: successCallback
  79. });
  80. }
  81. }
  82. }, {
  83. key: "getInitValue",
  84. value: function getInitValue(props) {
  85. var content = props.content;
  86. var newContent = content.content;
  87. var images = "";
  88. if (newContent.indexOf(_constant.IMAGE_SPLIT) !== -1) {
  89. newContent = newContent.split(_constant.IMAGE_SPLIT);
  90. images = newContent.pop();
  91. newContent = newContent.join("");
  92. }
  93. var fileList = [];
  94. if (images !== "") {
  95. fileList = images.split(",");
  96. fileList = fileList.map(function (item, index) {
  97. return {
  98. thumbUrl: item,
  99. uid: index
  100. };
  101. });
  102. }
  103. var value = this.renderTextWithReply(newContent, content);
  104. return { value: value, fileList: fileList };
  105. }
  106. }, {
  107. key: "getEmojiToolIcon",
  108. value: function getEmojiToolIcon() {
  109. return _react2.default.createElement(
  110. "div",
  111. { className: "expression-btn-wrap" },
  112. _react2.default.createElement(_icon2.default, { type: "smile", className: "icon" }),
  113. _react2.default.createElement(
  114. "span",
  115. { className: "icon-tool-text" },
  116. _reactIntlUniversal2.default.get("bilingually.emoji")
  117. )
  118. );
  119. }
  120. }, {
  121. key: "getImageToolIcon",
  122. value: function getImageToolIcon() {
  123. return _react2.default.createElement(
  124. "div",
  125. { className: "picture-btn-wrap" },
  126. _react2.default.createElement(_icon2.default, { type: "picture", className: "icon" }),
  127. _react2.default.createElement(
  128. "span",
  129. { className: "icon-tool-text" },
  130. _reactIntlUniversal2.default.get("bilingually.pic")
  131. )
  132. );
  133. }
  134. }, {
  135. key: "renderTextWithReply",
  136. value: function renderTextWithReply(text, content) {
  137. var newText = text;
  138. // const { reply } = content;
  139. // if (reply) {
  140. // newText = `${newText} //@${reply.user_name} ${reply.content}`;
  141. // if (reply.reply) {
  142. // return this.renderTextWithReply(newText, reply);
  143. // }
  144. // }
  145. return newText;
  146. }
  147. }, {
  148. key: "render",
  149. value: function render() {
  150. var _this3 = this;
  151. return _react2.default.createElement(
  152. _modal2.default,
  153. {
  154. visible: true,
  155. footer: null,
  156. wrapClassName: "editCommetModal",
  157. onCancel: this.props.handleClose
  158. },
  159. _react2.default.createElement(
  160. "div",
  161. { className: "title" },
  162. _reactIntlUniversal2.default.get("comment.edit")
  163. ),
  164. _react2.default.createElement(_CommentInput2.default, {
  165. content: _react2.default.createElement(_Editor2.default, {
  166. maxUpload: 9,
  167. autoFocus: true
  168. // {...this.props.editorProps}
  169. , action: this.props.action,
  170. replyId: this.props.replyId,
  171. commentId: this.props.commentId,
  172. userId: this.props.content.user_id,
  173. fileList: this.state.fileList,
  174. value: this.props.preRenderValue && this.props.preRenderValue(this.state.value),
  175. onChange: function onChange(value) {
  176. _this3.setState({
  177. value: value
  178. });
  179. },
  180. handleChangeFileList: function handleChangeFileList(fileList) {
  181. _this3.setState({
  182. fileList: fileList
  183. });
  184. },
  185. onSubmit: this.handleSubmit,
  186. emojiToolIcon: this.getEmojiToolIcon(),
  187. imageToolIcon: this.getImageToolIcon(),
  188. emojiPopoverPlacement: "bottom",
  189. uploadPopoverPlacement: "bottom",
  190. btnSubmitText: _reactIntlUniversal2.default.get("comment.update")
  191. })
  192. })
  193. );
  194. }
  195. }]);
  196. return EditComment;
  197. }(_react2.default.Component);
  198. exports.default = (0, _Comment2.default)(EditComment);
  199. //# sourceMappingURL=EditComment.js.map