通用评论 vedio

index.js 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 />
  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. console.warn("没有传入 businessId 参数,默认使用: test");
  28. }
  29. if (!config.API) {
  30. // throw new Error("API is required");
  31. console.warn(
  32. "没有传入 API 参数,默认使用: http://api.links123.net/comment/v1"
  33. );
  34. }
  35. const {
  36. id,
  37. type = 1,
  38. businessId = "test",
  39. API = "http://api.links123.net/comment/v1",
  40. userId
  41. } = config;
  42. ReactDOM.render(
  43. <Index type={type} businessId={businessId} API={API} userId={userId} />,
  44. document.getElementById(id)
  45. );
  46. // registerServiceWorker();
  47. }
  48. window.renderComment = renderComment;
  49. // renderComment({
  50. // id: "root-comment",
  51. // type: 1,
  52. // businessId: "test"
  53. // });
  54. // renderComment({
  55. // id: "root-comment",
  56. // type: 1,
  57. // businessId: "test",
  58. // API: 'http://api.links123.net/comment/v1',
  59. // });