通用评论

index.js 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. handleChangeFileList: function handleChangeFileList(fileList) {
  49. _this2.setState({
  50. fileList: fileList
  51. });
  52. }
  53. }))
  54. );
  55. }
  56. }]);
  57. return Index;
  58. }(_react2.default.Component);
  59. /**
  60. * 渲染评论组件
  61. * @param {object} config 编辑器配置
  62. * - {string} id 渲染评论的DOM的 ID
  63. * - {number} type 评论的 type
  64. * - {string} businessId 评论的 businessId
  65. * - {string} API, API 前缀, 默认 http://api.links123.net/comment/v1
  66. */
  67. function renderComment(config) {
  68. if (!config.id) {
  69. throw new Error("id is required");
  70. }
  71. if (!config.type) {
  72. throw new Error("type is required");
  73. }
  74. if (!config.businessId) {
  75. // throw new Error("businessId is required");
  76. config.businessId = "test";
  77. console.warn("没有传入 businessId 参数,默认使用: test");
  78. }
  79. if (!config.API) {
  80. // throw new Error("API is required");
  81. config.API = "http://api.links123.net/comment/v1";
  82. console.warn("没有传入 API 参数,默认使用: http://api.links123.net/comment/v1");
  83. }
  84. _reactDom2.default.render(_react2.default.createElement(Index, config), document.getElementById(config.id));
  85. // registerServiceWorker();
  86. }
  87. window.renderComment = renderComment;
  88. if (process.env.NODE_ENV !== "production") {
  89. renderComment({
  90. id: "root-comment",
  91. type: 1,
  92. businessId: "test",
  93. businessUserId: 4,
  94. userId: 71299,
  95. onCountChange: function onCountChange(c) {
  96. console.log(c);
  97. },
  98. editorProps: {
  99. // emojiPopoverPlacement: "bottom",
  100. // uploadPopoverPlacement: "top"
  101. }
  102. });
  103. }
  104. // renderComment({
  105. // id: "root-comment",
  106. // type: 1,
  107. // businessId: "test",
  108. // API: 'http://api.links123.net/comment/v1',
  109. // });
  110. //# sourceMappingURL=index.js.map