通用评论

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. uid: "1",
  23. name: "xxx.png",
  24. status: "done",
  25. response: "success", // custom error message to show
  26. url: "//links-comment.oss-cn-beijing.aliyuncs.com/comment/20190617/UCs7aXEjW.jpeg"
  27. }]
  28. };
  29. return _this;
  30. }
  31. _createClass(Index, [{
  32. key: "render",
  33. value: function render() {
  34. var _this2 = this;
  35. return _react2.default.createElement(
  36. _App2.default,
  37. _extends({
  38. showAlertComment: true,
  39. showAlertReply: true,
  40. showAlertFavor: true,
  41. showError: true
  42. }, this.props),
  43. _react2.default.createElement(_App.Editor, _extends({
  44. maxUpload: 9,
  45. autoFocus: true
  46. }, this.props.editorProps, {
  47. fileList: this.state.fileList,
  48. onSubmit: function onSubmit() {
  49. console.log('-----------');
  50. },
  51. handleChangeFileList: function handleChangeFileList(fileList) {
  52. _this2.setState({
  53. fileList: fileList
  54. });
  55. }
  56. }))
  57. );
  58. }
  59. }]);
  60. return Index;
  61. }(_react2.default.Component);
  62. /**
  63. * 渲染评论组件
  64. * @param {object} config 编辑器配置
  65. * - {string} id 渲染评论的DOM的 ID
  66. * - {number} type 评论的 type
  67. * - {string} businessId 评论的 businessId
  68. * - {string} API, API 前缀, 默认 http://api.links123.net/comment/v1
  69. */
  70. function renderComment(config) {
  71. if (!config.id) {
  72. throw new Error("id is required");
  73. }
  74. if (!config.type) {
  75. throw new Error("type is required");
  76. }
  77. if (!config.businessId) {
  78. // throw new Error("businessId is required");
  79. config.businessId = "test";
  80. console.warn("没有传入 businessId 参数,默认使用: test");
  81. }
  82. if (!config.API) {
  83. // throw new Error("API is required");
  84. config.API = "http://api.links123.net/comment/v1";
  85. console.warn("没有传入 API 参数,默认使用: http://api.links123.net/comment/v1");
  86. }
  87. _reactDom2.default.render(_react2.default.createElement(Index, config), document.getElementById(config.id));
  88. // registerServiceWorker();
  89. }
  90. window.renderComment = renderComment;
  91. if (process.env.NODE_ENV !== "production") {
  92. renderComment({
  93. id: "root-comment",
  94. type: 1,
  95. businessId: "test",
  96. businessUserId: 4,
  97. userId: 71299,
  98. onCountChange: function onCountChange(c) {
  99. console.log(c);
  100. },
  101. editorProps: {
  102. // emojiPopoverPlacement: "bottom",
  103. // uploadPopoverPlacement: "top"
  104. }
  105. });
  106. }
  107. // renderComment({
  108. // id: "root-comment",
  109. // type: 1,
  110. // businessId: "test",
  111. // API: 'http://api.links123.net/comment/v1',
  112. // });
  113. //# sourceMappingURL=index.js.map