通用评论

index.js 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. import React from "react";
  2. import ReactDOM from "react-dom";
  3. import App, { Editor } from "./App";
  4. // import registerServiceWorker from "./registerServiceWorker";
  5. class Index extends React.Component {
  6. constructor(props) {
  7. super(props);
  8. this.state = {
  9. fileList: [
  10. {
  11. uid: "1",
  12. name: "xxx.png",
  13. status: "done",
  14. response: "success", // custom error message to show
  15. url:
  16. "//links-comment.oss-cn-beijing.aliyuncs.com/comment/20190617/UCs7aXEjW.jpeg"
  17. }
  18. ]
  19. };
  20. }
  21. render() {
  22. return (
  23. <App
  24. showAlertComment
  25. showAlertReply
  26. showAlertFavor
  27. showError
  28. {...this.props}
  29. >
  30. <Editor
  31. maxUpload={9}
  32. autoFocus
  33. {...this.props.editorProps}
  34. fileList={this.state.fileList}
  35. onSubmit={() => {
  36. console.log("-----------");
  37. }}
  38. handleChangeFileList={fileList => {
  39. this.setState({
  40. fileList
  41. });
  42. }}
  43. />
  44. </App>
  45. );
  46. }
  47. }
  48. /**
  49. * 渲染评论组件
  50. * @param {object} config 编辑器配置
  51. * - {string} id 渲染评论的DOM的 ID
  52. * - {number} type 评论的 type
  53. * - {string} businessId 评论的 businessId
  54. * - {string} API, API 前缀, 默认 http://api.links123.net/comment/v1
  55. */
  56. function renderComment(config) {
  57. if (!config.id) {
  58. throw new Error("id is required");
  59. }
  60. if (!config.type) {
  61. throw new Error("type is required");
  62. }
  63. if (!config.businessId) {
  64. // throw new Error("businessId is required");
  65. config.businessId = "test";
  66. console.warn("没有传入 businessId 参数,默认使用: test");
  67. }
  68. if (!config.API) {
  69. // throw new Error("API is required");
  70. config.API = "http://api.links123.net/comment/v1";
  71. console.warn(
  72. "没有传入 API 参数,默认使用: http://api.links123.net/comment/v1"
  73. );
  74. }
  75. ReactDOM.render(<Index {...config} />, document.getElementById(config.id));
  76. // registerServiceWorker();
  77. }
  78. window.renderComment = renderComment;
  79. if (process.env.NODE_ENV !== "production") {
  80. renderComment({
  81. id: "root-comment",
  82. type: 1,
  83. businessId: "test",
  84. businessUserId: 4,
  85. userId: 71299,
  86. onCountChange: c => {
  87. console.log(c);
  88. },
  89. editorProps: {
  90. // emojiPopoverPlacement: "bottom",
  91. // uploadPopoverPlacement: "top"
  92. }
  93. });
  94. }
  95. // renderComment({
  96. // id: "root-comment",
  97. // type: 1,
  98. // businessId: "test",
  99. // API: 'http://api.links123.net/comment/v1',
  100. // });