通用评论

index.js 5.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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 _pagination = require("antd/es/pagination");
  8. var _pagination2 = _interopRequireDefault(_pagination);
  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/spin/style");
  11. require("antd/es/pagination/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 _Comment = require("../../Comment");
  17. var _Comment2 = _interopRequireDefault(_Comment);
  18. var _CommentBox = require("../CommentBox");
  19. var _CommentBox2 = _interopRequireDefault(_CommentBox);
  20. require("./index.css");
  21. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  22. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  23. 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; }
  24. 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; }
  25. var CommentList = function (_Component) {
  26. _inherits(CommentList, _Component);
  27. function CommentList(props) {
  28. _classCallCheck(this, CommentList);
  29. var _this = _possibleConstructorReturn(this, (CommentList.__proto__ || Object.getPrototypeOf(CommentList)).call(this, props));
  30. _this.state = {};
  31. return _this;
  32. }
  33. _createClass(CommentList, [{
  34. key: "componentWillMount",
  35. value: function componentWillMount() {
  36. this.props.app.sGetComment({ page: this.props.app.page });
  37. }
  38. }, {
  39. key: "renderPagination",
  40. value: function renderPagination() {
  41. var _props$app = this.props.app,
  42. list = _props$app.list,
  43. total = _props$app.total,
  44. page = _props$app.page,
  45. pageType = _props$app.pageType,
  46. limit = _props$app.limit,
  47. isNoMoreComment = _props$app.isNoMoreComment,
  48. sGetComment = _props$app.sGetComment,
  49. onPageChange = _props$app.onPageChange,
  50. onGetMoreBtnClick = _props$app.onGetMoreBtnClick;
  51. if (pageType === "slice") {
  52. // 截断多余评论,通过点击查看更多跳转
  53. return _react2.default.createElement(
  54. "div",
  55. { className: "comment-list-show-more", onClick: onGetMoreBtnClick },
  56. _react2.default.createElement(
  57. "span",
  58. null,
  59. "\u67E5\u770B\u66F4\u591A"
  60. )
  61. );
  62. } else if (pageType === "more") {
  63. if (!isNoMoreComment && list.length !== total) {
  64. return _react2.default.createElement(
  65. "div",
  66. {
  67. className: "comment-list-show-more",
  68. onClick: function onClick() {
  69. sGetComment({ page: page + 1 });
  70. onPageChange(page + 1);
  71. }
  72. },
  73. _react2.default.createElement(
  74. "span",
  75. null,
  76. _reactIntlUniversal2.default.get("comment.moreComment")
  77. )
  78. );
  79. } else {
  80. return null;
  81. }
  82. } else if (pageType === "pagination") {
  83. return _react2.default.createElement(
  84. "div",
  85. { className: "comment-list-pagination" },
  86. _react2.default.createElement(_pagination2.default, {
  87. pageSize: limit,
  88. current: page,
  89. total: total,
  90. onChange: function onChange(p) {
  91. sGetComment({ page: p });
  92. onPageChange(p);
  93. }
  94. })
  95. );
  96. }
  97. }
  98. }, {
  99. key: "render",
  100. value: function render() {
  101. var _props$app2 = this.props.app,
  102. list = _props$app2.list,
  103. total = _props$app2.total,
  104. loading = _props$app2.loading;
  105. var spinning = Boolean(loading.sGetComment || loading.sCommentFavor || loading.sReplyFavor);
  106. return _react2.default.createElement(
  107. "div",
  108. null,
  109. _react2.default.createElement(
  110. _spin2.default,
  111. { spinning: spinning },
  112. _react2.default.createElement(
  113. "div",
  114. null,
  115. _reactIntlUniversal2.default.get("comment.totalComment", { total: total })
  116. ),
  117. list.map(function (item) {
  118. return _react2.default.createElement(_CommentBox2.default, {
  119. content: item,
  120. user_id: item.user_id,
  121. key: item.id,
  122. commentId: item.id
  123. });
  124. }),
  125. this.renderPagination()
  126. )
  127. );
  128. }
  129. }]);
  130. return CommentList;
  131. }(_react.Component);
  132. CommentList.propTypes = {};
  133. exports.default = (0, _Comment2.default)(CommentList);
  134. //# sourceMappingURL=index.js.map