通用评论

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