通用评论

index.js 7.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. var _icon = require("antd/es/icon");
  6. var _icon2 = _interopRequireDefault(_icon);
  7. var _avatar = require("antd/es/avatar");
  8. var _avatar2 = _interopRequireDefault(_avatar);
  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/icon/style/css");
  11. require("antd/es/avatar/style/css");
  12. var _react = require("react");
  13. var _react2 = _interopRequireDefault(_react);
  14. var _propTypes = require("prop-types");
  15. var _propTypes2 = _interopRequireDefault(_propTypes);
  16. var _dayjs = require("dayjs");
  17. var _dayjs2 = _interopRequireDefault(_dayjs);
  18. var _Comment = require("../../Comment");
  19. var _Comment2 = _interopRequireDefault(_Comment);
  20. var _CommentInput = require("../CommentInput");
  21. var _CommentInput2 = _interopRequireDefault(_CommentInput);
  22. var _helper = require("../../helper");
  23. require("./index.css");
  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 CommentItem = function (_Component) {
  29. _inherits(CommentItem, _Component);
  30. function CommentItem(props) {
  31. _classCallCheck(this, CommentItem);
  32. var _this = _possibleConstructorReturn(this, (CommentItem.__proto__ || Object.getPrototypeOf(CommentItem)).call(this, props));
  33. _this.state = {
  34. isShowInput: false
  35. };
  36. _this.handleToggleInput = _this.handleToggleInput.bind(_this);
  37. _this.renderTextWithReply = _this.renderTextWithReply.bind(_this);
  38. return _this;
  39. }
  40. _createClass(CommentItem, [{
  41. key: "handleToggleInput",
  42. value: function handleToggleInput() {
  43. this.setState({ isShowInput: !this.state.isShowInput });
  44. }
  45. }, {
  46. key: "renderTextWithReply",
  47. value: function renderTextWithReply(text, content) {
  48. var newText = text;
  49. var reply = content.reply;
  50. if (reply) {
  51. newText = newText + " //@<a href=\"/" + reply.user_id + "\">" + reply.user_name + "</a> " + reply.content;
  52. if (reply.reply) {
  53. return this.renderTextWithReply(newText, reply);
  54. }
  55. }
  56. return newText;
  57. }
  58. }, {
  59. key: "render",
  60. value: function render() {
  61. var _props = this.props,
  62. commentId = _props.commentId,
  63. replyId = _props.replyId,
  64. content = _props.content,
  65. type = _props.type,
  66. showReply = _props.showReply,
  67. onShowReply = _props.onShowReply,
  68. app = _props.app;
  69. var isShowInput = this.state.isShowInput;
  70. var isComment = type === "comment";
  71. return _react2.default.createElement(
  72. "div",
  73. { className: "box" },
  74. _react2.default.createElement(
  75. "div",
  76. { className: "left" },
  77. _react2.default.createElement(_avatar2.default, { src: content.user_avatar, size: "large" })
  78. ),
  79. _react2.default.createElement(
  80. "div",
  81. { className: "right" },
  82. _react2.default.createElement(
  83. "div",
  84. { className: "name" },
  85. _react2.default.createElement(
  86. "a",
  87. { href: "/" + content.user_id },
  88. content.user_name || "暂无昵称"
  89. ),
  90. _react2.default.createElement(
  91. "span",
  92. { style: { marginLeft: 10 } },
  93. (0, _dayjs2.default)(content.created * 1000).format("YYYY-MM-DD HH:mm:ss")
  94. )
  95. ),
  96. _react2.default.createElement("div", {
  97. className: "content",
  98. dangerouslySetInnerHTML: {
  99. __html: (0, _helper.renderContent)(this.renderTextWithReply(content.content, content))
  100. }
  101. }),
  102. _react2.default.createElement(
  103. "div",
  104. { className: "bottom" },
  105. isComment && content.reply_count ? _react2.default.createElement(
  106. "div",
  107. null,
  108. _react2.default.createElement(
  109. "a",
  110. {
  111. className: "itemLeft",
  112. onClick: onShowReply,
  113. style: { userSelect: "none" }
  114. },
  115. content.reply_count,
  116. " \u6761\u56DE\u590D",
  117. showReply ? _react2.default.createElement(_icon2.default, { type: "up" }) : _react2.default.createElement(_icon2.default, { type: "down" })
  118. )
  119. ) : null,
  120. _react2.default.createElement(
  121. "a",
  122. { onClick: this.handleToggleInput, className: "itemRight" },
  123. "\xA0 \u56DE\u590D"
  124. ),
  125. _react2.default.createElement(
  126. "div",
  127. {
  128. className: "itemRight",
  129. style: { cursor: "pointer" },
  130. onClick: function onClick() {
  131. return app.sCommentFavor(content.id, content.favored);
  132. }
  133. },
  134. _react2.default.createElement(_icon2.default, {
  135. type: "like-o",
  136. className: content.favored ? "favored" : ""
  137. }),
  138. "\xA0",
  139. content.favor_count
  140. )
  141. ),
  142. isShowInput ? _react2.default.createElement(_CommentInput2.default, {
  143. type: type,
  144. replyId: replyId,
  145. commentId: commentId,
  146. handleToggleInput: this.handleToggleInput
  147. }) : null
  148. )
  149. );
  150. }
  151. }]);
  152. return CommentItem;
  153. }(_react.Component);
  154. CommentItem.propTypes = {
  155. content: _propTypes2.default.object.isRequired,
  156. // comment 评论
  157. // reply 回复
  158. type: _propTypes2.default.oneOf(["comment", "reply"]),
  159. onShowReply: _propTypes2.default.func
  160. };
  161. CommentItem.defaultProps = {
  162. type: "comment",
  163. onShowReply: function onShowReply() {}
  164. };
  165. exports.default = (0, _Comment2.default)(CommentItem);
  166. //# sourceMappingURL=index.js.map