通用评论

index.js 3.2KB

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