通用评论 vedio

index.js 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. } = config;
  41. ReactDOM.render(
  42. <Index type={type} businessId={businessId} API={API} />,
  43. document.getElementById(id)
  44. );
  45. // registerServiceWorker();
  46. }
  47. window.renderComment = renderComment;
  48. // renderComment({
  49. // id: "root-comment",
  50. // type: 1,
  51. // businessId: "test",
  52. // API: 'http://api.links123.net/comment/v1',
  53. // });