通用评论 vedio

index.js 8.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  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 _Comment = require("../../Comment");
  14. var _Comment2 = _interopRequireDefault(_Comment);
  15. var _ContentItem = require("./../ContentItem");
  16. var _ContentItem2 = _interopRequireDefault(_ContentItem);
  17. var _ReplyItem = require("./../ReplyItem");
  18. var _ReplyItem2 = _interopRequireDefault(_ReplyItem);
  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. // import intl from "react-intl-universal";
  25. var CommentBox = function (_Component) {
  26. _inherits(CommentBox, _Component);
  27. function CommentBox(props) {
  28. _classCallCheck(this, CommentBox);
  29. var _this = _possibleConstructorReturn(this, (CommentBox.__proto__ || Object.getPrototypeOf(CommentBox)).call(this, props));
  30. _this.state = {
  31. showReply: true,
  32. page: 1
  33. };
  34. _this.handleToggleReply = _this.handleToggleReply.bind(_this);
  35. _this.handleGetMoreReply = _this.handleGetMoreReply.bind(_this);
  36. _this.renderReplies = _this.renderReplies.bind(_this);
  37. return _this;
  38. }
  39. /**
  40. * 切换是否显示回复列表
  41. */
  42. _createClass(CommentBox, [{
  43. key: "handleToggleReply",
  44. value: function handleToggleReply() {
  45. this.setState({ showReply: !this.state.showReply });
  46. }
  47. /**
  48. * 获取更多评论
  49. * @param {string} commentId comment id
  50. */
  51. }, {
  52. key: "handleGetMoreReply",
  53. value: function handleGetMoreReply(commentId) {
  54. // 从第一页开始获取评论
  55. var page = this.state.page;
  56. this.props.app.sGetReply({ commentId: commentId, page: page });
  57. this.setState({ page: page + 1 });
  58. }
  59. /**
  60. * 渲染回复 DOM
  61. * @param {array} replies 回复列表
  62. * @param {number} replies 回复的数量
  63. * @param {boolean} isNoMoreReply 是否没有更多回复
  64. */
  65. // renderReplies(replies, replyCount, isNoMoreReply) {
  66. // console.log('replies', replies);
  67. // console.log('replyCount', replyCount);
  68. // console.log('isNoMoreReply', isNoMoreReply);
  69. // const { commentId } = this.props;
  70. // const { showReply } = this.state;
  71. // if (showReply && replies && replies.length) {
  72. // const len = replies.length;
  73. // return (
  74. // <div style={{ marginLeft: 50 }}>
  75. // {replies.map((item, index) => {
  76. // if (index === len - 1) {
  77. // return [
  78. // <ContentItem
  79. // commentId={commentId}
  80. // replyId={item.id}
  81. // key={item.id}
  82. // content={item}
  83. // action="replyToReply" // 回复的回复
  84. // />,
  85. // <div className="comment-more-box" key="show_more_button">
  86. // {!isNoMoreReply && replyCount !== len && (
  87. // <span
  88. // className="comment-show-more"
  89. // onClick={() => this.handleGetMoreReply(commentId)}
  90. // >
  91. // {intl.get("reply.moreReply")}
  92. // </span>
  93. // )}
  94. // <a
  95. // style={{ float: "right" }}
  96. // onClick={this.handleToggleReply}
  97. // >
  98. // <Icon type="up" /> {intl.get("reply.collapse")}
  99. // </a>
  100. // </div>
  101. // ];
  102. // }
  103. // return (
  104. // <ContentItem
  105. // commentId={commentId}
  106. // replyId={item.id}
  107. // key={item.id}
  108. // content={item}
  109. // action="replyToReply" // 评论的回复
  110. // />
  111. // );
  112. // })}
  113. // </div>
  114. // );
  115. // }
  116. // return null;
  117. // }
  118. /**
  119. * 渲染回复 DOM
  120. * @param {array} replies 回复列表
  121. * @param {number} replyCount 回复的数量
  122. * @param {boolean} isNoMoreReply 是否没有更多回复
  123. */
  124. }, {
  125. key: "renderReplies",
  126. value: function renderReplies(replies, replyCount, isNoMoreReply) {
  127. var _this2 = this;
  128. var commentId = this.props.commentId;
  129. var showReply = this.state.showReply;
  130. if (showReply && replies && replies.length) {
  131. var len = replies.length;
  132. return _react2.default.createElement(
  133. "div",
  134. {
  135. style: {
  136. marginLeft: 50,
  137. borderTop: "1px solid #929292",
  138. paddingTop: 15,
  139. marginTop: 10,
  140. overflow: "auto"
  141. }
  142. },
  143. replies.map(function (item, index) {
  144. if (index === len - 1) {
  145. return [_react2.default.createElement(_ReplyItem2.default, {
  146. replyItem: item,
  147. key: item.id,
  148. commentId: commentId,
  149. action: "replyToReply"
  150. }), _react2.default.createElement(
  151. "div",
  152. { key: "show_more_button" },
  153. !isNoMoreReply && replyCount !== len && _react2.default.createElement(
  154. "span",
  155. {
  156. className: "comment-show-more",
  157. onClick: function onClick() {
  158. return _this2.handleGetMoreReply(commentId);
  159. }
  160. },
  161. "\u5C55\u5F00\u66F4\u591A\u8BC4\u8BBA",
  162. _react2.default.createElement(_icon2.default, { type: "down" })
  163. ),
  164. _react2.default.createElement(
  165. "a",
  166. {
  167. style: { float: "right", color: "#d5d5d5" },
  168. onClick: _this2.handleToggleReply
  169. },
  170. _react2.default.createElement(_icon2.default, { type: "up" }),
  171. " \u6536\u8D77"
  172. )
  173. )];
  174. }
  175. return _react2.default.createElement(_ReplyItem2.default, {
  176. replyItem: item,
  177. key: item.id,
  178. commentId: commentId,
  179. action: "replyToReply"
  180. });
  181. })
  182. );
  183. }
  184. }
  185. }, {
  186. key: "render",
  187. value: function render() {
  188. var content = this.props.content;
  189. var showReply = this.state.showReply;
  190. return _react2.default.createElement(
  191. "div",
  192. null,
  193. _react2.default.createElement(_ContentItem2.default, {
  194. content: content,
  195. onShowReply: this.handleToggleReply,
  196. showReply: showReply,
  197. commentId: content.id,
  198. action: "reply" // 评论的回复
  199. }),
  200. this.renderReplies(content.replies, content.reply_count, content.isNoMoreReply)
  201. );
  202. }
  203. }]);
  204. return CommentBox;
  205. }(_react.Component);
  206. CommentBox.propTypes = {
  207. commentId: _propTypes2.default.string.isRequired
  208. };
  209. CommentBox.defaultProps = {};
  210. exports.default = (0, _Comment2.default)(CommentBox);
  211. //# sourceMappingURL=index.js.map