通用评论

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. "use strict";
  2. var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
  3. 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; }; }();
  4. var _react = require("react");
  5. var _react2 = _interopRequireDefault(_react);
  6. var _reactDom = require("react-dom");
  7. var _reactDom2 = _interopRequireDefault(_reactDom);
  8. var _App = require("./App");
  9. var _App2 = _interopRequireDefault(_App);
  10. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  11. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  12. 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; }
  13. 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; }
  14. // import registerServiceWorker from "./registerServiceWorker";
  15. var Index = function (_React$Component) {
  16. _inherits(Index, _React$Component);
  17. function Index(props) {
  18. _classCallCheck(this, Index);
  19. var _this = _possibleConstructorReturn(this, (Index.__proto__ || Object.getPrototypeOf(Index)).call(this, props));
  20. _this.state = {
  21. fileList: []
  22. };
  23. return _this;
  24. }
  25. _createClass(Index, [{
  26. key: "render",
  27. value: function render() {
  28. var _this2 = this;
  29. return _react2.default.createElement(
  30. _App2.default,
  31. _extends({
  32. showAlertComment: true,
  33. showAlertReply: true,
  34. showAlertFavor: true,
  35. showError: true
  36. }, this.props),
  37. _react2.default.createElement(_App.Editor, _extends({
  38. maxUpload: 9,
  39. autoFocus: true
  40. }, this.props.editorProps, {
  41. fileList: this.state.fileList,
  42. handleChangeFileList: function handleChangeFileList(fileList) {
  43. _this2.setState({
  44. fileList: fileList
  45. });
  46. }
  47. }))
  48. );
  49. }
  50. }]);
  51. return Index;
  52. }(_react2.default.Component);
  53. /**
  54. * 渲染评论组件
  55. * @param {object} config 编辑器配置
  56. * - {string} id 渲染评论的DOM的 ID
  57. * - {number} type 评论的 type
  58. * - {string} businessId 评论的 businessId
  59. * - {string} API, API 前缀, 默认 http://api.links123.net/comment/v1
  60. */
  61. function renderComment(config) {
  62. if (!config.id) {
  63. throw new Error("id is required");
  64. }
  65. if (!config.type) {
  66. throw new Error("type is required");
  67. }
  68. if (!config.businessId) {
  69. // throw new Error("businessId is required");
  70. config.businessId = "test";
  71. console.warn("没有传入 businessId 参数,默认使用: test");
  72. }
  73. if (!config.API) {
  74. // throw new Error("API is required");
  75. config.API = "http://api.links123.net/comment/v1";
  76. console.warn("没有传入 API 参数,默认使用: http://api.links123.net/comment/v1");
  77. }
  78. _reactDom2.default.render(_react2.default.createElement(Index, config), document.getElementById(config.id));
  79. // registerServiceWorker();
  80. }
  81. window.renderComment = renderComment;
  82. if (process.env.NODE_ENV !== "production") {
  83. renderComment({
  84. id: "root-comment",
  85. type: 1,
  86. businessId: "test",
  87. businessUserId: 4,
  88. userId: 71299,
  89. onCountChange: function onCountChange(c) {
  90. console.log(c);
  91. },
  92. editorProps: {}
  93. });
  94. }
  95. // renderComment({
  96. // id: "root-comment",
  97. // type: 1,
  98. // businessId: "test",
  99. // API: 'http://api.links123.net/comment/v1',
  100. // });
  101. //# sourceMappingURL=index.js.map