通用评论

index.js 1.6KB

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