通用评论

index.js 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import React, { Component } from "react";
  2. import ReactDOM from "react-dom";
  3. import { Button } from "antd";
  4. import App, { Editor } from "./App";
  5. import registerServiceWorker from "./registerServiceWorker";
  6. class Index extends Component {
  7. constructor(props) {
  8. super(props);
  9. this.state = {
  10. value: ""
  11. };
  12. this.handleChangeValue = this.handleChangeValue.bind(this);
  13. this.handleChangeSubmit = this.handleChangeSubmit.bind(this);
  14. }
  15. handleChangeValue(value) {
  16. this.setState({ value });
  17. console.log("handleChangeValue value: ", value);
  18. }
  19. handleChangeSubmit(value) {
  20. this.setState({ loading: true }, () => {
  21. setTimeout(() => {
  22. this.setState({ loading: false });
  23. }, 2000);
  24. });
  25. console.log("submit value: ", value);
  26. }
  27. render() {
  28. const props = {
  29. type: 1,
  30. businessId: "1",
  31. API: "http://api.links123.net/comment/v1",
  32. showList: true
  33. };
  34. const editorProps = {
  35. showEmoji: true,
  36. placeholder: "说点什么吧",
  37. rows: 5,
  38. btnLoading: this.state.loading,
  39. btnDisable: this.state.loading,
  40. btnSubmitText: "提交",
  41. value: this.state.value,
  42. onChange: v => this.handleChangeValue(v),
  43. onSubmit: v => this.handleChangeSubmit(v),
  44. button: (
  45. <Button
  46. type="primary"
  47. ghost
  48. onClick={() => console.log("click btn: ", this.state.value)}
  49. >
  50. 自定义按钮
  51. </Button>
  52. )
  53. };
  54. return (
  55. <App {...props}>
  56. <Editor {...editorProps} />
  57. </App>
  58. );
  59. }
  60. }
  61. ReactDOM.render(<Index />, document.getElementById("root-comment"));
  62. registerServiceWorker();