通用评论

index.js 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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/css");
  11. require("antd/es/pagination/style/css");
  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. var _constant = require("../../constant");
  22. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  23. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  24. 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; }
  25. 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; }
  26. var CommentList = function (_Component) {
  27. _inherits(CommentList, _Component);
  28. function CommentList(props) {
  29. _classCallCheck(this, CommentList);
  30. var _this = _possibleConstructorReturn(this, (CommentList.__proto__ || Object.getPrototypeOf(CommentList)).call(this, props));
  31. _this.state = {};
  32. return _this;
  33. }
  34. _createClass(CommentList, [{
  35. key: "componentWillMount",
  36. value: function componentWillMount() {
  37. this.props.app.sGetComment({ page: this.props.app.page });
  38. }
  39. }, {
  40. key: "renderPagination",
  41. value: function renderPagination() {
  42. var _props$app = this.props.app,
  43. list = _props$app.list,
  44. total = _props$app.total,
  45. page = _props$app.page,
  46. pageType = _props$app.pageType,
  47. isNoMoreComment = _props$app.isNoMoreComment,
  48. sGetComment = _props$app.sGetComment,
  49. onPageChange = _props$app.onPageChange;
  50. if (pageType === "more") {
  51. if (!isNoMoreComment && list.length !== total) {
  52. return _react2.default.createElement(
  53. "div",
  54. {
  55. className: "comment-list-show-more",
  56. onClick: function onClick() {
  57. sGetComment({ page: page + 1 });
  58. onPageChange(page + 1);
  59. }
  60. },
  61. _react2.default.createElement(
  62. "span",
  63. null,
  64. _reactIntlUniversal2.default.get("comment.moreComment")
  65. )
  66. );
  67. } else {
  68. return null;
  69. }
  70. } else if (pageType === "pagination") {
  71. return _react2.default.createElement(
  72. "div",
  73. { className: "comment-list-pagination" },
  74. _react2.default.createElement(_pagination2.default, {
  75. pageSize: _constant.LIMIT,
  76. current: page,
  77. total: total,
  78. onChange: function onChange(p) {
  79. sGetComment({ page: p });
  80. onPageChange(p);
  81. }
  82. })
  83. );
  84. }
  85. }
  86. }, {
  87. key: "render",
  88. value: function render() {
  89. var _props$app2 = this.props.app,
  90. list = _props$app2.list,
  91. total = _props$app2.total,
  92. loading = _props$app2.loading;
  93. var spinning = Boolean(loading.sGetComment || loading.sCommentFavor || loading.sReplyFavor);
  94. return _react2.default.createElement(
  95. "div",
  96. null,
  97. _react2.default.createElement(
  98. _spin2.default,
  99. { spinning: spinning },
  100. _react2.default.createElement(
  101. "div",
  102. null,
  103. _reactIntlUniversal2.default.get("comment.totalComment", { total: total })
  104. ),
  105. list.map(function (item) {
  106. return _react2.default.createElement(_CommentBox2.default, { content: item, key: item.id, commentId: item.id });
  107. }),
  108. this.renderPagination()
  109. )
  110. );
  111. }
  112. }]);
  113. return CommentList;
  114. }(_react.Component);
  115. CommentList.propTypes = {};
  116. exports.default = (0, _Comment2.default)(CommentList);
  117. //# sourceMappingURL=index.js.map