通用评论

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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: 71748,
  89. currentUser: {
  90. user_id: 71748
  91. },
  92. userAvaHoverData: {
  93. 71763: {
  94. nickname: "aaa",
  95. followers: 20,
  96. fans: 2,
  97. isFollowed: true
  98. },
  99. 71748: {
  100. nickname: "L0",
  101. followers: 10,
  102. fans: 11,
  103. isFollowed: false
  104. },
  105. 71299: {
  106. nickname: "narro",
  107. followers: 10,
  108. fans: 11,
  109. isFollowed: false
  110. }
  111. },
  112. showHoverCard: true,
  113. userAvaClick: function userAvaClick(id) {
  114. console.log("userAvaClick", id);
  115. },
  116. getUserInfo: function getUserInfo(id) {
  117. console.log("getinfo:", id);
  118. },
  119. focus: function focus(id) {
  120. return new Promise(function (resolve, reject) {
  121. console.log("focus:", id);
  122. resolve();
  123. });
  124. },
  125. unFocus: function unFocus(id) {
  126. return new Promise(function (resolve, reject) {
  127. console.log("unFocus:", id);
  128. resolve();
  129. });
  130. },
  131. onCountChange: function onCountChange(c) {
  132. console.log(c);
  133. },
  134. onDelete: function onDelete(type, data) {
  135. console.log(type, data);
  136. },
  137. editorProps: {
  138. onCommentSuccess: function onCommentSuccess(data) {
  139. console.log(data);
  140. }
  141. }
  142. });
  143. }
  144. // renderComment({
  145. // id: "root-comment",
  146. // type: 1,
  147. // businessId: "test",
  148. // API: 'http://api.links123.net/comment/v1',
  149. // });
  150. //# sourceMappingURL=index.js.map