通用评论

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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. value: ""
  23. };
  24. return _this;
  25. }
  26. _createClass(Index, [{
  27. key: "render",
  28. value: function render() {
  29. var _this2 = this;
  30. return _react2.default.createElement(
  31. _App2.default,
  32. _extends({
  33. showAlertComment: true,
  34. showAlertReply: true,
  35. showAlertFavor: true,
  36. showError: true
  37. }, this.props),
  38. _react2.default.createElement(_App.Editor, _extends({
  39. maxUpload: 9,
  40. autoFocus: true
  41. }, this.props.editorProps, {
  42. fileList: this.state.fileList,
  43. value: this.state.value,
  44. onChange: function onChange(value) {
  45. _this2.setState({
  46. value: value
  47. });
  48. },
  49. handleChangeFileList: function handleChangeFileList(fileList) {
  50. console.log(fileList);
  51. _this2.setState({
  52. fileList: fileList
  53. });
  54. }
  55. }))
  56. );
  57. }
  58. }]);
  59. return Index;
  60. }(_react2.default.Component);
  61. /**
  62. * 渲染评论组件
  63. * @param {object} config 编辑器配置
  64. * - {string} id 渲染评论的DOM的 ID
  65. * - {number} type 评论的 type
  66. * - {string} businessId 评论的 businessId
  67. * - {string} API, API 前缀, 默认 http://api.links123.net/comment/v1
  68. */
  69. function renderComment(config) {
  70. if (!config.id) {
  71. throw new Error("id is required");
  72. }
  73. if (!config.type) {
  74. throw new Error("type is required");
  75. }
  76. if (!config.businessId) {
  77. // throw new Error("businessId is required");
  78. config.businessId = "test";
  79. console.warn("没有传入 businessId 参数,默认使用: test");
  80. }
  81. if (!config.API) {
  82. // throw new Error("API is required");
  83. config.API = "http://api.links123.net/comment/v1";
  84. console.warn("没有传入 API 参数,默认使用: http://api.links123.net/comment/v1");
  85. }
  86. _reactDom2.default.render(_react2.default.createElement(Index, config), document.getElementById(config.id));
  87. // registerServiceWorker();
  88. }
  89. window.renderComment = renderComment;
  90. if (process.env.NODE_ENV !== "production") {
  91. renderComment({
  92. id: "root-comment",
  93. type: 1,
  94. businessId: "test",
  95. businessUserId: 4,
  96. userId: 71748,
  97. currentUser: {
  98. user_id: 71748
  99. },
  100. userAvaHoverData: {
  101. 71763: {
  102. nickname: "aaa",
  103. followers: 20,
  104. fans: 2,
  105. isFollowed: true
  106. },
  107. 71748: {
  108. nickname: "L0",
  109. followers: 10,
  110. fans: 11,
  111. isFollowed: false
  112. },
  113. 71299: {
  114. nickname: "narro",
  115. followers: 10,
  116. fans: 11,
  117. isFollowed: false
  118. }
  119. },
  120. showHoverCard: true,
  121. showEdit: true,
  122. userAvaClick: function userAvaClick(id) {
  123. console.log("userAvaClick", id);
  124. },
  125. getUserInfo: function getUserInfo(id) {
  126. console.log("getinfo:", id);
  127. },
  128. focus: function focus(id) {
  129. return new Promise(function (resolve, reject) {
  130. console.log("focus:", id);
  131. resolve();
  132. });
  133. },
  134. unFocus: function unFocus(id) {
  135. return new Promise(function (resolve, reject) {
  136. console.log("unFocus:", id);
  137. resolve();
  138. });
  139. },
  140. onCountChange: function onCountChange(c) {
  141. console.log(c);
  142. },
  143. onDelete: function onDelete(type, data) {
  144. console.log(type, data);
  145. },
  146. onUpdateComment: function onUpdateComment(type, data) {
  147. console.log("onUpdateComment", type);
  148. },
  149. onBeforeUpdateComment: function onBeforeUpdateComment() {
  150. console.log("onBeforeUpdateComment");
  151. },
  152. editorProps: {
  153. onCommentSuccess: function onCommentSuccess(data) {
  154. console.log(data);
  155. }
  156. }
  157. });
  158. }
  159. // renderComment({
  160. // id: "root-comment",
  161. // type: 1,
  162. // businessId: "test",
  163. // API: 'http://api.links123.net/comment/v1',
  164. // });
  165. //# sourceMappingURL=index.js.map