通用评论

index.js 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import React from "react";
  2. import ReactDOM from "react-dom";
  3. import App, { Editor } from "./App";
  4. // import registerServiceWorker from "./registerServiceWorker";
  5. const Index = props => (
  6. <App showAlertComment showAlertReply showAlertFavor showError {...props}>
  7. <Editor maxUpload={9} autoFocus {...props.editorProps} />
  8. </App>
  9. );
  10. /**
  11. * 渲染评论组件
  12. * @param {object} config 编辑器配置
  13. * - {string} id 渲染评论的DOM的 ID
  14. * - {number} type 评论的 type
  15. * - {string} businessId 评论的 businessId
  16. * - {string} API, API 前缀, 默认 http://api.links123.net/comment/v1
  17. */
  18. function renderComment(config) {
  19. if (!config.id) {
  20. throw new Error("id is required");
  21. }
  22. if (!config.type) {
  23. throw new Error("type is required");
  24. }
  25. if (!config.businessId) {
  26. // throw new Error("businessId is required");
  27. config.businessId = "test";
  28. console.warn("没有传入 businessId 参数,默认使用: test");
  29. }
  30. if (!config.API) {
  31. // throw new Error("API is required");
  32. config.API = "http://api.links123.net/comment/v1";
  33. console.warn(
  34. "没有传入 API 参数,默认使用: http://api.links123.net/comment/v1"
  35. );
  36. }
  37. ReactDOM.render(<Index {...config} />, document.getElementById(config.id));
  38. // registerServiceWorker();
  39. }
  40. window.renderComment = renderComment;
  41. if (process.env.NODE_ENV !== "production") {
  42. renderComment({
  43. id: "root-comment",
  44. type: 1,
  45. businessId: "test",
  46. businessUserId: 4,
  47. userId: 71299,
  48. onCountChange: c => {
  49. console.log(c);
  50. }
  51. });
  52. }
  53. // renderComment({
  54. // id: "root-comment",
  55. // type: 1,
  56. // businessId: "test",
  57. // API: 'http://api.links123.net/comment/v1',
  58. // });