通用评论

index.js 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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 _Comment = require("../../Comment");
  15. var _Comment2 = _interopRequireDefault(_Comment);
  16. var _CommentBox = require("../CommentBox");
  17. var _CommentBox2 = _interopRequireDefault(_CommentBox);
  18. require("./index.css");
  19. var _constant = require("../../constant");
  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 CommentList = function (_Component) {
  25. _inherits(CommentList, _Component);
  26. function CommentList(props) {
  27. _classCallCheck(this, CommentList);
  28. var _this = _possibleConstructorReturn(this, (CommentList.__proto__ || Object.getPrototypeOf(CommentList)).call(this, props));
  29. _this.state = {};
  30. return _this;
  31. }
  32. _createClass(CommentList, [{
  33. key: "componentWillMount",
  34. value: function componentWillMount() {
  35. this.props.app.sGetComment();
  36. }
  37. }, {
  38. key: "renderPagination",
  39. value: function renderPagination() {
  40. var _props$app = this.props.app,
  41. list = _props$app.list,
  42. total = _props$app.total,
  43. page = _props$app.page,
  44. pageType = _props$app.pageType,
  45. isNoMoreComment = _props$app.isNoMoreComment,
  46. sGetComment = _props$app.sGetComment;
  47. if (pageType === 'more') {
  48. if (!isNoMoreComment && list.length !== total) {
  49. return _react2.default.createElement(
  50. "div",
  51. {
  52. className: "comment-list-show-more",
  53. onClick: function onClick() {
  54. return sGetComment({ page: page + 1 });
  55. }
  56. },
  57. _react2.default.createElement(
  58. "span",
  59. null,
  60. "\u67E5\u770B\u66F4\u591A\u8BC4\u8BBA"
  61. )
  62. );
  63. } else {
  64. return null;
  65. }
  66. } else if (pageType === 'pagination') {
  67. return _react2.default.createElement(
  68. "div",
  69. { className: "comment-list-pagination" },
  70. _react2.default.createElement(_pagination2.default, {
  71. pageSize: _constant.LIMIT,
  72. current: page,
  73. total: total,
  74. onChange: function onChange(p) {
  75. sGetComment({ page: p });
  76. }
  77. })
  78. );
  79. }
  80. }
  81. }, {
  82. key: "render",
  83. value: function render() {
  84. var _props$app2 = this.props.app,
  85. list = _props$app2.list,
  86. total = _props$app2.total,
  87. loading = _props$app2.loading;
  88. var spinning = Boolean(loading.sGetComment || loading.sCommentFavor || loading.sReplyFavor);
  89. return _react2.default.createElement(
  90. "div",
  91. null,
  92. _react2.default.createElement(
  93. _spin2.default,
  94. { spinning: spinning },
  95. _react2.default.createElement(
  96. "div",
  97. null,
  98. "\u5171 ",
  99. total,
  100. " \u6761\u8BC4\u8BBA"
  101. ),
  102. list.map(function (item) {
  103. return _react2.default.createElement(_CommentBox2.default, { content: item, key: item.id, commentId: item.id });
  104. }),
  105. this.renderPagination()
  106. )
  107. );
  108. }
  109. }]);
  110. return CommentList;
  111. }(_react.Component);
  112. CommentList.propTypes = {};
  113. exports.default = (0, _Comment2.default)(CommentList);
  114. //# sourceMappingURL=index.js.map