通用评论

index.js 6.8KB

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