通用评论

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. "use strict";
  2. 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; }; }();
  3. var _react = require("react");
  4. var _react2 = _interopRequireDefault(_react);
  5. var _reactDom = require("react-dom");
  6. var _reactDom2 = _interopRequireDefault(_reactDom);
  7. var _App = require("./App");
  8. var _App2 = _interopRequireDefault(_App);
  9. var _registerServiceWorker = require("./registerServiceWorker");
  10. var _registerServiceWorker2 = _interopRequireDefault(_registerServiceWorker);
  11. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  12. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  13. 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; }
  14. 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; }
  15. // e.g.
  16. // import { Button, Icon } from "antd";
  17. // import App, { Editor, RenderText } from "./App";
  18. var Index = function (_Component) {
  19. _inherits(Index, _Component);
  20. function Index(props) {
  21. _classCallCheck(this, Index);
  22. var _this = _possibleConstructorReturn(this, (Index.__proto__ || Object.getPrototypeOf(Index)).call(this, props));
  23. _this.state = {
  24. value: ""
  25. };
  26. _this.handleChangeValue = _this.handleChangeValue.bind(_this);
  27. _this.handleChangeSubmit = _this.handleChangeSubmit.bind(_this);
  28. return _this;
  29. }
  30. _createClass(Index, [{
  31. key: "handleChangeValue",
  32. value: function handleChangeValue(value) {
  33. this.setState({ value: value });
  34. console.log("handleChangeValue value: ", value);
  35. }
  36. }, {
  37. key: "handleChangeSubmit",
  38. value: function handleChangeSubmit(_ref) {
  39. var _this2 = this;
  40. var text = _ref.text,
  41. files = _ref.files;
  42. this.setState({ loading: true }, function () {
  43. setTimeout(function () {
  44. _this2.setState({ loading: false });
  45. }, 2000);
  46. });
  47. console.log("submit text: ", text);
  48. console.log("submit files: ", files);
  49. }
  50. }, {
  51. key: "render",
  52. value: function render() {
  53. // 最简单的用法
  54. return _react2.default.createElement(
  55. _App2.default,
  56. {
  57. type: 1,
  58. businessId: "test",
  59. showAlertComment: true,
  60. showAlertReply: true,
  61. showAlertFavor: true,
  62. showError: false,
  63. userId: 71299,
  64. pageType: "pagination",
  65. onError: function onError(msg, _ref2) {
  66. var response = _ref2.response;
  67. if (response.status === 401) {
  68. console.log("unlogined");
  69. }
  70. console.log("-----------" + msg);
  71. }
  72. },
  73. _react2.default.createElement(_App.Editor, {
  74. maxUpload: 4,
  75. autoFocus: true,
  76. beforeSubmit: function beforeSubmit() {
  77. return new Promise(function (resolve) {
  78. resolve(true);
  79. });
  80. },
  81. onCommentSuccess: function onCommentSuccess() {
  82. console.log("succ");
  83. },
  84. showError: false,
  85. onError: function onError(msg, _ref3) {
  86. var response = _ref3.response;
  87. if (response.status === 401) {
  88. console.log("unlogined");
  89. }
  90. console.log("-----------" + msg);
  91. }
  92. })
  93. );
  94. // e.g.
  95. // 复杂的用户法
  96. // const props = {
  97. // type: 1,
  98. // businessId: "1",
  99. // API: "http://api.links123.net/comment/v1",
  100. // showList: true
  101. // };
  102. // const editorProps = {
  103. // showEmoji: true,
  104. // placeholder: "说点什么吧",
  105. // rows: 5,
  106. // btnLoading: this.state.loading,
  107. // btnDisable: this.state.loading,
  108. // btnSubmitText: "提交",
  109. // value: this.state.value,
  110. // onChange: v => this.handleChangeValue(v),
  111. // onSubmit: v => this.handleChangeSubmit(v),
  112. // button: (
  113. // <Button
  114. // type="primary"
  115. // ghost
  116. // // onClick={() => console.log('click btn: ', this.state.value)}
  117. // >
  118. // 自定义按钮
  119. // </Button>
  120. // ),
  121. // emojiToolIcon: <Icon type="smile" style={{ fontSize: 23 }} />,
  122. // imageToolIcon: (
  123. // <Icon type="cloud-upload-o" style={{ fontSize: 25, marginLeft: 10 }} />
  124. // )
  125. // };
  126. // return (
  127. // <App {...props}>
  128. // <Editor {...editorProps} />
  129. // </App>
  130. // );
  131. }
  132. }]);
  133. return Index;
  134. }(_react.Component);
  135. _reactDom2.default.render(_react2.default.createElement(Index, null), document.getElementById("root-comment"));
  136. (0, _registerServiceWorker2.default)();
  137. //# sourceMappingURL=index.js.map