通用评论

index.example.js 3.3KB

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