通用评论

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