通用评论 vedio

index.js 6.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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 _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; }; }();
  8. require("antd/es/icon/style/css");
  9. var _react = require("react");
  10. var _react2 = _interopRequireDefault(_react);
  11. var _propTypes = require("prop-types");
  12. var _propTypes2 = _interopRequireDefault(_propTypes);
  13. var _reactIntlUniversal = require("react-intl-universal");
  14. var _reactIntlUniversal2 = _interopRequireDefault(_reactIntlUniversal);
  15. var _Comment = require("../../Comment");
  16. var _Comment2 = _interopRequireDefault(_Comment);
  17. var _ContentItem = require("./../ContentItem");
  18. var _ContentItem2 = _interopRequireDefault(_ContentItem);
  19. require("./index.css");
  20. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  21. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  22. 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; }
  23. 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; }
  24. var CommentBox = function (_Component) {
  25. _inherits(CommentBox, _Component);
  26. function CommentBox(props) {
  27. _classCallCheck(this, CommentBox);
  28. var _this = _possibleConstructorReturn(this, (CommentBox.__proto__ || Object.getPrototypeOf(CommentBox)).call(this, props));
  29. _this.state = {
  30. showReply: true,
  31. page: 1
  32. };
  33. _this.handleToggleReply = _this.handleToggleReply.bind(_this);
  34. _this.handleGetMoreReply = _this.handleGetMoreReply.bind(_this);
  35. _this.renderReplies = _this.renderReplies.bind(_this);
  36. return _this;
  37. }
  38. /**
  39. * 切换是否显示回复列表
  40. */
  41. _createClass(CommentBox, [{
  42. key: "handleToggleReply",
  43. value: function handleToggleReply() {
  44. this.setState({ showReply: !this.state.showReply });
  45. }
  46. /**
  47. * 获取更多评论
  48. * @param {string} commentId comment id
  49. */
  50. }, {
  51. key: "handleGetMoreReply",
  52. value: function handleGetMoreReply(commentId) {
  53. // 从第一页开始获取评论
  54. var page = this.state.page;
  55. this.props.app.sGetReply({ commentId: commentId, page: page });
  56. this.setState({ page: page + 1 });
  57. }
  58. /**
  59. * 渲染回复 DOM
  60. * @param {array} replies 回复列表
  61. * @param {number} replies 回复的数量
  62. * @param {boolean} isNoMoreReply 是否没有更多回复
  63. */
  64. }, {
  65. key: "renderReplies",
  66. value: function renderReplies(replies, replyCount, isNoMoreReply) {
  67. var _this2 = this;
  68. var commentId = this.props.commentId;
  69. var showReply = this.state.showReply;
  70. if (showReply && replies && replies.length) {
  71. var len = replies.length;
  72. return _react2.default.createElement(
  73. "div",
  74. { style: { marginLeft: 50 } },
  75. replies.map(function (item, index) {
  76. if (index === len - 1) {
  77. return [_react2.default.createElement(_ContentItem2.default, {
  78. commentId: commentId,
  79. replyId: item.id,
  80. key: item.id,
  81. content: item,
  82. action: "replyToReply" // 回复的回复
  83. }), _react2.default.createElement(
  84. "div",
  85. { className: "comment-more-box", key: "show_more_button" },
  86. !isNoMoreReply && replyCount !== len && _react2.default.createElement(
  87. "span",
  88. {
  89. className: "comment-show-more",
  90. onClick: function onClick() {
  91. return _this2.handleGetMoreReply(commentId);
  92. }
  93. },
  94. _reactIntlUniversal2.default.get("reply.moreReply")
  95. ),
  96. _react2.default.createElement(
  97. "a",
  98. {
  99. style: { float: "right" },
  100. onClick: _this2.handleToggleReply
  101. },
  102. _react2.default.createElement(_icon2.default, { type: "up" }),
  103. " ",
  104. _reactIntlUniversal2.default.get("reply.collapse")
  105. )
  106. )];
  107. }
  108. return _react2.default.createElement(_ContentItem2.default, {
  109. commentId: commentId,
  110. replyId: item.id,
  111. key: item.id,
  112. content: item,
  113. action: "replyToReply" // 评论的回复
  114. });
  115. })
  116. );
  117. }
  118. return null;
  119. }
  120. }, {
  121. key: "render",
  122. value: function render() {
  123. var content = this.props.content;
  124. var showReply = this.state.showReply;
  125. return _react2.default.createElement(
  126. "div",
  127. null,
  128. _react2.default.createElement(_ContentItem2.default, {
  129. content: content,
  130. onShowReply: this.handleToggleReply,
  131. showReply: showReply,
  132. commentId: content.id,
  133. action: "reply" // 评论的回复
  134. }),
  135. this.renderReplies(content.replies, content.reply_count, content.isNoMoreReply)
  136. );
  137. }
  138. }]);
  139. return CommentBox;
  140. }(_react.Component);
  141. CommentBox.propTypes = {
  142. commentId: _propTypes2.default.string.isRequired
  143. };
  144. CommentBox.defaultProps = {};
  145. exports.default = (0, _Comment2.default)(CommentBox);
  146. //# sourceMappingURL=index.js.map