Bladeren bron

feat: 常规优化

node 6 jaren geleden
bovenliggende
commit
9ce1999dfd

+ 16
- 21
README.md Bestand weergeven

@@ -132,7 +132,7 @@ import Comment, { Editor } from 'comment'
132 132
 
133 133
 render() {
134 134
   return (
135
-    <Comment>
135
+    <Comment type={1} businessId="test">
136 136
       <Editor />
137 137
     </Comment>
138 138
   )
@@ -144,27 +144,12 @@ render() {
144 144
 
145 145
 ### 作为静态文件引入
146 146
 
147
-作为静态问卷使用的话,首先需要在 `index.js` 里面设置好组件的 `props`:
147
+作为静态问卷使用的话,首先需要在 `index.js` 里面设置好组件的 `props`,主要是 `type` 和 `businessId`
148 148
 
149 149
 ```js
150 150
 // ...
151
-const props = {
152
-  type: 1,
153
-  businessId: "1",
154
-  API: "http://api.links123.net/comment/v1",
155
-  showList: true
156
-};
157
-
158
-const editorProps = {
159
-  showEmoji: true,
160
-  placeholder: "说点什么吧",
161
-  rows: 5,
162
-};
163
-
164
-
165
-// ...
166
-<App {...props}>
167
-    <Editor {...editorProps} />
151
+<App type={1} businessId="test">
152
+    <Editor />
168 153
 </App>
169 154
 ```
170 155
 
@@ -174,10 +159,10 @@ const editorProps = {
174 159
 $ yarn build
175 160
 ```
176 161
 
177
-打包后会得到静态问卷,分别通过 link 和 script 标签在你的项目里面引入打包后的文件。
162
+打包后会得到静态文件,分别通过 link 和 script 标签在你的项目里面引入打包后的文件。
178 163
 
179 164
 
180
-然后还需要引入 OSS SDK,用于直传文件到 OSS。
165
+接下来还需要引入 OSS SDK,用于直传文件到 OSS。
181 166
 
182 167
 
183 168
 最后创建一个 id 为 `root-comment` 的标签,作为渲染通用评论的跟元素。
@@ -214,3 +199,13 @@ $ yarn start
214 199
 - `yarn build` 将项目打包成一个单页应用
215 200
 - `yarn lib` 将项目打包成一个 es5 组件
216 201
 - `yarn prettier` 格式化代码
202
+
203
+## TODO
204
+
205
+- [x] 前后端统一错误码
206
+- [x] type 和 businessID 的定义
207
+- [x] Editor onSubmit 回调
208
+- [ ] 对评论的回复点赞,报错
209
+- [ ] oss/sts 接口报错
210
+- [ ] 头像 404 `https://links123-images.oss-cn-hangzhou.aliyuncs.com/avatar/`
211
+

+ 3
- 3
src/App.js Bestand weergeven

@@ -103,7 +103,6 @@ class App extends Component {
103 103
     axios
104 104
       .get(`${API}/replies?comment_id=${commentId}&page=${page}&limit=${LIMIT}`)
105 105
       .then(response => {
106
-        // const { list: replies, total, page } = response.data;
107 106
         if (!response.data.list) {
108 107
           message.info("没有更多数据了!");
109 108
         }
@@ -167,12 +166,12 @@ class App extends Component {
167 166
         // 将数据写入到 list 中
168 167
         // 临时插入
169 168
         // 等到获取数据之后,删除临时数据
170
-        const { list } = this.state;
169
+        const { list, total } = this.state;
171 170
         list.unshift({
172 171
           ...response.data,
173 172
           isTemporary: true // 临时的数据
174 173
         });
175
-        this.setState({ list });
174
+        this.setState({ list, total: total + 1 });
176 175
       })
177 176
       .catch(error => {
178 177
         if (error.response && error.response.data && error.response.data.msg) {
@@ -288,6 +287,7 @@ class App extends Component {
288 287
         console.log("response: ", response);
289 288
 
290 289
         message.success(favored ? "取消点赞成功!" : "点赞成功!");
290
+        // TODO: (2018.07.20 node) 对评论的回复点赞,报错
291 291
         // // 更新 list 中的该项数据的 favored
292 292
         // const list = this.state.list.map(item => {
293 293
         //   if (item.id === replyId) {

+ 0
- 143
src/components/CommentInput.1/index.js Bestand weergeven

@@ -1,143 +0,0 @@
1
-import React, { Component } from "react";
2
-import PropTypes from "prop-types";
3
-import { OSS_LINK } from "../../constant";
4
-import Comment from "../../Comment";
5
-
6
-class CommentInput extends Component {
7
-  constructor(props) {
8
-    super(props);
9
-    this.state = {
10
-      value: "",
11
-
12
-      fileList: [], // 图片列表
13
-      fileMap: {} // 已经上传的图片路径和 uid 的映射 { uid: path }
14
-    };
15
-    this.handleChange = this.handleChange.bind(this);
16
-    this.handleSubmit = this.handleSubmit.bind(this);
17
-    this.handleChangeFileList = this.handleChangeFileList.bind(this);
18
-    this.handleChangeEmoji = this.handleChangeEmoji.bind(this);
19
-    this.handleUpload = this.handleUpload.bind(this);
20
-  }
21
-
22
-  handleChange(value) {
23
-    this.setState({ value });
24
-  }
25
-
26
-  handleChangeFileList(fileList) {
27
-    this.setState({ fileList });
28
-  }
29
-
30
-  handleChangeEmoji(emojiId) {
31
-    let { value } = this.state;
32
-    value += `[${emojiId}]`;
33
-    this.setState({ value });
34
-    React.Children.forEach(this.props.content, child => {
35
-      // 如果 Editor 的父组件传入了 onChange 事件,则需要将改变之后的值传递给父组件
36
-      if (child.props.onChange) {
37
-        child.props.onChange(value);
38
-      }
39
-    });
40
-  }
41
-
42
-  handleUpload({ uid, path }) {
43
-    const { fileMap } = this.state;
44
-    fileMap[uid] = path;
45
-    this.setState({ fileMap });
46
-  }
47
-
48
-  handleSubmit() {
49
-    let { value, fileMap, fileList } = this.state;
50
-    if (fileList.length) {
51
-      value += "<br/>";
52
-      fileList.forEach(item => {
53
-        value += `[${OSS_LINK}${fileMap[item.uid]}]`;
54
-      });
55
-    }
56
-
57
-    const { type, commentId, replyId, handleToggleInput } = this.props;
58
-    if (type === "normal") {
59
-      this.props.app.sCreateComment({
60
-        content: value
61
-      });
62
-    } else if (type === "comment") {
63
-      this.props.app.sCreateReply(
64
-        {
65
-          comment_id: commentId,
66
-          content: value
67
-        },
68
-        () => handleToggleInput()
69
-      );
70
-    } else if (type === "reply") {
71
-      this.props.app.sCreateReply(
72
-        {
73
-          comment_id: commentId,
74
-          content: value,
75
-          reply_id: replyId
76
-        },
77
-        () => handleToggleInput()
78
-      );
79
-    }
80
-
81
-    React.Children.forEach(this.props.content, child => {
82
-      // 如果 Editor 的父组件传入了 onSubmit 事件,则需要将改变之后的值传递给父组件
83
-      if (child.props.onSubmit) {
84
-        child.props.onSubmit(value);
85
-      }
86
-    });
87
-  }
88
-
89
-  render() {
90
-    const { type } = this.props;
91
-    const { value, fileList } = this.state;
92
-
93
-    const childrenWithProps = React.Children.map(this.props.content, child => {
94
-      return React.cloneElement(child, {
95
-        value: value,
96
-        fileList: fileList,
97
-        onChange: this.handleChange,
98
-        onSubmit: this.handleSubmit,
99
-        onChangeFileList: this.handleChangeFileList,
100
-        onChangeEmoji: this.handleChangeEmoji,
101
-        onUpload: this.handleUpload,
102
-        loading: this.props.app.loading.sCreateComment,
103
-        ...child.props
104
-      });
105
-    });
106
-
107
-    return (
108
-      <div>
109
-        {type === "normal" ? (
110
-          <div>
111
-            <span
112
-              style={{
113
-                border: "1px solid #CECECE",
114
-                color: "#666",
115
-                padding: "2px 3px"
116
-              }}
117
-            >
118
-              回复
119
-            </span>
120
-            <span style={{ marginLeft: "20px", color: "#5198EB" }}>
121
-              口碑
122
-              <span style={{ marginLeft: "20px", color: "#666666" }}>
123
-                (全站挑出毛病或提出合理建议,奖励10到100元红包)
124
-              </span>
125
-            </span>
126
-          </div>
127
-        ) : null}
128
-        <div style={{ marginTop: 40 }}>{childrenWithProps}</div>
129
-      </div>
130
-    );
131
-  }
132
-}
133
-
134
-CommentInput.propTypes = {
135
-  // normal 有切换回复/口碑的 header ; comment 评论输入框 / reply 回复输入框
136
-  type: PropTypes.oneOf(["normal", "comment", "reply"])
137
-};
138
-
139
-CommentInput.defaultProps = {
140
-  type: "normal"
141
-};
142
-
143
-export default Comment(CommentInput);

+ 0
- 1
src/components/CommentInput/index.js Bestand weergeven

@@ -10,7 +10,6 @@ class CommentInput extends Component {
10 10
   }
11 11
 
12 12
   handleSubmit(value) {
13
-    console.log("handleSubmit comment input value: ", value);
14 13
     const { action, commentId, replyId, callback } = this.props;
15 14
     if (action === "comment") {
16 15
       this.props.app.sCreateComment({

+ 3
- 2
src/components/ContentItem/index.css Bestand weergeven

@@ -7,10 +7,11 @@
7 7
   display: inline-block;
8 8
   width: 90%;
9 9
   margin-left: 10px;
10
+  margin-bottom: 20px;
10 11
 }
11 12
 .box {
12
-  margin: 10px 0;
13
-  padding: 15px 5px;
13
+  margin: 10px 0 0 0;
14
+  padding: 15px 5px 0 5px;
14 15
   border-top: 1px solid #eee;
15 16
 }
16 17
 .content {

+ 4
- 5
src/components/ContentItem/index.js Bestand weergeven

@@ -12,14 +12,14 @@ class CommentItem extends Component {
12 12
   constructor(props) {
13 13
     super(props);
14 14
     this.state = {
15
-      isShowInput: false
15
+      showInput: false
16 16
     };
17 17
     this.handleToggleInput = this.handleToggleInput.bind(this);
18 18
     this.renderTextWithReply = this.renderTextWithReply.bind(this);
19 19
   }
20 20
 
21 21
   handleToggleInput() {
22
-    this.setState({ isShowInput: !this.state.isShowInput });
22
+    this.setState({ showInput: !this.state.showInput });
23 23
   }
24 24
 
25 25
   renderTextWithReply(text, content) {
@@ -46,9 +46,8 @@ class CommentItem extends Component {
46 46
       onShowReply,
47 47
       app
48 48
     } = this.props;
49
-    // console.log("this.props: ", this.props);
50 49
 
51
-    const { isShowInput } = this.state;
50
+    const { showInput } = this.state;
52 51
 
53 52
     return (
54 53
       <div className="box">
@@ -111,7 +110,7 @@ class CommentItem extends Component {
111 110
           </div>
112 111
         </div>
113 112
 
114
-        {isShowInput && (
113
+        {showInput && (
115 114
           <CommentInput
116 115
             content={app.children}
117 116
             action={action}

+ 0
- 23
src/components/Editor.1/Emoji.css Bestand weergeven

@@ -1,23 +0,0 @@
1
-.item {
2
-  float: left;
3
-  width: 40px;
4
-  height: 40px;
5
-  cursor: pointer;
6
-  white-space: nowrap;
7
-  /* this is required unless you put the helper span closely near the img */
8
-  text-align: center;
9
-  margin: 0;
10
-}
11
-.item .helper {
12
-  display: inline-block;
13
-  height: 100%;
14
-  vertical-align: middle;
15
-}
16
-.item img {
17
-  margin: 0 auto;
18
-  vertical-align: middle;
19
-  padding: 3px;
20
-}
21
-.item img:hover {
22
-  border: 1px solid #40a9ff;
23
-}

+ 0
- 67
src/components/Editor.1/Emoji.js Bestand weergeven

@@ -1,67 +0,0 @@
1
-import React from "react";
2
-import { Carousel } from "antd";
3
-import emoji, { prefixUrl, ext } from "../../emoji";
4
-import "./Emoji.css";
5
-// 每页 20  5*4
6
-// 共 20 * 3 = 60 (实际是 54)
7
-
8
-// class Emoji
9
-
10
-const Emoji = ({ onClick }) => {
11
-  const content = [[], [], []];
12
-
13
-  for (let i = 0; i < emoji.length; i++) {
14
-    if (i < 20) {
15
-      content[0].push(emoji[i]);
16
-    } else if (i < 40) {
17
-      content[1].push(emoji[i]);
18
-    } else if (i < emoji.length) {
19
-      content[2].push(emoji[i]);
20
-    }
21
-  }
22
-  return (
23
-    <Carousel>
24
-      <div>
25
-        {content[0].map((item, index) => (
26
-          <div className="item" key={item.value}>
27
-            <span className="helper" />
28
-            <img
29
-              src={`${prefixUrl}${item.value}.${ext}`}
30
-              alt={item.title}
31
-              style={{ display: "inline-block" }}
32
-              onClick={() => onClick(item.title)}
33
-            />
34
-          </div>
35
-        ))}
36
-      </div>
37
-      <div>
38
-        {content[1].map((item, index) => (
39
-          <div className="item" key={item.value}>
40
-            <span className="helper" />
41
-            <img
42
-              src={`${prefixUrl}${item.value}.${ext}`}
43
-              alt={item.title}
44
-              style={{ display: "inline-block" }}
45
-              onClick={() => onClick(item.title)}
46
-            />
47
-          </div>
48
-        ))}
49
-      </div>
50
-      <div>
51
-        {content[2].map(item => (
52
-          <div className="item" key={item.value}>
53
-            <span className="helper" />
54
-            <img
55
-              src={`${prefixUrl}${item.value}.${ext}`}
56
-              alt={item.title}
57
-              style={{ display: "inline-block" }}
58
-              onClick={() => onClick(item.title)}
59
-            />
60
-          </div>
61
-        ))}
62
-      </div>
63
-    </Carousel>
64
-  );
65
-};
66
-
67
-export default Emoji;

+ 0
- 8
src/components/Editor.1/Upload.css Bestand weergeven

@@ -1,8 +0,0 @@
1
-.ant-upload-select-picture-card i {
2
-  font-size: 32px;
3
-  color: #999;
4
-}
5
-.ant-upload-select-picture-card .ant-upload-text {
6
-  margin-top: 8px;
7
-  color: #666;
8
-}

+ 0
- 132
src/components/Editor.1/Upload.js Bestand weergeven

@@ -1,132 +0,0 @@
1
-import React from "react";
2
-import { Upload, Icon, Modal, message } from "antd";
3
-import dayjs from "dayjs";
4
-import shortid from "shortid";
5
-import {
6
-  OSS_ENDPOINT,
7
-  OSS_BUCKET,
8
-  DRIVER_LICENSE_PATH,
9
-  ERROR_DEFAULT,
10
-  MAX_UPLOAD_NUMBER
11
-} from "../../constant";
12
-import Comment from "../../Comment";
13
-// import styles from "./Upload.less";
14
-import "./Upload.css";
15
-
16
-const client = oss => {
17
-  return new window.OSS.Wrapper({
18
-    accessKeyId: oss.access_key_id,
19
-    accessKeySecret: oss.access_key_secret,
20
-    stsToken: oss.security_token,
21
-    endpoint: OSS_ENDPOINT, //常量,你可以自己定义
22
-    bucket: OSS_BUCKET
23
-  });
24
-};
25
-
26
-const uploadPath = (path, file) => {
27
-  return `${path}/${dayjs().format("YYYYMMDD")}/${shortid.generate()}.${
28
-    file.type.split("/")[1]
29
-  }`;
30
-};
31
-
32
-const UploadToOss = (oss, path, file) => {
33
-  const url = uploadPath(path, file);
34
-  return new Promise((resolve, reject) => {
35
-    client(oss)
36
-      .multipartUpload(url, file)
37
-      .then(data => {
38
-        resolve(data);
39
-      })
40
-      .catch(error => {
41
-        reject(error);
42
-      });
43
-  });
44
-};
45
-
46
-class App extends React.Component {
47
-  constructor(props) {
48
-    super(props);
49
-    this.state = {
50
-      previewVisible: false,
51
-      previewImage: ""
52
-    };
53
-    this.handleCancel = this.handleCancel.bind(this);
54
-    this.handlePreview = this.handlePreview.bind(this);
55
-    this.handleChange = this.handleChange.bind(this);
56
-    this.customRequest = this.customRequest.bind(this);
57
-  }
58
-
59
-  componentDidMount() {
60
-    this.props.app.sOssSts();
61
-  }
62
-
63
-  handleCancel() {
64
-    this.setState({ previewVisible: false });
65
-  }
66
-
67
-  handlePreview(file) {
68
-    this.setState({
69
-      previewImage: file.url || file.thumbUrl,
70
-      previewVisible: true
71
-    });
72
-  }
73
-
74
-  handleChange({ fileList }) {
75
-    this.props.onChangeFileList(fileList);
76
-  }
77
-
78
-  customRequest(info) {
79
-    const { file } = info;
80
-    info.onProgress({ percent: 10 });
81
-    let reader = new FileReader();
82
-    reader.readAsDataURL(info.file);
83
-    reader.onloadend = () => {
84
-      info.onProgress({ percent: 20 });
85
-      // DRIVER_LICENSE_PATH oss 的存储路径位置
86
-      UploadToOss(this.props.app.oss, DRIVER_LICENSE_PATH, file)
87
-        .then(data => {
88
-          info.onProgress({ percent: 100 });
89
-          info.onSuccess();
90
-          this.props.onUpload({ path: data.name, uid: file.uid });
91
-        })
92
-        .catch(e => {
93
-          message.error(e.message || ERROR_DEFAULT);
94
-          info.onError(e);
95
-        });
96
-    };
97
-  }
98
-
99
-  render() {
100
-    const { previewVisible, previewImage } = this.state;
101
-    const { fileList } = this.props;
102
-    const uploadButton = (
103
-      <div>
104
-        <Icon type="plus" />
105
-        <div className="ant-upload-text">上传</div>
106
-      </div>
107
-    );
108
-    return (
109
-      <div>
110
-        <Upload
111
-          accept="image/jpg,image/jpeg,image/png,image/bmp"
112
-          listType="picture-card"
113
-          fileList={fileList}
114
-          customRequest={this.customRequest}
115
-          onPreview={this.handlePreview}
116
-          onChange={this.handleChange}
117
-        >
118
-          {fileList.length >= MAX_UPLOAD_NUMBER ? null : uploadButton}
119
-        </Upload>
120
-        <Modal
121
-          visible={previewVisible}
122
-          footer={null}
123
-          onCancel={this.handleCancel}
124
-        >
125
-          <img alt="upload" style={{ width: "100%" }} src={previewImage} />
126
-        </Modal>
127
-      </div>
128
-    );
129
-  }
130
-}
131
-
132
-export default Comment(App);

+ 0
- 82
src/components/Editor.1/index.css Bestand weergeven

@@ -1,82 +0,0 @@
1
-.editor {
2
-  box-sizing: border-box;
3
-  margin: 0;
4
-  padding: 0;
5
-  width: 100%;
6
-  max-width: 100%;
7
-  list-style: none;
8
-  position: relative;
9
-  display: block;
10
-  font-size: 14px;
11
-  line-height: 1.5;
12
-  color: rgba(0, 0, 0, 0.65);
13
-  background-color: #fff;
14
-  background-image: none;
15
-  border: 1px solid #d9d9d9;
16
-  border-radius: 4px;
17
-  transition: all 0.3s, height 0s;
18
-}
19
-.editor textarea.ant-input {
20
-  border: none;
21
-  border-bottom: 1px solid #eee;
22
-  border-bottom-right-radius: 0;
23
-  border-bottom-left-radius: 0;
24
-}
25
-.editor textarea.ant-input:hover {
26
-  border: none;
27
-  border-bottom: 1px solid #eee;
28
-}
29
-.editor textarea.ant-input:focus {
30
-  box-shadow: none;
31
-  border-bottom: 1px solid #eee;
32
-}
33
-.editor [contentEditable="true"]:empty:not(:focus):before {
34
-  content: attr(data-text);
35
-  color: #bfbfbf;
36
-}
37
-.editor:focus,
38
-.editor:hover {
39
-  border-color: #40a9ff;
40
-  outline: 0;
41
-  box-shadow: 0 0 0 2px rgba(24, 144, 255, 0.2);
42
-}
43
-.content {
44
-  display: block;
45
-  box-sizing: border-box;
46
-  padding: 4px 10px;
47
-  width: 100%;
48
-  max-width: 100%;
49
-  height: 100%;
50
-  max-height: 110px;
51
-  overflow-y: auto;
52
-  overflow-x: auto;
53
-}
54
-.content:focus,
55
-.content:hover {
56
-  outline: 0;
57
-}
58
-.toolbar {
59
-  display: inline-block;
60
-  width: 100%;
61
-  margin: 5px 0 0 0;
62
-}
63
-.toolbar .icon {
64
-  font-size: 23px;
65
-  cursor: pointer;
66
-  transition: color 0.3s;
67
-}
68
-.toolbar .icon:hover {
69
-  color: #40a9ff;
70
-}
71
-.feed .ant-popover-inner-content {
72
-  padding: 12px 16px 20px 16px;
73
-}
74
-.feed .ant-carousel .slick-dots {
75
-  bottom: -10px;
76
-}
77
-.feed .ant-carousel .slick-dots li.slick-active button {
78
-  background-color: #7b868a;
79
-}
80
-.feed .ant-carousel .slick-dots li button {
81
-  background-color: #a2aeb5;
82
-}

+ 0
- 157
src/components/Editor.1/index.js Bestand weergeven

@@ -1,157 +0,0 @@
1
-import React from "react";
2
-import PropTypes from "prop-types";
3
-import { Icon, Button, Popover, Input } from "antd";
4
-import { MAX_UPLOAD_NUMBER } from "../../constant";
5
-import Upload from "./Upload";
6
-import Emoji from "./Emoji";
7
-import "./index.css";
8
-
9
-const { TextArea } = Input;
10
-// 设置 Editor 组件的默认值
11
-// 不能在 Editor.defaultProps 中设置
12
-// 因为 Editor 在 ComponentInput 中调用
13
-// 在 ComponentInput 中,需要使用 Editor 的 props 覆盖 ComponentInput 传入的 props
14
-const EditorDefaultProps = {
15
-  rows: 5,
16
-  placeholder: "说点什么吧...",
17
-  showEmoji: true,
18
-  showUpload: true,
19
-  submitText: "发表",
20
-  onChange: () => {}
21
-};
22
-
23
-class Editor extends React.Component {
24
-  constructor(props) {
25
-    super(props);
26
-    this.state = {
27
-      showUpload: false
28
-    };
29
-    this.handleClickEmoji = this.handleClickEmoji.bind(this);
30
-    this.handleShowUpload = this.handleShowUpload.bind(this);
31
-  }
32
-
33
-  componentDidMount() {}
34
-
35
-  handleClickEmoji(emojiId) {
36
-    this.props.onChangeEmoji(emojiId);
37
-  }
38
-
39
-  handleShowUpload(showUpload) {
40
-    if (typeof showUpload === "boolean") {
41
-      this.setState({ showUpload: showUpload });
42
-    } else {
43
-      this.setState({ showUpload: !this.state.showUpload });
44
-    }
45
-  }
46
-
47
-  render() {
48
-    const props = { ...EditorDefaultProps, ...this.props };
49
-    const {
50
-      value,
51
-      onChange,
52
-      onSubmit,
53
-      loading,
54
-      placeholder,
55
-      fileList,
56
-      onChangeFileList,
57
-      rows,
58
-      onUpload,
59
-      showEmoji,
60
-      showUpload,
61
-      submitText
62
-    } = props;
63
-
64
-    return (
65
-      <div className="editor">
66
-        <TextArea
67
-          value={value}
68
-          onChange={e => onChange(e.target.value)}
69
-          rows={rows}
70
-          placeholder={placeholder}
71
-        />
72
-
73
-        <div className="toolbar">
74
-          <div style={{ float: "left", margin: "8px 11px" }}>
75
-            {showEmoji && (
76
-              <Popover
77
-                trigger="click"
78
-                placement="bottomLeft"
79
-                autoAdjustOverflow={false}
80
-                content={
81
-                  <div style={{ width: 200 }}>
82
-                    <Emoji onClick={this.handleClickEmoji} />
83
-                  </div>
84
-                }
85
-                overlayClassName="feed"
86
-              >
87
-                <Icon type="smile-o" className="icon" />
88
-              </Popover>
89
-            )}
90
-
91
-            {showUpload && (
92
-              <Popover
93
-                visible={this.state.showUpload}
94
-                overlayStyle={{ zIndex: 999 }}
95
-                content={
96
-                  <div
97
-                    style={{ width: 112 * MAX_UPLOAD_NUMBER, minHeight: 100 }}
98
-                  >
99
-                    <Upload
100
-                      onChangeFileList={onChangeFileList}
101
-                      onUpload={onUpload}
102
-                      fileList={fileList}
103
-                    />
104
-                  </div>
105
-                }
106
-                placement="bottomLeft"
107
-                title={
108
-                  <div style={{ margin: "5px auto" }}>
109
-                    <span>
110
-                      上传图片
111
-                      <span style={{ color: "#666", fontWeight: 400 }}>
112
-                        (您还能上传{MAX_UPLOAD_NUMBER - fileList.length}张图片)
113
-                      </span>
114
-                    </span>
115
-                    <Icon
116
-                      type="close"
117
-                      onClick={() => this.handleShowUpload(false)}
118
-                      style={{
119
-                        float: "right",
120
-                        cursor: "pointer",
121
-                        marginTop: 4
122
-                      }}
123
-                    />
124
-                  </div>
125
-                }
126
-              >
127
-                <Icon
128
-                  type="picture"
129
-                  className="icon"
130
-                  style={{ marginLeft: 10 }}
131
-                  onClick={() => this.handleShowUpload(true)}
132
-                />
133
-              </Popover>
134
-            )}
135
-          </div>
136
-
137
-          <div style={{ float: "right", margin: "5px 11px" }}>
138
-            <Button onClick={onSubmit} type="primary" loading={loading}>
139
-              {submitText}
140
-            </Button>
141
-          </div>
142
-        </div>
143
-      </div>
144
-    );
145
-  }
146
-}
147
-
148
-Editor.propTypes = {
149
-  rows: PropTypes.number,
150
-  placeholder: PropTypes.string,
151
-  showEmoji: PropTypes.bool,
152
-  showUpload: PropTypes.bool,
153
-  submitText: PropTypes.string,
154
-  onChange: PropTypes.func
155
-};
156
-
157
-export default Editor;

+ 0
- 1
src/components/Editor/Upload.js Bestand weergeven

@@ -10,7 +10,6 @@ import {
10 10
   MAX_UPLOAD_NUMBER
11 11
 } from "../../constant";
12 12
 import Comment from "../../Comment";
13
-// import styles from "./Upload.less";
14 13
 import "./Upload.css";
15 14
 
16 15
 const client = oss => {

+ 1
- 9
src/components/Editor/index.js Bestand weergeven

@@ -101,7 +101,6 @@ class Editor extends React.Component {
101 101
   }
102 102
 
103 103
   render() {
104
-    // const props = { ...EditorDefaultProps, ...this.props };
105 104
     const {
106 105
       value,
107 106
       placeholder,
@@ -115,14 +114,7 @@ class Editor extends React.Component {
115 114
       emojiToolIcon,
116 115
       imageToolIcon
117 116
     } = this.props;
118
-    // console.log("editor: ", this.props);
119
-    console.log("imageToolIcon: ", imageToolIcon);
120
-    //   var clonedElementWithMoreProps = React.cloneElement(
121
-    //     this.mainContent,
122
-    //     { anotherMessage: "nice to meet ya!" }
123
-    // );
124
-    // console.log('button: ', button);
125
-    console.log("button.props.onClick ", button.props.onClick);
117
+
126 118
     const handleSubmit = this.handleSubmit;
127 119
     return (
128 120
       <div className="editor">

+ 42
- 34
src/index.js Bestand weergeven

@@ -29,43 +29,51 @@ class Index extends Component {
29 29
   }
30 30
 
31 31
   render() {
32
-    const props = {
33
-      type: 1,
34
-      businessId: "1",
35
-      API: "http://api.links123.net/comment/v1",
36
-      showList: true
37
-    };
38
-
39
-    const editorProps = {
40
-      showEmoji: true,
41
-      placeholder: "说点什么吧",
42
-      rows: 5,
43
-      btnLoading: this.state.loading,
44
-      btnDisable: this.state.loading,
45
-      btnSubmitText: "提交",
46
-      value: this.state.value,
47
-      onChange: v => this.handleChangeValue(v),
48
-      onSubmit: v => this.handleChangeSubmit(v),
49
-      button: (
50
-        <Button
51
-          type="primary"
52
-          ghost
53
-          // onClick={() => console.log('click btn: ', this.state.value)}
54
-        >
55
-          自定义按钮
56
-        </Button>
57
-      ),
58
-      emojiToolIcon: <Icon type="smile" style={{ fontSize: 23 }} />,
59
-      imageToolIcon: (
60
-        <Icon type="cloud-upload-o" style={{ fontSize: 25, marginLeft: 10 }} />
61
-      )
62
-    };
63
-
32
+    // 最简单的用法
64 33
     return (
65
-      <App {...props}>
66
-        <Editor {...editorProps} />
34
+      <App type={1} businessId="test">
35
+        <Editor />
67 36
       </App>
68 37
     );
38
+
39
+    // 复杂的用户法
40
+    // const props = {
41
+    //   type: 1,
42
+    //   businessId: "1",
43
+    //   API: "http://api.links123.net/comment/v1",
44
+    //   showList: true
45
+    // };
46
+
47
+    // const editorProps = {
48
+    //   showEmoji: true,
49
+    //   placeholder: "说点什么吧",
50
+    //   rows: 5,
51
+    //   btnLoading: this.state.loading,
52
+    //   btnDisable: this.state.loading,
53
+    //   btnSubmitText: "提交",
54
+    //   value: this.state.value,
55
+    //   onChange: v => this.handleChangeValue(v),
56
+    //   onSubmit: v => this.handleChangeSubmit(v),
57
+    //   button: (
58
+    //     <Button
59
+    //       type="primary"
60
+    //       ghost
61
+    //       // onClick={() => console.log('click btn: ', this.state.value)}
62
+    //     >
63
+    //       自定义按钮
64
+    //     </Button>
65
+    //   ),
66
+    //   emojiToolIcon: <Icon type="smile" style={{ fontSize: 23 }} />,
67
+    //   imageToolIcon: (
68
+    //     <Icon type="cloud-upload-o" style={{ fontSize: 25, marginLeft: 10 }} />
69
+    //   )
70
+    // };
71
+
72
+    // return (
73
+    //   <App {...props}>
74
+    //     <Editor {...editorProps} />
75
+    //   </App>
76
+    // );
69 77
   }
70 78
 }
71 79