通用评论

index.js 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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
  34. type={1}
  35. businessId="test"
  36. showAlertComment
  37. showAlertReply
  38. showAlertFavor
  39. showError={false}
  40. userId={71299}
  41. onError={(msg, { response }) => {
  42. if (response.status === 401) {
  43. console.log("unlogined");
  44. }
  45. console.log(`-----------${msg}`);
  46. }}
  47. >
  48. <Editor
  49. maxUpload={4}
  50. autoFocus
  51. beforeSubmit={() => {
  52. return new Promise(resolve => {
  53. resolve(true);
  54. });
  55. }}
  56. onCommentSuccess={() => {
  57. console.log("succ");
  58. }}
  59. showError={false}
  60. onError={(msg, { response }) => {
  61. if (response.status === 401) {
  62. console.log("unlogined");
  63. }
  64. console.log(`-----------${msg}`);
  65. }}
  66. />
  67. </App>
  68. );
  69. // e.g.
  70. // 复杂的用户法
  71. // const props = {
  72. // type: 1,
  73. // businessId: "1",
  74. // API: "http://api.links123.net/comment/v1",
  75. // showList: true
  76. // };
  77. // const editorProps = {
  78. // showEmoji: true,
  79. // placeholder: "说点什么吧",
  80. // rows: 5,
  81. // btnLoading: this.state.loading,
  82. // btnDisable: this.state.loading,
  83. // btnSubmitText: "提交",
  84. // value: this.state.value,
  85. // onChange: v => this.handleChangeValue(v),
  86. // onSubmit: v => this.handleChangeSubmit(v),
  87. // button: (
  88. // <Button
  89. // type="primary"
  90. // ghost
  91. // // onClick={() => console.log('click btn: ', this.state.value)}
  92. // >
  93. // 自定义按钮
  94. // </Button>
  95. // ),
  96. // emojiToolIcon: <Icon type="smile" style={{ fontSize: 23 }} />,
  97. // imageToolIcon: (
  98. // <Icon type="cloud-upload-o" style={{ fontSize: 25, marginLeft: 10 }} />
  99. // )
  100. // };
  101. // return (
  102. // <App {...props}>
  103. // <Editor {...editorProps} />
  104. // </App>
  105. // );
  106. }
  107. }
  108. ReactDOM.render(<Index />, document.getElementById("root-comment"));
  109. registerServiceWorker();