通用评论

index.js 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. import React, { Component } from "react";
  2. import ReactDOM from "react-dom";
  3. // e.g.
  4. // import { Button, Icon } from "antd";
  5. // import App, { Editor, RenderText } from "./App";
  6. import App, { Editor } from "./App";
  7. import registerServiceWorker from "./registerServiceWorker";
  8. class Index extends Component {
  9. constructor(props) {
  10. super(props);
  11. this.state = {
  12. value: ""
  13. };
  14. this.handleChangeValue = this.handleChangeValue.bind(this);
  15. this.handleChangeSubmit = this.handleChangeSubmit.bind(this);
  16. }
  17. handleChangeValue(value) {
  18. this.setState({ value });
  19. console.log("handleChangeValue value: ", value);
  20. }
  21. handleChangeSubmit({ text, files }) {
  22. this.setState({ loading: true }, () => {
  23. setTimeout(() => {
  24. this.setState({ loading: false });
  25. }, 2000);
  26. });
  27. console.log("submit text: ", text);
  28. console.log("submit files: ", files);
  29. }
  30. render() {
  31. // 最简单的用法
  32. return (
  33. <App type={1} businessId="test">
  34. <Editor maxUpload={4} />
  35. </App>
  36. );
  37. // e.g.
  38. // 复杂的用户法
  39. // const props = {
  40. // type: 1,
  41. // businessId: "1",
  42. // API: "http://api.links123.net/comment/v1",
  43. // showList: true
  44. // };
  45. // const editorProps = {
  46. // showEmoji: true,
  47. // placeholder: "说点什么吧",
  48. // rows: 5,
  49. // btnLoading: this.state.loading,
  50. // btnDisable: this.state.loading,
  51. // btnSubmitText: "提交",
  52. // value: this.state.value,
  53. // onChange: v => this.handleChangeValue(v),
  54. // onSubmit: v => this.handleChangeSubmit(v),
  55. // button: (
  56. // <Button
  57. // type="primary"
  58. // ghost
  59. // // onClick={() => console.log('click btn: ', this.state.value)}
  60. // >
  61. // 自定义按钮
  62. // </Button>
  63. // ),
  64. // emojiToolIcon: <Icon type="smile" style={{ fontSize: 23 }} />,
  65. // imageToolIcon: (
  66. // <Icon type="cloud-upload-o" style={{ fontSize: 25, marginLeft: 10 }} />
  67. // )
  68. // };
  69. // return (
  70. // <App {...props}>
  71. // <Editor {...editorProps} />
  72. // </App>
  73. // );
  74. }
  75. }
  76. ReactDOM.render(<Index />, document.getElementById("root-comment"));
  77. registerServiceWorker();