通用评论

index.js 6.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. var _spin = require("antd/es/spin");
  6. var _spin2 = _interopRequireDefault(_spin);
  7. var _checkbox = require("antd/es/checkbox");
  8. var _checkbox2 = _interopRequireDefault(_checkbox);
  9. var _pagination = require("antd/es/pagination");
  10. var _pagination2 = _interopRequireDefault(_pagination);
  11. 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; }; }();
  12. require("antd/es/spin/style");
  13. require("antd/es/checkbox/style");
  14. require("antd/es/pagination/style");
  15. var _react = require("react");
  16. var _react2 = _interopRequireDefault(_react);
  17. var _reactIntlUniversal = require("react-intl-universal");
  18. var _reactIntlUniversal2 = _interopRequireDefault(_reactIntlUniversal);
  19. var _Comment = require("../../Comment");
  20. var _Comment2 = _interopRequireDefault(_Comment);
  21. var _CommentBox = require("../CommentBox");
  22. var _CommentBox2 = _interopRequireDefault(_CommentBox);
  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 CommentList = function (_Component) {
  29. _inherits(CommentList, _Component);
  30. function CommentList(props) {
  31. _classCallCheck(this, CommentList);
  32. var _this = _possibleConstructorReturn(this, (CommentList.__proto__ || Object.getPrototypeOf(CommentList)).call(this, props));
  33. _this.state = {
  34. filterSpeak: 0
  35. };
  36. return _this;
  37. }
  38. _createClass(CommentList, [{
  39. key: "componentWillMount",
  40. value: function componentWillMount() {
  41. this.props.app.sGetComment({ page: this.props.app.page });
  42. }
  43. }, {
  44. key: "renderPagination",
  45. value: function renderPagination() {
  46. var _props$app = this.props.app,
  47. list = _props$app.list,
  48. total = _props$app.total,
  49. page = _props$app.page,
  50. pageType = _props$app.pageType,
  51. limit = _props$app.limit,
  52. isNoMoreComment = _props$app.isNoMoreComment,
  53. sGetComment = _props$app.sGetComment,
  54. onPageChange = _props$app.onPageChange,
  55. onGetMoreBtnClick = _props$app.onGetMoreBtnClick;
  56. var filterSpeak = this.state.filterSpeak;
  57. if (pageType === "slice") {
  58. // 截断多余评论,通过点击查看更多跳转
  59. return _react2.default.createElement(
  60. "div",
  61. { className: "comment-list-show-more", onClick: onGetMoreBtnClick },
  62. _react2.default.createElement(
  63. "span",
  64. null,
  65. "\u67E5\u770B\u66F4\u591A"
  66. )
  67. );
  68. } else if (pageType === "more") {
  69. if (!isNoMoreComment && list.length !== total) {
  70. return _react2.default.createElement(
  71. "div",
  72. {
  73. className: "comment-list-show-more",
  74. onClick: function onClick() {
  75. sGetComment({ page: page + 1, filterSpeak: filterSpeak });
  76. onPageChange(page + 1);
  77. }
  78. },
  79. _react2.default.createElement(
  80. "span",
  81. null,
  82. _reactIntlUniversal2.default.get("comment.moreComment")
  83. )
  84. );
  85. } else {
  86. return null;
  87. }
  88. } else if (pageType === "pagination") {
  89. return _react2.default.createElement(
  90. "div",
  91. { className: "comment-list-pagination" },
  92. _react2.default.createElement(_pagination2.default, {
  93. pageSize: limit,
  94. current: page,
  95. total: total,
  96. onChange: function onChange(p) {
  97. sGetComment({ page: p, filterSpeak: filterSpeak });
  98. onPageChange(p);
  99. }
  100. })
  101. );
  102. }
  103. }
  104. }, {
  105. key: "render",
  106. value: function render() {
  107. var _this2 = this;
  108. var _props$app2 = this.props.app,
  109. list = _props$app2.list,
  110. total = _props$app2.total,
  111. loading = _props$app2.loading,
  112. isSpeak = _props$app2.isSpeak,
  113. sGetComment = _props$app2.sGetComment,
  114. onPageChange = _props$app2.onPageChange;
  115. var spinning = Boolean(loading.sGetComment || loading.sCommentFavor || loading.sReplyFavor);
  116. return _react2.default.createElement(
  117. "div",
  118. null,
  119. _react2.default.createElement(
  120. _spin2.default,
  121. { spinning: spinning },
  122. _react2.default.createElement(
  123. "div",
  124. null,
  125. _reactIntlUniversal2.default.get("comment.totalComment", { total: total }),
  126. isSpeak && _react2.default.createElement(
  127. _checkbox2.default,
  128. {
  129. className: "comment-list-filter-speak",
  130. onChange: function onChange(e) {
  131. _this2.setState({
  132. filterSpeak: e.target.checked ? 1 : 0
  133. });
  134. sGetComment({
  135. page: 1,
  136. filterSpeak: e.target.checked ? 1 : 0
  137. });
  138. onPageChange(1);
  139. }
  140. },
  141. _reactIntlUniversal2.default.get("comment.filterSpeak")
  142. )
  143. ),
  144. list.map(function (item) {
  145. return _react2.default.createElement(_CommentBox2.default, {
  146. content: item,
  147. user_id: item.user_id,
  148. key: item.id,
  149. commentId: item.id
  150. });
  151. }),
  152. this.renderPagination()
  153. )
  154. );
  155. }
  156. }]);
  157. return CommentList;
  158. }(_react.Component);
  159. CommentList.propTypes = {};
  160. exports.default = (0, _Comment2.default)(CommentList);
  161. //# sourceMappingURL=index.js.map