通用评论

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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 _ref$text = _ref.text,
  44. text = _ref$text === undefined ? "" : _ref$text,
  45. _ref$files = _ref.files,
  46. files = _ref$files === undefined ? [] : _ref$files;
  47. var fileList = this.state.fileList;
  48. var _props = this.props,
  49. app = _props.app,
  50. action = _props.action,
  51. commentId = _props.commentId,
  52. replyId = _props.replyId,
  53. replyPage = _props.replyPage;
  54. var value = text;
  55. app.onBeforeUpdateComment();
  56. if (fileList && fileList.length) {
  57. value += _constant.IMAGE_SPLIT;
  58. fileList.forEach(function (file) {
  59. value += file.thumbUrl + ",";
  60. });
  61. }
  62. if (value.substr(-1) === ",") {
  63. value = value.slice(0, -1);
  64. }
  65. if (action === "comment") {
  66. app.sUpdateComment({ commentId: commentId, content: value });
  67. } else {
  68. app.sUpdateReply({ commentId: commentId, content: value, replyId: replyId, replyPage: replyPage });
  69. }
  70. this.props.handleClose();
  71. }
  72. }, {
  73. key: "getInitValue",
  74. value: function getInitValue(props) {
  75. var content = props.content;
  76. var newContent = content.content;
  77. var images = "";
  78. if (newContent.indexOf(_constant.IMAGE_SPLIT) !== -1) {
  79. newContent = newContent.split(_constant.IMAGE_SPLIT);
  80. images = newContent.pop();
  81. newContent = newContent.join("");
  82. }
  83. var fileList = [];
  84. if (images !== "") {
  85. fileList = images.split(",");
  86. fileList = fileList.map(function (item, index) {
  87. return {
  88. thumbUrl: item,
  89. uid: index
  90. };
  91. });
  92. }
  93. var value = this.renderTextWithReply(newContent, content);
  94. return { value: value, fileList: fileList };
  95. }
  96. }, {
  97. key: "getEmojiToolIcon",
  98. value: function getEmojiToolIcon() {
  99. return _react2.default.createElement(
  100. "div",
  101. { className: "expression-btn-wrap" },
  102. _react2.default.createElement(_icon2.default, { type: "smile", className: "icon" }),
  103. _react2.default.createElement(
  104. "span",
  105. { className: "icon-tool-text" },
  106. _reactIntlUniversal2.default.get("bilingually.emoji")
  107. )
  108. );
  109. }
  110. }, {
  111. key: "getImageToolIcon",
  112. value: function getImageToolIcon() {
  113. return _react2.default.createElement(
  114. "div",
  115. { className: "picture-btn-wrap" },
  116. _react2.default.createElement(_icon2.default, { type: "picture", className: "icon" }),
  117. _react2.default.createElement(
  118. "span",
  119. { className: "icon-tool-text" },
  120. _reactIntlUniversal2.default.get("bilingually.pic")
  121. )
  122. );
  123. }
  124. }, {
  125. key: "renderTextWithReply",
  126. value: function renderTextWithReply(text, content) {
  127. var newText = text;
  128. // const { reply } = content;
  129. // if (reply) {
  130. // newText = `${newText} //@${reply.user_name} ${reply.content}`;
  131. // if (reply.reply) {
  132. // return this.renderTextWithReply(newText, reply);
  133. // }
  134. // }
  135. return newText;
  136. }
  137. }, {
  138. key: "render",
  139. value: function render() {
  140. var _this2 = this;
  141. return _react2.default.createElement(
  142. _modal2.default,
  143. {
  144. visible: true,
  145. footer: null,
  146. wrapClassName: "editCommetModal",
  147. onCancel: this.props.handleClose
  148. },
  149. _react2.default.createElement(
  150. "div",
  151. { className: "title" },
  152. _reactIntlUniversal2.default.get("comment.edit")
  153. ),
  154. _react2.default.createElement(_CommentInput2.default, {
  155. content: _react2.default.createElement(_Editor2.default, {
  156. maxUpload: 9,
  157. autoFocus: true
  158. // {...this.props.editorProps}
  159. , action: this.props.action,
  160. replyId: this.props.replyId,
  161. commentId: this.props.commentId,
  162. userId: this.props.content.user_id,
  163. fileList: this.state.fileList,
  164. value: this.state.value,
  165. onChange: function onChange(value) {
  166. _this2.setState({
  167. value: value
  168. });
  169. },
  170. handleChangeFileList: function handleChangeFileList(fileList) {
  171. _this2.setState({
  172. fileList: fileList
  173. });
  174. },
  175. onSubmit: this.handleSubmit,
  176. emojiToolIcon: this.getEmojiToolIcon(),
  177. imageToolIcon: this.getImageToolIcon(),
  178. emojiPopoverPlacement: "bottom",
  179. uploadPopoverPlacement: "bottom",
  180. btnSubmitText: _reactIntlUniversal2.default.get("comment.update")
  181. })
  182. })
  183. );
  184. }
  185. }]);
  186. return EditComment;
  187. }(_react2.default.Component);
  188. exports.default = (0, _Comment2.default)(EditComment);
  189. //# sourceMappingURL=EditComment.js.map