通用评论

index.js 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import React, { Component } from "react";
  2. import ReactDOM from "react-dom";
  3. import { Button, Icon } 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. emojiToolIcon: <Icon type="smile" style={{ fontSize: 23 }} />,
  54. imageToolIcon: (
  55. <Icon type="cloud-upload-o" style={{ fontSize: 25, marginLeft: 10 }} />
  56. )
  57. };
  58. return (
  59. <App {...props}>
  60. <Editor {...editorProps} />
  61. </App>
  62. );
  63. }
  64. }
  65. ReactDOM.render(<Index />, document.getElementById("root-comment"));
  66. registerServiceWorker();