123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- import React from "react";
- import ReactDOM from "react-dom";
- import App, { Editor } from "./App";
- // import registerServiceWorker from "./registerServiceWorker";
-
- class Index extends React.Component {
- constructor(props) {
- super(props);
- this.state = {
- fileList: [
- {
- uid: "1",
- name: "xxx.png",
- status: "done",
- response: "success", // custom error message to show
- url:
- "//links-comment.oss-cn-beijing.aliyuncs.com/comment/20190617/UCs7aXEjW.jpeg"
- }
- ]
- };
- }
-
- render() {
- return (
- <App
- showAlertComment
- showAlertReply
- showAlertFavor
- showError
- {...this.props}
- >
- <Editor
- maxUpload={9}
- autoFocus
- {...this.props.editorProps}
- fileList={this.state.fileList}
- handleChangeFileList={fileList => {
- this.setState({
- fileList
- });
- }}
- />
- </App>
- );
- }
- }
-
- /**
- * 渲染评论组件
- * @param {object} config 编辑器配置
- * - {string} id 渲染评论的DOM的 ID
- * - {number} type 评论的 type
- * - {string} businessId 评论的 businessId
- * - {string} API, API 前缀, 默认 http://api.links123.net/comment/v1
- */
- function renderComment(config) {
- if (!config.id) {
- throw new Error("id is required");
- }
- if (!config.type) {
- throw new Error("type is required");
- }
- if (!config.businessId) {
- // throw new Error("businessId is required");
- config.businessId = "test";
- console.warn("没有传入 businessId 参数,默认使用: test");
- }
- if (!config.API) {
- // throw new Error("API is required");
- config.API = "http://api.links123.net/comment/v1";
- console.warn(
- "没有传入 API 参数,默认使用: http://api.links123.net/comment/v1"
- );
- }
-
- ReactDOM.render(<Index {...config} />, document.getElementById(config.id));
- // registerServiceWorker();
- }
-
- window.renderComment = renderComment;
-
- if (process.env.NODE_ENV !== "production") {
- renderComment({
- id: "root-comment",
- type: 1,
- businessId: "test",
- businessUserId: 4,
- userId: 71299,
- onCountChange: c => {
- console.log(c);
- },
- editorProps: {
- // emojiPopoverPlacement: "bottom",
- // uploadPopoverPlacement: "top"
- }
- });
- }
-
- // renderComment({
- // id: "root-comment",
- // type: 1,
- // businessId: "test",
- // API: 'http://api.links123.net/comment/v1',
- // });
|