Selaa lähdekoodia

Merge branch 'master' of narrowizard/comment into master

narrowizard 6 vuotta sitten
vanhempi
commit
7f2175298c

+ 5
- 0
CHANGELOG.md Näytä tiedosto

@@ -1,5 +1,10 @@
1 1
 # CHANGELOG
2 2
 
3
+## 0.5.2
4
+
5
+- [x] feat: Editor 增加 props: showError、onError、beforeSubmit
6
+- [x] feat: Comment 增加 props: showError、onError
7
+
3 8
 ## 0.5.1
4 9
 
5 10
 - [x] feat: Editor 添加 props: closeUploadWhenBlur

+ 36
- 30
README.md Näytä tiedosto

@@ -8,45 +8,51 @@
8 8
 import Comment, { Editor, RenderText } from 'comment';
9 9
 ```
10 10
 
11
-- [deprecate] 表示不推荐使用
11
+- 标记了`deprecated`的配置项表示不推荐使用,并且可能在将来版本中不再受支持。
12 12
 
13 13
 ## Comment
14 14
 
15 15
 
16
-| props      | type    | default                            | required | description                                  |
17
-| ---------- | ------- | ---------------------------------- | -------- | -------------------------------------------- |
18
-| type       | number  |                                    | true     | 评论的 type                                  |
19
-| businessId | string  |                                    | true     | 评论的 business id                           |
20
-| API        | string  | http://api.links123.net/comment/v1 | false    | API 前缀                                     |
21
-| showList   | boolean | true                               | false    | 是否显示评论列表                             |
22
-| showEditor | boolean | true                               | false    | 是否显示评论输入框                           |
23
-| showAlertComment | boolean | false                               | false    | 评论成功之后,是否通过 Antd 的 Message 组件进行提示  |
24
-| showAlertReply | boolean | false                               | false    | 回复成功之后,是否通过 Antd 的 Message 组件进行提示  |
25
-| showAlertFavor | boolean | false                               | false    | 点赞/取消点赞成功之后,是否通过 Antd 的 Message 组件进行提示  |
26
-| token      | string  |                                    | false    |  [deprecate] token,用于身份认证,非必须。默认使用 cookie |
16
+| props            | type          | default                            | required | description                                                  |
17
+| ---------------- | ------------- | ---------------------------------- | -------- | ------------------------------------------------------------ |
18
+| type             | number        |                                    | true     | 评论的 type                                                  |
19
+| businessId       | string        |                                    | true     | 评论的 business id                                           |
20
+| API              | string        | http://api.links123.net/comment/v1 | false    | API 前缀                                                     |
21
+| showList         | boolean       | true                               | false    | 是否显示评论列表                                             |
22
+| showEditor       | boolean       | true                               | false    | 是否显示评论输入框                                           |
23
+| showAlertComment | boolean       | false                              | false    | 评论成功之后,是否通过 Antd 的 Message 组件进行提示          |
24
+| showAlertReply   | boolean       | false                              | false    | 回复成功之后,是否通过 Antd 的 Message 组件进行提示          |
25
+| showAlertFavor   | boolean       | false                              | false    | 点赞/取消点赞成功之后,是否通过 Antd 的 Message 组件进行提示 |
26
+| showError        | boolean       | true                               | false    | 是否使用Antd的Message组件提示错误信息                        |
27
+| onError          | function(msg) |                                    | false    | 错误回调, 出错了会被调用                                     |
28
+| token            | string        |                                    | false    | [deprecated] token,用于身份认证,非必须。默认使用 cookie    |
27 29
 
28 30
 
29 31
 
30 32
 ## Editor
31 33
 
32
-| props         | type            | default       | required | description                                                                                       |
33
-| ------------- | --------------- | ------------- | -------- | ------------------------------------------------------------------------------------------------- |
34
-| rows          | number          | 5             | false    | 编辑器的高度。默认情况下,回复评论/回复回复的编辑器会比评论的编辑器高度小一行                     |
35
-| placeholder   | string          | 说点什么吧... | false    | 评论的中的提示文字                                                                                |
36
-| showEmoji     | boolean         | true          | false    | 是否显示 Toolbar 中表情工具                                                                       |
37
-| showUpload    | boolean         | true          | false    | 是否显示 Toolbar 中 上传图片工具                                                                  |
38
-| maxUpload    | number         |  1          | false    | 最大能够上传的图片数量                                                                  |
39
-| value         | string          |               | false    | 编辑器的值。如果设置了该属性,则编辑器变为受控组件,需要父组件来维护 value                        |
40
-| onChange      | function(value) |               | false    | 编辑器内容改变的回调函数                                                                          |
41
-| onSubmit      | function({ text, files }) |               | false    | 点击提交按钮的回调函数,text 为编辑器的文本,files 为上传的文件列表                           |
42
-| btnSubmitText | string          | 发表          | false    | 提交按钮的文字                                                                                    |
43
-| btnLoading    | boolean         | false         | false    | 按钮是否正在加载中                                                                                |
44
-| btnDisable    | boolean         | false         | false    | 按钮是否禁用                                                                                      |
45
-| button        | ReactNode       |               | false    | 按钮组件。如果上面几个 btn 相关的属性都无法满足要求,则可以使用 button 来自定义提交编辑器值的按钮 |
46
-| emojiToolIcon | ReactNode       |               | false    | Toolbar 中表情的图标                                                                              |
47
-| imageToolIcon | ReactNode       |               | false    | Toolbar 中上传文件的图标                                                     |
48
-| onRef      | function |                                   | false    | 传递子组件的引用                       |
49
-| closeUploadWhenBlur      | boolean |         | false    | 当 upload 失去焦点(鼠标点击非 Upload 的区域)的时候,是否自动关闭 Popover                |
34
+| props               | type                            | default       | required | description                                                                                       |
35
+| ------------------- | ------------------------------- | ------------- | -------- | ------------------------------------------------------------------------------------------------- |
36
+| rows                | number                          | 5             | false    | 编辑器的高度。默认情况下,回复评论/回复回复的编辑器会比评论的编辑器高度小一行                     |
37
+| placeholder         | string                          | 说点什么吧... | false    | 评论的中的提示文字                                                                                |
38
+| showEmoji           | boolean                         | true          | false    | 是否显示 Toolbar 中表情工具                                                                       |
39
+| showUpload          | boolean                         | true          | false    | 是否显示 Toolbar 中 上传图片工具                                                                  |
40
+| maxUpload           | number                          | 1             | false    | 最大能够上传的图片数量                                                                            |
41
+| value               | string                          |               | false    | 编辑器的值。如果设置了该属性,则编辑器变为受控组件,需要父组件来维护 value                        |
42
+| onChange            | function(value)                 |               | false    | 编辑器内容改变的回调函数                                                                          |
43
+| onSubmit            | function({ text, files })       |               | false    | 点击提交按钮的回调函数,text 为编辑器的文本,files 为上传的文件列表                               |
44
+| beforeSubmit        | function ({text,files}):boolean |               | false    | 点击提交按钮后的钩子, 若返回false则不触发onSubmit函数, 主要用于控制默认的submit行为               |
45
+| btnSubmitText       | string                          | 发表          | false    | 提交按钮的文字                                                                                    |
46
+| btnLoading          | boolean                         | false         | false    | 按钮是否正在加载中                                                                                |
47
+| btnDisable          | boolean                         | false         | false    | 按钮是否禁用                                                                                      |
48
+| button              | ReactNode                       |               | false    | 按钮组件。如果上面几个 btn 相关的属性都无法满足要求,则可以使用 button 来自定义提交编辑器值的按钮 |
49
+| emojiToolIcon       | ReactNode                       |               | false    | Toolbar 中表情的图标                                                                              |
50
+| imageToolIcon       | ReactNode                       |               | false    | Toolbar 中上传文件的图标                                                                          |
51
+| onRef               | function                        |               | false    | 传递子组件的引用                                                                                  |
52
+| closeUploadWhenBlur | boolean                         |               | false    | 当 upload 失去焦点(鼠标点击非 Upload 的区域)的时候,是否自动关闭 Popover                        |
53
+| showError           | boolean                         | true          | false    | 是否使用Antd的Message组件提示错误信息, 主要是上传图片出错的情况                                   |
54
+| onError             | function(msg)                   |               | false    | 错误回调, 出错了会被调用, 主要是上传图片出错的情况                                                                           |
55
+
50 56
 
51 57
 
52 58
 

+ 31
- 18
lib/App.js Näytä tiedosto

@@ -107,6 +107,16 @@ var App = function (_Component) {
107 107
   }, {
108 108
     key: "componentDidMount",
109 109
     value: function componentDidMount() {}
110
+  }, {
111
+    key: "error",
112
+    value: function error(msg) {
113
+      if (this.props.showError) {
114
+        _message3.default.error(msg);
115
+      }
116
+      if (this.props.onError) {
117
+        this.props.onError(msg);
118
+      }
119
+    }
110 120
 
111 121
     /**
112 122
      * 改变 loading 状态
@@ -172,10 +182,10 @@ var App = function (_Component) {
172 182
         }
173 183
       }).catch(function (error) {
174 184
         if (error.response && error.response.data && error.response.data.msg) {
175
-          _message3.default.error(_lang2.default[error.response.data.msg] || _constant.ERROR_DEFAULT);
185
+          _this2.error(_lang2.default[error.response.data.msg] || _constant.ERROR_DEFAULT);
176 186
           return;
177 187
         }
178
-        _message3.default.error(_lang2.default[error.message] || _constant.ERROR_DEFAULT);
188
+        _this2.error(_lang2.default[error.message] || _constant.ERROR_DEFAULT);
179 189
       }).finally(function () {
180 190
         _this2.handleChangeLoading("sGetComment", false);
181 191
       });
@@ -227,10 +237,10 @@ var App = function (_Component) {
227 237
         _this3.setState({ list: list });
228 238
       }).catch(function (error) {
229 239
         if (error.response && error.response.data && error.response.data.msg) {
230
-          _message3.default.error(_lang2.default[error.response.data.msg] || _constant.ERROR_DEFAULT);
240
+          _this3.error(_lang2.default[error.response.data.msg] || _constant.ERROR_DEFAULT);
231 241
           return;
232 242
         }
233
-        _message3.default.error(_lang2.default[error.message] || _constant.ERROR_DEFAULT);
243
+        _this3.error(_lang2.default[error.message] || _constant.ERROR_DEFAULT);
234 244
       }).finally(function () {
235 245
         _this3.handleChangeLoading("sGetReply", false);
236 246
       });
@@ -251,7 +261,7 @@ var App = function (_Component) {
251 261
 
252 262
       var cb = arguments[1];
253 263
 
254
-      if (!content) return _message3.default.error("评论内容不能为空 ");
264
+      if (!content) return this.error("评论内容不能为空 ");
255 265
       this.handleChangeLoading("sCreateComment", true);
256 266
       var _props2 = this.props,
257 267
           API = _props2.API,
@@ -284,10 +294,10 @@ var App = function (_Component) {
284 294
         _this4.setState({ list: list, total: total + 1 });
285 295
       }).catch(function (error) {
286 296
         if (error.response && error.response.data && error.response.data.msg) {
287
-          _message3.default.error(_lang2.default[error.response.data.msg] || _constant.ERROR_DEFAULT);
297
+          _this4.error(_lang2.default[error.response.data.msg] || _constant.ERROR_DEFAULT);
288 298
           return;
289 299
         }
290
-        _message3.default.error(_lang2.default[error.message] || _constant.ERROR_DEFAULT);
300
+        _this4.error(_lang2.default[error.message] || _constant.ERROR_DEFAULT);
291 301
       }).finally(function () {
292 302
         _this4.handleChangeLoading("sCreateComment", false);
293 303
       });
@@ -304,7 +314,7 @@ var App = function (_Component) {
304 314
     value: function sCreateReply(data, cb) {
305 315
       var _this5 = this;
306 316
 
307
-      if (!data.content) return _message3.default.error("回复内容不能为空 ");
317
+      if (!data.content) return this.error("回复内容不能为空 ");
308 318
       this.handleChangeLoading("sCreateReply", true);
309 319
       var API = this.props.API;
310 320
 
@@ -333,10 +343,10 @@ var App = function (_Component) {
333 343
         _this5.setState({ list: list });
334 344
       }).catch(function (error) {
335 345
         if (error.response && error.response.data && error.response.data.msg) {
336
-          _message3.default.error(_lang2.default[error.response.data.msg] || _constant.ERROR_DEFAULT);
346
+          _this5.error(_lang2.default[error.response.data.msg] || _constant.ERROR_DEFAULT);
337 347
           return;
338 348
         }
339
-        _message3.default.error(_lang2.default[error.message] || _constant.ERROR_DEFAULT);
349
+        _this5.error(_lang2.default[error.message] || _constant.ERROR_DEFAULT);
340 350
       }).finally(function () {
341 351
         _this5.handleChangeLoading("sCreateReply", false);
342 352
       });
@@ -374,10 +384,10 @@ var App = function (_Component) {
374 384
         _this6.setState({ list: list });
375 385
       }).catch(function (error) {
376 386
         if (error.response && error.response.data && error.response.data.msg) {
377
-          _message3.default.error(_lang2.default[error.response.data.msg] || _constant.ERROR_DEFAULT);
387
+          _this6.error(_lang2.default[error.response.data.msg] || _constant.ERROR_DEFAULT);
378 388
           return;
379 389
         }
380
-        _message3.default.error(_lang2.default[error.message] || _constant.ERROR_DEFAULT);
390
+        _this6.error(_lang2.default[error.message] || _constant.ERROR_DEFAULT);
381 391
       }).finally(function () {
382 392
         _this6.handleChangeLoading("sCommentFavor", false);
383 393
       });
@@ -425,10 +435,10 @@ var App = function (_Component) {
425 435
         _this7.setState({ list: list });
426 436
       }).catch(function (error) {
427 437
         if (error.response && error.response.data && error.response.data.msg) {
428
-          _message3.default.error(_lang2.default[error.response.data.msg] || _constant.ERROR_DEFAULT);
438
+          _this7.error(_lang2.default[error.response.data.msg] || _constant.ERROR_DEFAULT);
429 439
           return;
430 440
         }
431
-        _message3.default.error(_lang2.default[error.message] || _constant.ERROR_DEFAULT);
441
+        _this7.error(_lang2.default[error.message] || _constant.ERROR_DEFAULT);
432 442
       }).finally(function () {
433 443
         _this7.handleChangeLoading("sReplyFavor", false);
434 444
       });
@@ -450,10 +460,10 @@ var App = function (_Component) {
450 460
         _this8.setState({ oss: _extends({}, response.data) });
451 461
       }).catch(function (error) {
452 462
         if (error.response && error.response.data && error.response.data.msg) {
453
-          _message3.default.error(_lang2.default[error.response.data.msg] || _constant.ERROR_DEFAULT);
463
+          _this8.error(_lang2.default[error.response.data.msg] || _constant.ERROR_DEFAULT);
454 464
           return;
455 465
         }
456
-        _message3.default.error(_lang2.default[error.message] || _constant.ERROR_DEFAULT);
466
+        _this8.error(_lang2.default[error.message] || _constant.ERROR_DEFAULT);
457 467
       }).finally(function () {
458 468
         _this8.handleChangeLoading("sOssSts", false);
459 469
       });
@@ -500,7 +510,9 @@ App.propTypes = {
500 510
   showEditor: _propTypes2.default.bool, // 是否显示评论输入框
501 511
   showAlertComment: _propTypes2.default.bool, // 评论成功之后,是否通过 Antd 的 Message 组件进行提示
502 512
   showAlertReply: _propTypes2.default.bool, // 回复成功之后,是否通过 Antd 的 Message 组件进行提示
503
-  showAlertFavor: _propTypes2.default.bool // 点赞/取消点赞成功之后,是否通过 Antd 的 Message 组件进行提示
513
+  showAlertFavor: _propTypes2.default.bool, // 点赞/取消点赞成功之后,是否通过 Antd 的 Message 组件进行提示
514
+  showError: _propTypes2.default.bool, // 是否使用Antd的Message组件提示错误信息
515
+  onError: _propTypes2.default.func // 错误回调, 出错了会被调用
504 516
 };
505 517
 
506 518
 App.defaultProps = {
@@ -509,7 +521,8 @@ App.defaultProps = {
509 521
   showEditor: true,
510 522
   showAlertComment: false,
511 523
   showAlertReply: false,
512
-  showAlertFavor: false
524
+  showAlertFavor: false,
525
+  showError: true
513 526
 };
514 527
 
515 528
 exports.Editor = _Editor2.default;

+ 1
- 1
lib/App.js.map
File diff suppressed because it is too large
Näytä tiedosto


+ 1
- 1
lib/avatar.js.map
File diff suppressed because it is too large
Näytä tiedosto


+ 1
- 1
lib/axios.js.map Näytä tiedosto

@@ -1 +1 @@
1
-{"version":3,"sources":["../src/axios.js"],"names":["axios","defaults","withCredentials","headers","common"],"mappings":";;;;;;AAAA;;;;;;AAEAA,gBAAMC,QAAN,CAAeC,eAAf,GAAiC,IAAjC;AACAF,gBAAMC,QAAN,CAAeE,OAAf,CAAuBC,MAAvB,CAA8B,eAA9B,IAAiD,SAAjD;;kBAEeJ,e","file":"axios.js","sourcesContent":["import axios from \"axios\";\n\naxios.defaults.withCredentials = true;\naxios.defaults.headers.common[\"Authorization\"] = \"Bearer \";\n\nexport default axios;\n"]}
1
+{"version":3,"sources":["../src/axios.js"],"names":["axios","defaults","withCredentials","headers","common"],"mappings":";;;;;;AAAA;;;;;;AAEAA,gBAAMC,QAAN,CAAeC,eAAf,GAAiC,IAAjC;AACAF,gBAAMC,QAAN,CAAeE,OAAf,CAAuBC,MAAvB,CAA8B,eAA9B,IAAiD,SAAjD;;kBAEeJ,e","file":"axios.js","sourcesContent":["import axios from \"axios\";\r\n\r\naxios.defaults.withCredentials = true;\r\naxios.defaults.headers.common[\"Authorization\"] = \"Bearer \";\r\n\r\nexport default axios;\r\n"]}

+ 1
- 1
lib/components/CommentBox/index.js.map
File diff suppressed because it is too large
Näytä tiedosto


+ 1
- 1
lib/components/CommentInput/index.js.map
File diff suppressed because it is too large
Näytä tiedosto


+ 1
- 1
lib/components/CommentList/index.js.map Näytä tiedosto

@@ -1 +1 @@
1
-{"version":3,"sources":["../../../src/components/CommentList/index.js"],"names":["CommentList","props","state","app","sGetComment","list","total","page","loading","isNoMoreComment","spinning","Boolean","sCommentFavor","sReplyFavor","map","item","id","length","Component","propTypes"],"mappings":";;;;;;;;;;;;;;AAAA;;;;AAEA;;;;AACA;;;;AACA;;;;;;;;;;IAEMA,W;;;AACJ,uBAAYC,KAAZ,EAAmB;AAAA;;AAAA,0HACXA,KADW;;AAEjB,UAAKC,KAAL,GAAa,EAAb;AAFiB;AAGlB;;;;yCAEoB;AACnB,WAAKD,KAAL,CAAWE,GAAX,CAAeC,WAAf;AACD;;;6BAEQ;AAAA,uBAQH,KAAKH,KAAL,CAAWE,GARR;AAAA,UAELE,IAFK,cAELA,IAFK;AAAA,UAGLC,KAHK,cAGLA,KAHK;AAAA,UAILC,IAJK,cAILA,IAJK;AAAA,UAKLC,OALK,cAKLA,OALK;AAAA,UAMLC,eANK,cAMLA,eANK;AAAA,UAOLL,WAPK,cAOLA,WAPK;;;AAUP,UAAMM,WAAWC,QACfH,QAAQJ,WAAR,IAAuBI,QAAQI,aAA/B,IAAgDJ,QAAQK,WADzC,CAAjB;AAGA,aACE;AAAA;AAAA;AACE;AAAA;AAAA,YAAM,UAAUH,QAAhB;AACE;AAAA;AAAA;AAAA;AAAQJ,iBAAR;AAAA;AAAA,WADF;AAEGD,eAAKS,GAAL,CAAS;AAAA,mBACR,8BAAC,oBAAD,IAAY,SAASC,IAArB,EAA2B,KAAKA,KAAKC,EAArC,EAAyC,WAAWD,KAAKC,EAAzD,GADQ;AAAA,WAAT,CAFH;AAMG,WAACP,eAAD,IACCJ,KAAKY,MAAL,KAAgBX,KADjB,IAEG;AAAA;AAAA;AACE,yBAAU,wBADZ;AAEE,uBAAS;AAAA,uBAAMF,YAAY,EAAEG,MAAMA,OAAO,CAAf,EAAZ,CAAN;AAAA;AAFX;AAIE;AAAA;AAAA;AAAA;AAAA;AAJF;AARN;AADF,OADF;AAoBD;;;;EA3CuBW,gB;;AA8C1BlB,YAAYmB,SAAZ,GAAwB,EAAxB;;kBAEe,uBAAQnB,WAAR,C","file":"index.js","sourcesContent":["import React, { Component } from \"react\";\nimport { Spin } from \"antd\";\nimport Comment from \"../../Comment\";\nimport CommentBox from \"../CommentBox\";\nimport \"./index.css\";\n\nclass CommentList extends Component {\n  constructor(props) {\n    super(props);\n    this.state = {};\n  }\n\n  componentWillMount() {\n    this.props.app.sGetComment();\n  }\n\n  render() {\n    const {\n      list,\n      total,\n      page,\n      loading,\n      isNoMoreComment,\n      sGetComment\n    } = this.props.app;\n\n    const spinning = Boolean(\n      loading.sGetComment || loading.sCommentFavor || loading.sReplyFavor\n    );\n    return (\n      <div>\n        <Spin spinning={spinning}>\n          <div>共 {total} 条评论</div>\n          {list.map(item => (\n            <CommentBox content={item} key={item.id} commentId={item.id} />\n          ))}\n\n          {!isNoMoreComment &&\n            list.length !== total && (\n              <div\n                className=\"comment-list-show-more\"\n                onClick={() => sGetComment({ page: page + 1 })}\n              >\n                <span>查看更多评论</span>\n              </div>\n            )}\n        </Spin>\n      </div>\n    );\n  }\n}\n\nCommentList.propTypes = {};\n\nexport default Comment(CommentList);\n"]}
1
+{"version":3,"sources":["../../../src/components/CommentList/index.js"],"names":["CommentList","props","state","app","sGetComment","list","total","page","loading","isNoMoreComment","spinning","Boolean","sCommentFavor","sReplyFavor","map","item","id","length","Component","propTypes"],"mappings":";;;;;;;;;;;;;;AAAA;;;;AAEA;;;;AACA;;;;AACA;;;;;;;;;;IAEMA,W;;;AACJ,uBAAYC,KAAZ,EAAmB;AAAA;;AAAA,0HACXA,KADW;;AAEjB,UAAKC,KAAL,GAAa,EAAb;AAFiB;AAGlB;;;;yCAEoB;AACnB,WAAKD,KAAL,CAAWE,GAAX,CAAeC,WAAf;AACD;;;6BAEQ;AAAA,uBAQH,KAAKH,KAAL,CAAWE,GARR;AAAA,UAELE,IAFK,cAELA,IAFK;AAAA,UAGLC,KAHK,cAGLA,KAHK;AAAA,UAILC,IAJK,cAILA,IAJK;AAAA,UAKLC,OALK,cAKLA,OALK;AAAA,UAMLC,eANK,cAMLA,eANK;AAAA,UAOLL,WAPK,cAOLA,WAPK;;;AAUP,UAAMM,WAAWC,QACfH,QAAQJ,WAAR,IAAuBI,QAAQI,aAA/B,IAAgDJ,QAAQK,WADzC,CAAjB;AAGA,aACE;AAAA;AAAA;AACE;AAAA;AAAA,YAAM,UAAUH,QAAhB;AACE;AAAA;AAAA;AAAA;AAAQJ,iBAAR;AAAA;AAAA,WADF;AAEGD,eAAKS,GAAL,CAAS;AAAA,mBACR,8BAAC,oBAAD,IAAY,SAASC,IAArB,EAA2B,KAAKA,KAAKC,EAArC,EAAyC,WAAWD,KAAKC,EAAzD,GADQ;AAAA,WAAT,CAFH;AAMG,WAACP,eAAD,IACCJ,KAAKY,MAAL,KAAgBX,KADjB,IAEG;AAAA;AAAA;AACE,yBAAU,wBADZ;AAEE,uBAAS;AAAA,uBAAMF,YAAY,EAAEG,MAAMA,OAAO,CAAf,EAAZ,CAAN;AAAA;AAFX;AAIE;AAAA;AAAA;AAAA;AAAA;AAJF;AARN;AADF,OADF;AAoBD;;;;EA3CuBW,gB;;AA8C1BlB,YAAYmB,SAAZ,GAAwB,EAAxB;;kBAEe,uBAAQnB,WAAR,C","file":"index.js","sourcesContent":["import React, { Component } from \"react\";\r\nimport { Spin } from \"antd\";\r\nimport Comment from \"../../Comment\";\r\nimport CommentBox from \"../CommentBox\";\r\nimport \"./index.css\";\r\n\r\nclass CommentList extends Component {\r\n  constructor(props) {\r\n    super(props);\r\n    this.state = {};\r\n  }\r\n\r\n  componentWillMount() {\r\n    this.props.app.sGetComment();\r\n  }\r\n\r\n  render() {\r\n    const {\r\n      list,\r\n      total,\r\n      page,\r\n      loading,\r\n      isNoMoreComment,\r\n      sGetComment\r\n    } = this.props.app;\r\n\r\n    const spinning = Boolean(\r\n      loading.sGetComment || loading.sCommentFavor || loading.sReplyFavor\r\n    );\r\n    return (\r\n      <div>\r\n        <Spin spinning={spinning}>\r\n          <div>共 {total} 条评论</div>\r\n          {list.map(item => (\r\n            <CommentBox content={item} key={item.id} commentId={item.id} />\r\n          ))}\r\n\r\n          {!isNoMoreComment &&\r\n            list.length !== total && (\r\n              <div\r\n                className=\"comment-list-show-more\"\r\n                onClick={() => sGetComment({ page: page + 1 })}\r\n              >\r\n                <span>查看更多评论</span>\r\n              </div>\r\n            )}\r\n        </Spin>\r\n      </div>\r\n    );\r\n  }\r\n}\r\n\r\nCommentList.propTypes = {};\r\n\r\nexport default Comment(CommentList);\r\n"]}

+ 1
- 1
lib/components/ContentItem/index.js.map
File diff suppressed because it is too large
Näytä tiedosto


+ 1
- 1
lib/components/Editor/Emoji.js.map Näytä tiedosto

@@ -1 +1 @@
1
-{"version":3,"sources":["../../../src/components/Editor/Emoji.js"],"names":["Emoji","onClick","content","i","emoji","length","push","map","item","index","value","prefixUrl","ext","title","display"],"mappings":";;;;;;;;;;;;AAAA;;;;AAEA;;;;AACA;;;;AACA;AACA;;AAEA;;AAEA,IAAMA,QAAQ,SAARA,KAAQ,OAAiB;AAAA,MAAdC,QAAc,QAAdA,OAAc;;AAC7B,MAAMC,UAAU,CAAC,EAAD,EAAK,EAAL,EAAS,EAAT,CAAhB;;AAEA,OAAK,IAAIC,IAAI,CAAb,EAAgBA,IAAIC,gBAAMC,MAA1B,EAAkCF,GAAlC,EAAuC;AACrC,QAAIA,IAAI,EAAR,EAAY;AACVD,cAAQ,CAAR,EAAWI,IAAX,CAAgBF,gBAAMD,CAAN,CAAhB;AACD,KAFD,MAEO,IAAIA,IAAI,EAAR,EAAY;AACjBD,cAAQ,CAAR,EAAWI,IAAX,CAAgBF,gBAAMD,CAAN,CAAhB;AACD,KAFM,MAEA,IAAIA,IAAIC,gBAAMC,MAAd,EAAsB;AAC3BH,cAAQ,CAAR,EAAWI,IAAX,CAAgBF,gBAAMD,CAAN,CAAhB;AACD;AACF;AACD,SACE;AAAA;AAAA;AACE;AAAA;AAAA;AACGD,cAAQ,CAAR,EAAWK,GAAX,CAAe,UAACC,IAAD,EAAOC,KAAP;AAAA,eACd;AAAA;AAAA,YAAK,WAAU,MAAf,EAAsB,KAAKD,KAAKE,KAAhC;AACE,kDAAM,WAAU,QAAhB,GADF;AAEE;AACE,sBAAQC,gBAAR,GAAoBH,KAAKE,KAAzB,SAAkCE,UADpC;AAEE,iBAAKJ,KAAKK,KAFZ;AAGE,mBAAO,EAAEC,SAAS,cAAX,EAHT;AAIE,qBAAS;AAAA,qBAAMb,SAAQO,KAAKK,KAAb,CAAN;AAAA;AAJX;AAFF,SADc;AAAA,OAAf;AADH,KADF;AAcE;AAAA;AAAA;AACGX,cAAQ,CAAR,EAAWK,GAAX,CAAe,UAACC,IAAD,EAAOC,KAAP;AAAA,eACd;AAAA;AAAA,YAAK,WAAU,MAAf,EAAsB,KAAKD,KAAKE,KAAhC;AACE,kDAAM,WAAU,QAAhB,GADF;AAEE;AACE,sBAAQC,gBAAR,GAAoBH,KAAKE,KAAzB,SAAkCE,UADpC;AAEE,iBAAKJ,KAAKK,KAFZ;AAGE,mBAAO,EAAEC,SAAS,cAAX,EAHT;AAIE,qBAAS;AAAA,qBAAMb,SAAQO,KAAKK,KAAb,CAAN;AAAA;AAJX;AAFF,SADc;AAAA,OAAf;AADH,KAdF;AA2BE;AAAA;AAAA;AACGX,cAAQ,CAAR,EAAWK,GAAX,CAAe;AAAA,eACd;AAAA;AAAA,YAAK,WAAU,MAAf,EAAsB,KAAKC,KAAKE,KAAhC;AACE,kDAAM,WAAU,QAAhB,GADF;AAEE;AACE,sBAAQC,gBAAR,GAAoBH,KAAKE,KAAzB,SAAkCE,UADpC;AAEE,iBAAKJ,KAAKK,KAFZ;AAGE,mBAAO,EAAEC,SAAS,cAAX,EAHT;AAIE,qBAAS;AAAA,qBAAMb,SAAQO,KAAKK,KAAb,CAAN;AAAA;AAJX;AAFF,SADc;AAAA,OAAf;AADH;AA3BF,GADF;AA2CD,CAvDD;;kBAyDeb,K","file":"Emoji.js","sourcesContent":["import React from \"react\";\nimport { Carousel } from \"antd\";\nimport emoji, { prefixUrl, ext } from \"../../emoji\";\nimport \"./Emoji.css\";\n// 每页 20  5*4\n// 共 20 * 3 = 60 (实际是 54)\n\n// class Emoji\n\nconst Emoji = ({ onClick }) => {\n  const content = [[], [], []];\n\n  for (let i = 0; i < emoji.length; i++) {\n    if (i < 20) {\n      content[0].push(emoji[i]);\n    } else if (i < 40) {\n      content[1].push(emoji[i]);\n    } else if (i < emoji.length) {\n      content[2].push(emoji[i]);\n    }\n  }\n  return (\n    <Carousel>\n      <div>\n        {content[0].map((item, index) => (\n          <div className=\"item\" key={item.value}>\n            <span className=\"helper\" />\n            <img\n              src={`${prefixUrl}${item.value}.${ext}`}\n              alt={item.title}\n              style={{ display: \"inline-block\" }}\n              onClick={() => onClick(item.title)}\n            />\n          </div>\n        ))}\n      </div>\n      <div>\n        {content[1].map((item, index) => (\n          <div className=\"item\" key={item.value}>\n            <span className=\"helper\" />\n            <img\n              src={`${prefixUrl}${item.value}.${ext}`}\n              alt={item.title}\n              style={{ display: \"inline-block\" }}\n              onClick={() => onClick(item.title)}\n            />\n          </div>\n        ))}\n      </div>\n      <div>\n        {content[2].map(item => (\n          <div className=\"item\" key={item.value}>\n            <span className=\"helper\" />\n            <img\n              src={`${prefixUrl}${item.value}.${ext}`}\n              alt={item.title}\n              style={{ display: \"inline-block\" }}\n              onClick={() => onClick(item.title)}\n            />\n          </div>\n        ))}\n      </div>\n    </Carousel>\n  );\n};\n\nexport default Emoji;\n"]}
1
+{"version":3,"sources":["../../../src/components/Editor/Emoji.js"],"names":["Emoji","onClick","content","i","emoji","length","push","map","item","index","value","prefixUrl","ext","title","display"],"mappings":";;;;;;;;;;;;AAAA;;;;AAEA;;;;AACA;;;;AACA;AACA;;AAEA;;AAEA,IAAMA,QAAQ,SAARA,KAAQ,OAAiB;AAAA,MAAdC,QAAc,QAAdA,OAAc;;AAC7B,MAAMC,UAAU,CAAC,EAAD,EAAK,EAAL,EAAS,EAAT,CAAhB;;AAEA,OAAK,IAAIC,IAAI,CAAb,EAAgBA,IAAIC,gBAAMC,MAA1B,EAAkCF,GAAlC,EAAuC;AACrC,QAAIA,IAAI,EAAR,EAAY;AACVD,cAAQ,CAAR,EAAWI,IAAX,CAAgBF,gBAAMD,CAAN,CAAhB;AACD,KAFD,MAEO,IAAIA,IAAI,EAAR,EAAY;AACjBD,cAAQ,CAAR,EAAWI,IAAX,CAAgBF,gBAAMD,CAAN,CAAhB;AACD,KAFM,MAEA,IAAIA,IAAIC,gBAAMC,MAAd,EAAsB;AAC3BH,cAAQ,CAAR,EAAWI,IAAX,CAAgBF,gBAAMD,CAAN,CAAhB;AACD;AACF;AACD,SACE;AAAA;AAAA;AACE;AAAA;AAAA;AACGD,cAAQ,CAAR,EAAWK,GAAX,CAAe,UAACC,IAAD,EAAOC,KAAP;AAAA,eACd;AAAA;AAAA,YAAK,WAAU,MAAf,EAAsB,KAAKD,KAAKE,KAAhC;AACE,kDAAM,WAAU,QAAhB,GADF;AAEE;AACE,sBAAQC,gBAAR,GAAoBH,KAAKE,KAAzB,SAAkCE,UADpC;AAEE,iBAAKJ,KAAKK,KAFZ;AAGE,mBAAO,EAAEC,SAAS,cAAX,EAHT;AAIE,qBAAS;AAAA,qBAAMb,SAAQO,KAAKK,KAAb,CAAN;AAAA;AAJX;AAFF,SADc;AAAA,OAAf;AADH,KADF;AAcE;AAAA;AAAA;AACGX,cAAQ,CAAR,EAAWK,GAAX,CAAe,UAACC,IAAD,EAAOC,KAAP;AAAA,eACd;AAAA;AAAA,YAAK,WAAU,MAAf,EAAsB,KAAKD,KAAKE,KAAhC;AACE,kDAAM,WAAU,QAAhB,GADF;AAEE;AACE,sBAAQC,gBAAR,GAAoBH,KAAKE,KAAzB,SAAkCE,UADpC;AAEE,iBAAKJ,KAAKK,KAFZ;AAGE,mBAAO,EAAEC,SAAS,cAAX,EAHT;AAIE,qBAAS;AAAA,qBAAMb,SAAQO,KAAKK,KAAb,CAAN;AAAA;AAJX;AAFF,SADc;AAAA,OAAf;AADH,KAdF;AA2BE;AAAA;AAAA;AACGX,cAAQ,CAAR,EAAWK,GAAX,CAAe;AAAA,eACd;AAAA;AAAA,YAAK,WAAU,MAAf,EAAsB,KAAKC,KAAKE,KAAhC;AACE,kDAAM,WAAU,QAAhB,GADF;AAEE;AACE,sBAAQC,gBAAR,GAAoBH,KAAKE,KAAzB,SAAkCE,UADpC;AAEE,iBAAKJ,KAAKK,KAFZ;AAGE,mBAAO,EAAEC,SAAS,cAAX,EAHT;AAIE,qBAAS;AAAA,qBAAMb,SAAQO,KAAKK,KAAb,CAAN;AAAA;AAJX;AAFF,SADc;AAAA,OAAf;AADH;AA3BF,GADF;AA2CD,CAvDD;;kBAyDeb,K","file":"Emoji.js","sourcesContent":["import React from \"react\";\r\nimport { Carousel } from \"antd\";\r\nimport emoji, { prefixUrl, ext } from \"../../emoji\";\r\nimport \"./Emoji.css\";\r\n// 每页 20  5*4\r\n// 共 20 * 3 = 60 (实际是 54)\r\n\r\n// class Emoji\r\n\r\nconst Emoji = ({ onClick }) => {\r\n  const content = [[], [], []];\r\n\r\n  for (let i = 0; i < emoji.length; i++) {\r\n    if (i < 20) {\r\n      content[0].push(emoji[i]);\r\n    } else if (i < 40) {\r\n      content[1].push(emoji[i]);\r\n    } else if (i < emoji.length) {\r\n      content[2].push(emoji[i]);\r\n    }\r\n  }\r\n  return (\r\n    <Carousel>\r\n      <div>\r\n        {content[0].map((item, index) => (\r\n          <div className=\"item\" key={item.value}>\r\n            <span className=\"helper\" />\r\n            <img\r\n              src={`${prefixUrl}${item.value}.${ext}`}\r\n              alt={item.title}\r\n              style={{ display: \"inline-block\" }}\r\n              onClick={() => onClick(item.title)}\r\n            />\r\n          </div>\r\n        ))}\r\n      </div>\r\n      <div>\r\n        {content[1].map((item, index) => (\r\n          <div className=\"item\" key={item.value}>\r\n            <span className=\"helper\" />\r\n            <img\r\n              src={`${prefixUrl}${item.value}.${ext}`}\r\n              alt={item.title}\r\n              style={{ display: \"inline-block\" }}\r\n              onClick={() => onClick(item.title)}\r\n            />\r\n          </div>\r\n        ))}\r\n      </div>\r\n      <div>\r\n        {content[2].map(item => (\r\n          <div className=\"item\" key={item.value}>\r\n            <span className=\"helper\" />\r\n            <img\r\n              src={`${prefixUrl}${item.value}.${ext}`}\r\n              alt={item.title}\r\n              style={{ display: \"inline-block\" }}\r\n              onClick={() => onClick(item.title)}\r\n            />\r\n          </div>\r\n        ))}\r\n      </div>\r\n    </Carousel>\r\n  );\r\n};\r\n\r\nexport default Emoji;\r\n"]}

+ 7
- 1
lib/components/Editor/Upload.js Näytä tiedosto

@@ -145,7 +145,13 @@ var App = function (_React$Component) {
145 145
           info.onSuccess();
146 146
           _this2.props.onUpload({ path: data.name, uid: file.uid });
147 147
         }).catch(function (e) {
148
-          _message3.default.error(e.message || _constant.ERROR_DEFAULT);
148
+          var msg = e.message || _constant.ERROR_DEFAULT;
149
+          if (_this2.props.showError) {
150
+            _message3.default.error(msg);
151
+          }
152
+          if (_this2.props.onError) {
153
+            _this2.props.onError(msg);
154
+          }
149 155
           info.onError(e);
150 156
         });
151 157
       };

+ 1
- 1
lib/components/Editor/Upload.js.map
File diff suppressed because it is too large
Näytä tiedosto


+ 18
- 6
lib/components/Editor/index.js Näytä tiedosto

@@ -191,9 +191,15 @@ var Editor = function (_React$Component) {
191 191
           files.push("" + _constant.OSS_LINK + fileMap[item.uid]);
192 192
         });
193 193
       }
194
-      this.props.onSubmit({ text: value, files: files }, function () {
195
-        _this2.resetState();
196
-      });
194
+      var canSubmit = true;
195
+      if (this.props.beforeSubmit) {
196
+        canSubmit = this.props.beforeSubmit({ text: value, files: files }) === false ? false : true;
197
+      }
198
+      if (canSubmit) {
199
+        this.props.onSubmit({ text: value, files: files }, function () {
200
+          _this2.resetState();
201
+        });
202
+      }
197 203
     }
198 204
   }, {
199 205
     key: "resetState",
@@ -339,7 +345,9 @@ var Editor = function (_React$Component) {
339 345
                     onChangeFileList: this.handleChangeFileList,
340 346
                     onUpload: this.handleUpload,
341 347
                     maxUpload: maxUpload,
342
-                    fileList: this.state.fileList
348
+                    fileList: this.state.fileList,
349
+                    showError: this.props.showError,
350
+                    onError: this.props.onError
343 351
                   })
344 352
                 ),
345 353
                 placement: "bottomLeft",
@@ -421,12 +429,15 @@ Editor.propTypes = {
421 429
   value: _propTypes2.default.string,
422 430
   onChange: _propTypes2.default.func,
423 431
   onSubmit: _propTypes2.default.func,
432
+  beforeSubmit: _propTypes2.default.func,
424 433
   btnSubmitText: _propTypes2.default.string,
425 434
   btnLoading: _propTypes2.default.bool,
426 435
   btnDisabled: _propTypes2.default.bool,
427 436
   button: _propTypes2.default.node,
428 437
   emojiToolIcon: _propTypes2.default.node,
429
-  imageToolIcon: _propTypes2.default.node
438
+  imageToolIcon: _propTypes2.default.node,
439
+  showError: _propTypes2.default.bool,
440
+  onError: _propTypes2.default.func
430 441
 };
431 442
 
432 443
 Editor.defaultProps = {
@@ -438,7 +449,8 @@ Editor.defaultProps = {
438 449
   maxUpload: 1,
439 450
   btnSubmitText: "发表",
440 451
   btnLoading: false,
441
-  btnDisabled: false
452
+  btnDisabled: false,
453
+  showError: true
442 454
 };
443 455
 
444 456
 exports.default = Editor;

+ 1
- 1
lib/components/Editor/index.js.map
File diff suppressed because it is too large
Näytä tiedosto


+ 1
- 1
lib/components/RenderText/index.js.map Näytä tiedosto

@@ -1 +1 @@
1
-{"version":3,"sources":["../../../src/components/RenderText/index.js"],"names":["App","__html","text"],"mappings":";;;;;;AAAA;;;;AACA;;;;AAEA,IAAMA,MAAM,SAANA,GAAM;AAAA,SACV;AACE,eAAU,sBADZ;AAEE,6BAAyB;AACvBC,cAAQ,2BAAcC,IAAd;AADe;AAF3B,IADU;AAAA,CAAZ;;kBASeF,G","file":"index.js","sourcesContent":["import React from \"react\";\nimport { renderContent } from \"../../helper\";\n\nconst App = text => (\n  <div\n    className=\"comment-item-content\"\n    dangerouslySetInnerHTML={{\n      __html: renderContent(text)\n    }}\n  />\n);\n\nexport default App;\n"]}
1
+{"version":3,"sources":["../../../src/components/RenderText/index.js"],"names":["App","__html","text"],"mappings":";;;;;;AAAA;;;;AACA;;;;AAEA,IAAMA,MAAM,SAANA,GAAM;AAAA,SACV;AACE,eAAU,sBADZ;AAEE,6BAAyB;AACvBC,cAAQ,2BAAcC,IAAd;AADe;AAF3B,IADU;AAAA,CAAZ;;kBASeF,G","file":"index.js","sourcesContent":["import React from \"react\";\r\nimport { renderContent } from \"../../helper\";\r\n\r\nconst App = text => (\r\n  <div\r\n    className=\"comment-item-content\"\r\n    dangerouslySetInnerHTML={{\r\n      __html: renderContent(text)\r\n    }}\r\n  />\r\n);\r\n\r\nexport default App;\r\n"]}

+ 1
- 1
lib/constant.js.map Näytä tiedosto

@@ -1 +1 @@
1
-{"version":3,"sources":["../src/constant.js"],"names":["ERROR_DEFAULT","LIMIT","OSS_ENDPOINT","OSS_BUCKET","DRIVER_LICENSE_PATH","OSS_LINK","MAX_UPLOAD_NUMBER","REGEXP","AVATAR","IMAGE_SPLIT"],"mappings":";;;;;AAAO,IAAMA,wCAAgB,MAAtB;;AAEA,IAAMC,wBAAQ,EAAd,C,CAAkB;;AAElB,IAAMC,sCAAe,6BAArB;AACA,IAAMC,kCAAa,eAAnB;AACA,IAAMC,oDAAsB,UAA5B;;AAEA,IAAMC,8BAAW,kDAAjB;;AAEA,IAAMC,gDAAoB,CAA1B;;AAEA,IAAMC,0BAAS,UAAf;;AAEA,IAAMC,0BAAS,EAAf;;AAEA,IAAMC,oCAAc,aAApB","file":"constant.js","sourcesContent":["export const ERROR_DEFAULT = \"出错了!\";\n\nexport const LIMIT = 10; // 默认 limit\n\nexport const OSS_ENDPOINT = \"oss-cn-beijing.aliyuncs.com\";\nexport const OSS_BUCKET = \"links-comment\";\nexport const DRIVER_LICENSE_PATH = \"/comment\";\n\nexport const OSS_LINK = \"http://links-comment.oss-cn-beijing.aliyuncs.com\";\n\nexport const MAX_UPLOAD_NUMBER = 4;\n\nexport const REGEXP = /\\[.+?\\]/g;\n\nexport const AVATAR = \"\";\n\nexport const IMAGE_SPLIT = \"IMAGE_SPLIT\";\n"]}
1
+{"version":3,"sources":["../src/constant.js"],"names":["ERROR_DEFAULT","LIMIT","OSS_ENDPOINT","OSS_BUCKET","DRIVER_LICENSE_PATH","OSS_LINK","MAX_UPLOAD_NUMBER","REGEXP","AVATAR","IMAGE_SPLIT"],"mappings":";;;;;AAAO,IAAMA,wCAAgB,MAAtB;;AAEA,IAAMC,wBAAQ,EAAd,C,CAAkB;;AAElB,IAAMC,sCAAe,6BAArB;AACA,IAAMC,kCAAa,eAAnB;AACA,IAAMC,oDAAsB,UAA5B;;AAEA,IAAMC,8BAAW,kDAAjB;;AAEA,IAAMC,gDAAoB,CAA1B;;AAEA,IAAMC,0BAAS,UAAf;;AAEA,IAAMC,0BAAS,EAAf;;AAEA,IAAMC,oCAAc,aAApB","file":"constant.js","sourcesContent":["export const ERROR_DEFAULT = \"出错了!\";\r\n\r\nexport const LIMIT = 10; // 默认 limit\r\n\r\nexport const OSS_ENDPOINT = \"oss-cn-beijing.aliyuncs.com\";\r\nexport const OSS_BUCKET = \"links-comment\";\r\nexport const DRIVER_LICENSE_PATH = \"/comment\";\r\n\r\nexport const OSS_LINK = \"http://links-comment.oss-cn-beijing.aliyuncs.com\";\r\n\r\nexport const MAX_UPLOAD_NUMBER = 4;\r\n\r\nexport const REGEXP = /\\[.+?\\]/g;\r\n\r\nexport const AVATAR = \"\";\r\n\r\nexport const IMAGE_SPLIT = \"IMAGE_SPLIT\";\r\n"]}

+ 1
- 1
lib/helper.js.map Näytä tiedosto

@@ -1 +1 @@
1
-{"version":3,"sources":["../src/helper.js"],"names":["isFunction","isUrl","arrayToObject","htmlEncode","renderContent","emojiObejct","emoji","functionToCheck","toString","call","userInput","regexp","res","match","array","keyField","reduce","obj","item","str","replace","i","charCodeAt","content","onClick","newContent","indexOf","IMAGE_SPLIT","split","pop","join","REGEXP","a","b","src","slice","value","prefixUrl","ext"],"mappings":";;;;;QAKgBA,U,GAAAA,U;QAMAC,K,GAAAA,K;QAYAC,a,GAAAA,a;QAYAC,U,GAAAA,U;QAYAC,a,GAAAA,a;;AA/ChB;;AACA;;;;;;AAEA,IAAMC,cAAcH,cAAcI,eAAd,EAAqB,OAArB,CAApB;;AAEO,SAASN,UAAT,CAAoBO,eAApB,EAAqC;AAC1C,SACEA,mBAAmB,GAAGC,QAAH,CAAYC,IAAZ,CAAiBF,eAAjB,MAAsC,mBAD3D;AAGD;;AAEM,SAASN,KAAT,CAAeS,SAAf,EAA0B;AAC/B,MAAMC,SAAS,kGAAf;AACA,MAAIC,MAAMF,UAAUG,KAAV,CAAgBF,MAAhB,CAAV;AACA,MAAIC,QAAQ,IAAZ,EAAkB,OAAO,KAAP,CAAlB,KACK,OAAO,IAAP;AACN;;AAED;;;;;AAKO,SAASV,aAAT,CAAuBY,KAAvB,EAA8BC,QAA9B,EAAwC;AAC7C,SAAOD,MAAME,MAAN,CAAa,UAACC,GAAD,EAAMC,IAAN,EAAe;AACjCD,QAAIC,KAAKH,QAAL,CAAJ,IAAsBG,IAAtB;AACA,WAAOD,GAAP;AACD,GAHM,EAGJ,EAHI,CAAP;AAID;;AAED;;;;;AAKO,SAASd,UAAT,CAAoBgB,GAApB,EAAyB;AAC9B,MAAI,CAACA,GAAL,EAAU,OAAO,EAAP;AACV,SAAOA,IAAIC,OAAJ,CAAY,SAAZ,EAAuB,UAASC,CAAT,EAAY;AACxC,WAAO,OAAOA,EAAEC,UAAF,CAAa,CAAb,CAAP,GAAyB,GAAhC;AACD,GAFM,CAAP;AAGD;;AAED;;;;;AAKO,SAASlB,aAAT,CAAuBmB,OAAvB,EAAgCC,OAAhC,EAAyC;AAC9C,MAAIC,aAAaF,OAAjB;AACA,MAAIE,WAAWC,OAAX,CAAmBC,qBAAnB,MAAoC,CAAC,CAAzC,EAA4C;AAC1CF,iBAAaA,WAAWG,KAAX,CAAiBD,qBAAjB,CAAb;AACAF,eAAWI,GAAX;AACAJ,iBAAaA,WAAWK,IAAX,CAAgB,EAAhB,CAAb;AACD;;AAED,SAAO3B,WAAWsB,UAAX,EAAuBL,OAAvB,CAA+BW,gBAA/B,EAAuC,UAASC,CAAT,EAAYC,CAAZ,EAAe;AAC3D,QAAMC,MAAMF,EAAEG,KAAF,CAAQ,CAAR,EAAW,CAAC,CAAZ,CAAZ;;AAEA;AACA;AACA,QAAIlC,MAAMiC,GAAN,CAAJ,EAAgB;AACd,kCAAyBA,GAAzB,iBAAsCA,GAAtC;AACD;AACD,QAAME,QAAQ/B,YAAY6B,GAAZ,IAAmB7B,YAAY6B,GAAZ,EAAiBE,KAApC,GAA4CF,GAA1D;AACA,2BAAoBG,gBAApB,GAAgCD,KAAhC,SAAyCE,UAAzC,iBAAsDF,KAAtD;AACD,GAVM,CAAP;AAWD","file":"helper.js","sourcesContent":["import { REGEXP, IMAGE_SPLIT } from \"./constant\";\nimport emoji, { prefixUrl, ext } from \"./emoji\";\n\nconst emojiObejct = arrayToObject(emoji, \"title\");\n\nexport function isFunction(functionToCheck) {\n  return (\n    functionToCheck && {}.toString.call(functionToCheck) === \"[object Function]\"\n  );\n}\n\nexport function isUrl(userInput) {\n  const regexp = /(http(s)?:\\/\\/.)?(www\\.)?[-a-zA-Z0-9@:%._+~#=]{2,256}\\.[a-z]{2,6}\\b([-a-zA-Z0-9@:%_+.~#?&//=]*)/g;\n  var res = userInput.match(regexp);\n  if (res === null) return false;\n  else return true;\n}\n\n/**\n * 将对象数组转换为对象\n * @param {array} array Array of Objects\n * @param {string} keyField string\n */\nexport function arrayToObject(array, keyField) {\n  return array.reduce((obj, item) => {\n    obj[item[keyField]] = item;\n    return obj;\n  }, {});\n}\n\n/**\n * HTML 编码\n * 将 < > 等字符串进行编码\n * @param {string} str 文本\n */\nexport function htmlEncode(str) {\n  if (!str) return \"\";\n  return str.replace(/[<>]/gim, function(i) {\n    return \"&#\" + i.charCodeAt(0) + \";\";\n  });\n}\n\n/**\n * 渲染编辑器\n * [x] => <img src=\"x\" />\n * @param {strig} content\n */\nexport function renderContent(content, onClick) {\n  let newContent = content;\n  if (newContent.indexOf(IMAGE_SPLIT) !== -1) {\n    newContent = newContent.split(IMAGE_SPLIT);\n    newContent.pop();\n    newContent = newContent.join(\"\");\n  }\n\n  return htmlEncode(newContent).replace(REGEXP, function(a, b) {\n    const src = a.slice(1, -1);\n\n    // 兼容旧的评\n    // 因为旧的评论用 [img url] 方式存储的\n    if (isUrl(src)) {\n      return `<br/><img src=\"${src}\" alt=\"${src}\" style=\"max-width: 100%\" />`;\n    }\n    const value = emojiObejct[src] ? emojiObejct[src].value : src;\n    return `<img src=\"${prefixUrl}${value}.${ext}\" alt=\"${value}\" />`;\n  });\n}\n"]}
1
+{"version":3,"sources":["../src/helper.js"],"names":["isFunction","isUrl","arrayToObject","htmlEncode","renderContent","emojiObejct","emoji","functionToCheck","toString","call","userInput","regexp","res","match","array","keyField","reduce","obj","item","str","replace","i","charCodeAt","content","onClick","newContent","indexOf","IMAGE_SPLIT","split","pop","join","REGEXP","a","b","src","slice","value","prefixUrl","ext"],"mappings":";;;;;QAKgBA,U,GAAAA,U;QAMAC,K,GAAAA,K;QAYAC,a,GAAAA,a;QAYAC,U,GAAAA,U;QAYAC,a,GAAAA,a;;AA/ChB;;AACA;;;;;;AAEA,IAAMC,cAAcH,cAAcI,eAAd,EAAqB,OAArB,CAApB;;AAEO,SAASN,UAAT,CAAoBO,eAApB,EAAqC;AAC1C,SACEA,mBAAmB,GAAGC,QAAH,CAAYC,IAAZ,CAAiBF,eAAjB,MAAsC,mBAD3D;AAGD;;AAEM,SAASN,KAAT,CAAeS,SAAf,EAA0B;AAC/B,MAAMC,SAAS,kGAAf;AACA,MAAIC,MAAMF,UAAUG,KAAV,CAAgBF,MAAhB,CAAV;AACA,MAAIC,QAAQ,IAAZ,EAAkB,OAAO,KAAP,CAAlB,KACK,OAAO,IAAP;AACN;;AAED;;;;;AAKO,SAASV,aAAT,CAAuBY,KAAvB,EAA8BC,QAA9B,EAAwC;AAC7C,SAAOD,MAAME,MAAN,CAAa,UAACC,GAAD,EAAMC,IAAN,EAAe;AACjCD,QAAIC,KAAKH,QAAL,CAAJ,IAAsBG,IAAtB;AACA,WAAOD,GAAP;AACD,GAHM,EAGJ,EAHI,CAAP;AAID;;AAED;;;;;AAKO,SAASd,UAAT,CAAoBgB,GAApB,EAAyB;AAC9B,MAAI,CAACA,GAAL,EAAU,OAAO,EAAP;AACV,SAAOA,IAAIC,OAAJ,CAAY,SAAZ,EAAuB,UAASC,CAAT,EAAY;AACxC,WAAO,OAAOA,EAAEC,UAAF,CAAa,CAAb,CAAP,GAAyB,GAAhC;AACD,GAFM,CAAP;AAGD;;AAED;;;;;AAKO,SAASlB,aAAT,CAAuBmB,OAAvB,EAAgCC,OAAhC,EAAyC;AAC9C,MAAIC,aAAaF,OAAjB;AACA,MAAIE,WAAWC,OAAX,CAAmBC,qBAAnB,MAAoC,CAAC,CAAzC,EAA4C;AAC1CF,iBAAaA,WAAWG,KAAX,CAAiBD,qBAAjB,CAAb;AACAF,eAAWI,GAAX;AACAJ,iBAAaA,WAAWK,IAAX,CAAgB,EAAhB,CAAb;AACD;;AAED,SAAO3B,WAAWsB,UAAX,EAAuBL,OAAvB,CAA+BW,gBAA/B,EAAuC,UAASC,CAAT,EAAYC,CAAZ,EAAe;AAC3D,QAAMC,MAAMF,EAAEG,KAAF,CAAQ,CAAR,EAAW,CAAC,CAAZ,CAAZ;;AAEA;AACA;AACA,QAAIlC,MAAMiC,GAAN,CAAJ,EAAgB;AACd,kCAAyBA,GAAzB,iBAAsCA,GAAtC;AACD;AACD,QAAME,QAAQ/B,YAAY6B,GAAZ,IAAmB7B,YAAY6B,GAAZ,EAAiBE,KAApC,GAA4CF,GAA1D;AACA,2BAAoBG,gBAApB,GAAgCD,KAAhC,SAAyCE,UAAzC,iBAAsDF,KAAtD;AACD,GAVM,CAAP;AAWD","file":"helper.js","sourcesContent":["import { REGEXP, IMAGE_SPLIT } from \"./constant\";\r\nimport emoji, { prefixUrl, ext } from \"./emoji\";\r\n\r\nconst emojiObejct = arrayToObject(emoji, \"title\");\r\n\r\nexport function isFunction(functionToCheck) {\r\n  return (\r\n    functionToCheck && {}.toString.call(functionToCheck) === \"[object Function]\"\r\n  );\r\n}\r\n\r\nexport function isUrl(userInput) {\r\n  const regexp = /(http(s)?:\\/\\/.)?(www\\.)?[-a-zA-Z0-9@:%._+~#=]{2,256}\\.[a-z]{2,6}\\b([-a-zA-Z0-9@:%_+.~#?&//=]*)/g;\r\n  var res = userInput.match(regexp);\r\n  if (res === null) return false;\r\n  else return true;\r\n}\r\n\r\n/**\r\n * 将对象数组转换为对象\r\n * @param {array} array Array of Objects\r\n * @param {string} keyField string\r\n */\r\nexport function arrayToObject(array, keyField) {\r\n  return array.reduce((obj, item) => {\r\n    obj[item[keyField]] = item;\r\n    return obj;\r\n  }, {});\r\n}\r\n\r\n/**\r\n * HTML 编码\r\n * 将 < > 等字符串进行编码\r\n * @param {string} str 文本\r\n */\r\nexport function htmlEncode(str) {\r\n  if (!str) return \"\";\r\n  return str.replace(/[<>]/gim, function(i) {\r\n    return \"&#\" + i.charCodeAt(0) + \";\";\r\n  });\r\n}\r\n\r\n/**\r\n * 渲染编辑器\r\n * [x] => <img src=\"x\" />\r\n * @param {strig} content\r\n */\r\nexport function renderContent(content, onClick) {\r\n  let newContent = content;\r\n  if (newContent.indexOf(IMAGE_SPLIT) !== -1) {\r\n    newContent = newContent.split(IMAGE_SPLIT);\r\n    newContent.pop();\r\n    newContent = newContent.join(\"\");\r\n  }\r\n\r\n  return htmlEncode(newContent).replace(REGEXP, function(a, b) {\r\n    const src = a.slice(1, -1);\r\n\r\n    // 兼容旧的评\r\n    // 因为旧的评论用 [img url] 方式存储的\r\n    if (isUrl(src)) {\r\n      return `<br/><img src=\"${src}\" alt=\"${src}\" style=\"max-width: 100%\" />`;\r\n    }\r\n    const value = emojiObejct[src] ? emojiObejct[src].value : src;\r\n    return `<img src=\"${prefixUrl}${value}.${ext}\" alt=\"${value}\" />`;\r\n  });\r\n}\r\n"]}

+ 21
- 2
lib/index.js Näytä tiedosto

@@ -74,8 +74,27 @@ var Index = function (_Component) {
74 74
       // 最简单的用法
75 75
       return _react2.default.createElement(
76 76
         _App2.default,
77
-        { type: 1, businessId: "test" },
78
-        _react2.default.createElement(_App.Editor, { maxUpload: 4 })
77
+        {
78
+          type: 1,
79
+          businessId: "test",
80
+          showAlertComment: true,
81
+          showAlertReply: true,
82
+          showAlertFavor: true,
83
+          showError: false,
84
+          onError: function onError(msg) {
85
+            console.log("-----------" + msg);
86
+          }
87
+        },
88
+        _react2.default.createElement(_App.Editor, {
89
+          maxUpload: 4,
90
+          beforeSubmit: function beforeSubmit() {
91
+            return true;
92
+          },
93
+          showError: false,
94
+          onError: function onError(msg) {
95
+            console.log("-----------" + msg);
96
+          }
97
+        })
79 98
       );
80 99
 
81 100
       // e.g.

+ 1
- 1
lib/index.js.map Näytä tiedosto

@@ -1 +1 @@
1
-{"version":3,"sources":["../src/index.js"],"names":["Index","props","state","value","handleChangeValue","bind","handleChangeSubmit","setState","console","log","text","files","loading","setTimeout","Component","ReactDOM","render","document","getElementById"],"mappings":";;;;AAAA;;;;AACA;;;;AAIA;;;;AACA;;;;;;;;;;;AAJA;AACA;AACA;;;IAIMA,K;;;AACJ,iBAAYC,KAAZ,EAAmB;AAAA;;AAAA,8GACXA,KADW;;AAEjB,UAAKC,KAAL,GAAa;AACXC,aAAO;AADI,KAAb;AAGA,UAAKC,iBAAL,GAAyB,MAAKA,iBAAL,CAAuBC,IAAvB,OAAzB;AACA,UAAKC,kBAAL,GAA0B,MAAKA,kBAAL,CAAwBD,IAAxB,OAA1B;AANiB;AAOlB;;;;sCAEiBF,K,EAAO;AACvB,WAAKI,QAAL,CAAc,EAAEJ,YAAF,EAAd;AACAK,cAAQC,GAAR,CAAY,2BAAZ,EAAyCN,KAAzC;AACD;;;6CAEmC;AAAA;;AAAA,UAAfO,IAAe,QAAfA,IAAe;AAAA,UAATC,KAAS,QAATA,KAAS;;AAClC,WAAKJ,QAAL,CAAc,EAAEK,SAAS,IAAX,EAAd,EAAiC,YAAM;AACrCC,mBAAW,YAAM;AACf,iBAAKN,QAAL,CAAc,EAAEK,SAAS,KAAX,EAAd;AACD,SAFD,EAEG,IAFH;AAGD,OAJD;AAKAJ,cAAQC,GAAR,CAAY,eAAZ,EAA6BC,IAA7B;AACAF,cAAQC,GAAR,CAAY,gBAAZ,EAA8BE,KAA9B;AACD;;;6BAEQ;AACP;AACA,aACE;AAAC,qBAAD;AAAA,UAAK,MAAM,CAAX,EAAc,YAAW,MAAzB;AACE,sCAAC,WAAD,IAAQ,WAAW,CAAnB;AADF,OADF;;AAMA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACD;;;;EAxEiBG,gB;;AA2EpBC,mBAASC,MAAT,CAAgB,8BAAC,KAAD,OAAhB,EAA2BC,SAASC,cAAT,CAAwB,cAAxB,CAA3B;AACA","file":"index.js","sourcesContent":["import React, { Component } from \"react\";\nimport ReactDOM from \"react-dom\";\n// e.g.\n// import { Button, Icon } from \"antd\";\n// import App, { Editor, RenderText } from \"./App\";\nimport App, { Editor } from \"./App\";\nimport registerServiceWorker from \"./registerServiceWorker\";\n\nclass Index extends Component {\n  constructor(props) {\n    super(props);\n    this.state = {\n      value: \"\"\n    };\n    this.handleChangeValue = this.handleChangeValue.bind(this);\n    this.handleChangeSubmit = this.handleChangeSubmit.bind(this);\n  }\n\n  handleChangeValue(value) {\n    this.setState({ value });\n    console.log(\"handleChangeValue value: \", value);\n  }\n\n  handleChangeSubmit({ text, files }) {\n    this.setState({ loading: true }, () => {\n      setTimeout(() => {\n        this.setState({ loading: false });\n      }, 2000);\n    });\n    console.log(\"submit text: \", text);\n    console.log(\"submit files: \", files);\n  }\n\n  render() {\n    // 最简单的用法\n    return (\n      <App type={1} businessId=\"test\">\n        <Editor maxUpload={4} />\n      </App>\n    );\n\n    // e.g.\n    // 复杂的用户法\n    // const props = {\n    //   type: 1,\n    //   businessId: \"1\",\n    //   API: \"http://api.links123.net/comment/v1\",\n    //   showList: true\n    // };\n\n    // const editorProps = {\n    //   showEmoji: true,\n    //   placeholder: \"说点什么吧\",\n    //   rows: 5,\n    //   btnLoading: this.state.loading,\n    //   btnDisable: this.state.loading,\n    //   btnSubmitText: \"提交\",\n    //   value: this.state.value,\n    //   onChange: v => this.handleChangeValue(v),\n    //   onSubmit: v => this.handleChangeSubmit(v),\n    //   button: (\n    //     <Button\n    //       type=\"primary\"\n    //       ghost\n    //       // onClick={() => console.log('click btn: ', this.state.value)}\n    //     >\n    //       自定义按钮\n    //     </Button>\n    //   ),\n    //   emojiToolIcon: <Icon type=\"smile\" style={{ fontSize: 23 }} />,\n    //   imageToolIcon: (\n    //     <Icon type=\"cloud-upload-o\" style={{ fontSize: 25, marginLeft: 10 }} />\n    //   )\n    // };\n\n    // return (\n    //   <App {...props}>\n    //     <Editor {...editorProps} />\n    //   </App>\n    // );\n  }\n}\n\nReactDOM.render(<Index />, document.getElementById(\"root-comment\"));\nregisterServiceWorker();\n"]}
1
+{"version":3,"sources":["../src/index.js"],"names":["Index","props","state","value","handleChangeValue","bind","handleChangeSubmit","setState","console","log","text","files","loading","setTimeout","msg","Component","ReactDOM","render","document","getElementById"],"mappings":";;;;AAAA;;;;AACA;;;;AAIA;;;;AACA;;;;;;;;;;;AAJA;AACA;AACA;;;IAIMA,K;;;AACJ,iBAAYC,KAAZ,EAAmB;AAAA;;AAAA,8GACXA,KADW;;AAEjB,UAAKC,KAAL,GAAa;AACXC,aAAO;AADI,KAAb;AAGA,UAAKC,iBAAL,GAAyB,MAAKA,iBAAL,CAAuBC,IAAvB,OAAzB;AACA,UAAKC,kBAAL,GAA0B,MAAKA,kBAAL,CAAwBD,IAAxB,OAA1B;AANiB;AAOlB;;;;sCAEiBF,K,EAAO;AACvB,WAAKI,QAAL,CAAc,EAAEJ,YAAF,EAAd;AACAK,cAAQC,GAAR,CAAY,2BAAZ,EAAyCN,KAAzC;AACD;;;6CAEmC;AAAA;;AAAA,UAAfO,IAAe,QAAfA,IAAe;AAAA,UAATC,KAAS,QAATA,KAAS;;AAClC,WAAKJ,QAAL,CAAc,EAAEK,SAAS,IAAX,EAAd,EAAiC,YAAM;AACrCC,mBAAW,YAAM;AACf,iBAAKN,QAAL,CAAc,EAAEK,SAAS,KAAX,EAAd;AACD,SAFD,EAEG,IAFH;AAGD,OAJD;AAKAJ,cAAQC,GAAR,CAAY,eAAZ,EAA6BC,IAA7B;AACAF,cAAQC,GAAR,CAAY,gBAAZ,EAA8BE,KAA9B;AACD;;;6BAEQ;AACP;AACA,aACE;AAAC,qBAAD;AAAA;AACE,gBAAM,CADR;AAEE,sBAAW,MAFb;AAGE,gCAHF;AAIE,8BAJF;AAKE,8BALF;AAME,qBAAW,KANb;AAOE,mBAAS,iBAACG,GAAD,EAAS;AAChBN,oBAAQC,GAAR,iBAA0BK,GAA1B;AACD;AATH;AAWE,sCAAC,WAAD;AACE,qBAAW,CADb;AAEE,wBAAc,wBAAM;AAClB,mBAAO,IAAP;AACD,WAJH;AAKE,qBAAW,KALb;AAME,mBAAS,iBAACA,GAAD,EAAS;AAChBN,oBAAQC,GAAR,iBAA0BK,GAA1B;AACD;AARH;AAXF,OADF;;AAyBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACD;;;;EA3FiBC,gB;;AA8FpBC,mBAASC,MAAT,CAAgB,8BAAC,KAAD,OAAhB,EAA2BC,SAASC,cAAT,CAAwB,cAAxB,CAA3B;AACA","file":"index.js","sourcesContent":["import React, { Component } from \"react\";\r\nimport ReactDOM from \"react-dom\";\r\n// e.g.\r\n// import { Button, Icon } from \"antd\";\r\n// import App, { Editor, RenderText } from \"./App\";\r\nimport App, { Editor } from \"./App\";\r\nimport registerServiceWorker from \"./registerServiceWorker\";\r\n\r\nclass Index extends Component {\r\n  constructor(props) {\r\n    super(props);\r\n    this.state = {\r\n      value: \"\"\r\n    };\r\n    this.handleChangeValue = this.handleChangeValue.bind(this);\r\n    this.handleChangeSubmit = this.handleChangeSubmit.bind(this);\r\n  }\r\n\r\n  handleChangeValue(value) {\r\n    this.setState({ value });\r\n    console.log(\"handleChangeValue value: \", value);\r\n  }\r\n\r\n  handleChangeSubmit({ text, files }) {\r\n    this.setState({ loading: true }, () => {\r\n      setTimeout(() => {\r\n        this.setState({ loading: false });\r\n      }, 2000);\r\n    });\r\n    console.log(\"submit text: \", text);\r\n    console.log(\"submit files: \", files);\r\n  }\r\n\r\n  render() {\r\n    // 最简单的用法\r\n    return (\r\n      <App\r\n        type={1}\r\n        businessId=\"test\"\r\n        showAlertComment\r\n        showAlertReply\r\n        showAlertFavor\r\n        showError={false}\r\n        onError={(msg) => {\r\n          console.log(`-----------${msg}`)\r\n        }}\r\n      >\r\n        <Editor\r\n          maxUpload={4}\r\n          beforeSubmit={() => {\r\n            return true;\r\n          }}\r\n          showError={false}\r\n          onError={(msg) => {\r\n            console.log(`-----------${msg}`)\r\n          }}\r\n        />\r\n      </App>\r\n    );\r\n\r\n    // e.g.\r\n    // 复杂的用户法\r\n    // const props = {\r\n    //   type: 1,\r\n    //   businessId: \"1\",\r\n    //   API: \"http://api.links123.net/comment/v1\",\r\n    //   showList: true\r\n    // };\r\n\r\n    // const editorProps = {\r\n    //   showEmoji: true,\r\n    //   placeholder: \"说点什么吧\",\r\n    //   rows: 5,\r\n    //   btnLoading: this.state.loading,\r\n    //   btnDisable: this.state.loading,\r\n    //   btnSubmitText: \"提交\",\r\n    //   value: this.state.value,\r\n    //   onChange: v => this.handleChangeValue(v),\r\n    //   onSubmit: v => this.handleChangeSubmit(v),\r\n    //   button: (\r\n    //     <Button\r\n    //       type=\"primary\"\r\n    //       ghost\r\n    //       // onClick={() => console.log('click btn: ', this.state.value)}\r\n    //     >\r\n    //       自定义按钮\r\n    //     </Button>\r\n    //   ),\r\n    //   emojiToolIcon: <Icon type=\"smile\" style={{ fontSize: 23 }} />,\r\n    //   imageToolIcon: (\r\n    //     <Icon type=\"cloud-upload-o\" style={{ fontSize: 25, marginLeft: 10 }} />\r\n    //   )\r\n    // };\r\n\r\n    // return (\r\n    //   <App {...props}>\r\n    //     <Editor {...editorProps} />\r\n    //   </App>\r\n    // );\r\n  }\r\n}\r\n\r\nReactDOM.render(<Index />, document.getElementById(\"root-comment\"));\r\nregisterServiceWorker();\r\n"]}

+ 1
- 1
lib/lang/index.js.map Näytä tiedosto

@@ -1 +1 @@
1
-{"version":3,"sources":["../../src/lang/index.js"],"names":["data"],"mappings":";;;;;AAAA;AACA;AACA,IAAMA,OAAO;AACX,eAAa,MADF;AAEX,iBAAe,MAFJ;AAGX,2BAAyB,QAHd;AAIX,0BAAwB,QAJb;AAKX,iCAA+B,UALpB;AAMX,yBAAuB,UANZ;AAOX,yBAAuB,QAPZ;AAQX,wBAAsB,QARX;AASX,+BAA6B,UATlB;AAUX,wBAAsB;AAVX,CAAb;;kBAaeA,I","file":"index.js","sourcesContent":["// 语言包\n// 英文短语和中文提示的对应\nconst data = {\n  \"not found\": \"没有数据\",\n  \"auth failed\": \"请先登录\",\n  \"create comment failed\": \"创建评论失败\",\n  \"comment favor failed\": \"评论点赞失败\",\n  \"delete comment favor failed\": \"评论取消点赞失败\",\n  \"get comments failed\": \"获取评论列表失败\",\n  \"create reply failed\": \"创建回复失败\",\n  \"reply favor failed\": \"回复点赞失败\",\n  \"delete reply favor failed\": \"删除回复点赞失败\",\n  \"get replies failed\": \"获取回复列表失败\"\n};\n\nexport default data;\n"]}
1
+{"version":3,"sources":["../../src/lang/index.js"],"names":["data"],"mappings":";;;;;AAAA;AACA;AACA,IAAMA,OAAO;AACX,eAAa,MADF;AAEX,iBAAe,MAFJ;AAGX,2BAAyB,QAHd;AAIX,0BAAwB,QAJb;AAKX,iCAA+B,UALpB;AAMX,yBAAuB,UANZ;AAOX,yBAAuB,QAPZ;AAQX,wBAAsB,QARX;AASX,+BAA6B,UATlB;AAUX,wBAAsB;AAVX,CAAb;;kBAaeA,I","file":"index.js","sourcesContent":["// 语言包\r\n// 英文短语和中文提示的对应\r\nconst data = {\r\n  \"not found\": \"没有数据\",\r\n  \"auth failed\": \"请先登录\",\r\n  \"create comment failed\": \"创建评论失败\",\r\n  \"comment favor failed\": \"评论点赞失败\",\r\n  \"delete comment favor failed\": \"评论取消点赞失败\",\r\n  \"get comments failed\": \"获取评论列表失败\",\r\n  \"create reply failed\": \"创建回复失败\",\r\n  \"reply favor failed\": \"回复点赞失败\",\r\n  \"delete reply favor failed\": \"删除回复点赞失败\",\r\n  \"get replies failed\": \"获取回复列表失败\"\r\n};\r\n\r\nexport default data;\r\n"]}

+ 1
- 1
package.json Näytä tiedosto

@@ -1,6 +1,6 @@
1 1
 {
2 2
   "name": "comment",
3
-  "version": "0.5.1",
3
+  "version": "0.5.2",
4 4
   "main": "lib/App.js",
5 5
   "description": "通用评论",
6 6
   "keywords": [

+ 30
- 18
src/App.js Näytä tiedosto

@@ -50,6 +50,15 @@ class App extends Component {
50 50
 
51 51
   componentDidMount() {}
52 52
 
53
+  error(msg) {
54
+    if (this.props.showError) {
55
+      message.error(msg);
56
+    }
57
+    if (this.props.onError) {
58
+      this.props.onError(msg);
59
+    }
60
+  }
61
+
53 62
   /**
54 63
    * 改变 loading 状态
55 64
    * @param {string} key key
@@ -95,10 +104,10 @@ class App extends Component {
95 104
       })
96 105
       .catch(error => {
97 106
         if (error.response && error.response.data && error.response.data.msg) {
98
-          message.error(lang[error.response.data.msg] || ERROR_DEFAULT);
107
+          this.error(lang[error.response.data.msg] || ERROR_DEFAULT);
99 108
           return;
100 109
         }
101
-        message.error(lang[error.message] || ERROR_DEFAULT);
110
+        this.error(lang[error.message] || ERROR_DEFAULT);
102 111
       })
103 112
       .finally(() => {
104 113
         this.handleChangeLoading("sGetComment", false);
@@ -143,10 +152,10 @@ class App extends Component {
143 152
       })
144 153
       .catch(error => {
145 154
         if (error.response && error.response.data && error.response.data.msg) {
146
-          message.error(lang[error.response.data.msg] || ERROR_DEFAULT);
155
+          this.error(lang[error.response.data.msg] || ERROR_DEFAULT);
147 156
           return;
148 157
         }
149
-        message.error(lang[error.message] || ERROR_DEFAULT);
158
+        this.error(lang[error.message] || ERROR_DEFAULT);
150 159
       })
151 160
       .finally(() => {
152 161
         this.handleChangeLoading("sGetReply", false);
@@ -158,7 +167,7 @@ class App extends Component {
158 167
    * @param {object} {content} comment content
159 168
    */
160 169
   sCreateComment({ content } = {}, cb) {
161
-    if (!content) return message.error("评论内容不能为空 ");
170
+    if (!content) return this.error("评论内容不能为空 ");
162 171
     this.handleChangeLoading("sCreateComment", true);
163 172
     const { API, type, businessId } = this.props;
164 173
     this.axios(`${API}/comments`, {
@@ -187,10 +196,10 @@ class App extends Component {
187 196
       })
188 197
       .catch(error => {
189 198
         if (error.response && error.response.data && error.response.data.msg) {
190
-          message.error(lang[error.response.data.msg] || ERROR_DEFAULT);
199
+          this.error(lang[error.response.data.msg] || ERROR_DEFAULT);
191 200
           return;
192 201
         }
193
-        message.error(lang[error.message] || ERROR_DEFAULT);
202
+        this.error(lang[error.message] || ERROR_DEFAULT);
194 203
       })
195 204
       .finally(() => {
196 205
         this.handleChangeLoading("sCreateComment", false);
@@ -203,7 +212,7 @@ class App extends Component {
203 212
    * @param {object} data { comment_id, content, [reply_id] }
204 213
    */
205 214
   sCreateReply(data, cb) {
206
-    if (!data.content) return message.error("回复内容不能为空 ");
215
+    if (!data.content) return this.error("回复内容不能为空 ");
207 216
     this.handleChangeLoading("sCreateReply", true);
208 217
     const { API } = this.props;
209 218
     this.axios(`${API}/replies`, {
@@ -234,10 +243,10 @@ class App extends Component {
234 243
       })
235 244
       .catch(error => {
236 245
         if (error.response && error.response.data && error.response.data.msg) {
237
-          message.error(lang[error.response.data.msg] || ERROR_DEFAULT);
246
+          this.error(lang[error.response.data.msg] || ERROR_DEFAULT);
238 247
           return;
239 248
         }
240
-        message.error(lang[error.message] || ERROR_DEFAULT);
249
+        this.error(lang[error.message] || ERROR_DEFAULT);
241 250
       })
242 251
       .finally(() => {
243 252
         this.handleChangeLoading("sCreateReply", false);
@@ -272,10 +281,10 @@ class App extends Component {
272 281
       })
273 282
       .catch(error => {
274 283
         if (error.response && error.response.data && error.response.data.msg) {
275
-          message.error(lang[error.response.data.msg] || ERROR_DEFAULT);
284
+          this.error(lang[error.response.data.msg] || ERROR_DEFAULT);
276 285
           return;
277 286
         }
278
-        message.error(lang[error.message] || ERROR_DEFAULT);
287
+        this.error(lang[error.message] || ERROR_DEFAULT);
279 288
       })
280 289
       .finally(() => {
281 290
         this.handleChangeLoading("sCommentFavor", false);
@@ -320,10 +329,10 @@ class App extends Component {
320 329
       })
321 330
       .catch(error => {
322 331
         if (error.response && error.response.data && error.response.data.msg) {
323
-          message.error(lang[error.response.data.msg] || ERROR_DEFAULT);
332
+          this.error(lang[error.response.data.msg] || ERROR_DEFAULT);
324 333
           return;
325 334
         }
326
-        message.error(lang[error.message] || ERROR_DEFAULT);
335
+        this.error(lang[error.message] || ERROR_DEFAULT);
327 336
       })
328 337
       .finally(() => {
329 338
         this.handleChangeLoading("sReplyFavor", false);
@@ -343,10 +352,10 @@ class App extends Component {
343 352
       })
344 353
       .catch(error => {
345 354
         if (error.response && error.response.data && error.response.data.msg) {
346
-          message.error(lang[error.response.data.msg] || ERROR_DEFAULT);
355
+          this.error(lang[error.response.data.msg] || ERROR_DEFAULT);
347 356
           return;
348 357
         }
349
-        message.error(lang[error.message] || ERROR_DEFAULT);
358
+        this.error(lang[error.message] || ERROR_DEFAULT);
350 359
       })
351 360
       .finally(() => {
352 361
         this.handleChangeLoading("sOssSts", false);
@@ -392,7 +401,9 @@ App.propTypes = {
392 401
   showEditor: PropTypes.bool, // 是否显示评论输入框
393 402
   showAlertComment: PropTypes.bool, // 评论成功之后,是否通过 Antd 的 Message 组件进行提示
394 403
   showAlertReply: PropTypes.bool, // 回复成功之后,是否通过 Antd 的 Message 组件进行提示
395
-  showAlertFavor: PropTypes.bool // 点赞/取消点赞成功之后,是否通过 Antd 的 Message 组件进行提示
404
+  showAlertFavor: PropTypes.bool, // 点赞/取消点赞成功之后,是否通过 Antd 的 Message 组件进行提示
405
+  showError: PropTypes.bool, // 是否使用Antd的Message组件提示错误信息
406
+  onError: PropTypes.func // 错误回调, 出错了会被调用
396 407
 };
397 408
 
398 409
 App.defaultProps = {
@@ -401,7 +412,8 @@ App.defaultProps = {
401 412
   showEditor: true,
402 413
   showAlertComment: false,
403 414
   showAlertReply: false,
404
-  showAlertFavor: false
415
+  showAlertFavor: false,
416
+  showError: true
405 417
 };
406 418
 
407 419
 export { Editor, RenderText };

+ 7
- 1
src/components/Editor/Upload.js Näytä tiedosto

@@ -88,7 +88,13 @@ class App extends React.Component {
88 88
           this.props.onUpload({ path: data.name, uid: file.uid });
89 89
         })
90 90
         .catch(e => {
91
-          message.error(e.message || ERROR_DEFAULT);
91
+          const msg = e.message || ERROR_DEFAULT;
92
+          if (this.props.showError) {
93
+            message.error(msg);
94
+          }
95
+          if (this.props.onError) {
96
+            this.props.onError(msg);
97
+          }
92 98
           info.onError(e);
93 99
         });
94 100
     };

+ 20
- 5
src/components/Editor/index.js Näytä tiedosto

@@ -102,9 +102,18 @@ class Editor extends React.Component {
102 102
         files.push(`${OSS_LINK}${fileMap[item.uid]}`);
103 103
       });
104 104
     }
105
-    this.props.onSubmit({ text: value, files }, () => {
106
-      this.resetState();
107
-    });
105
+    let canSubmit = true;
106
+    if (this.props.beforeSubmit) {
107
+      canSubmit =
108
+        this.props.beforeSubmit({ text: value, files }) === false
109
+          ? false
110
+          : true;
111
+    }
112
+    if (canSubmit) {
113
+      this.props.onSubmit({ text: value, files }, () => {
114
+        this.resetState();
115
+      });
116
+    }
108 117
   }
109 118
 
110 119
   resetState() {
@@ -239,6 +248,8 @@ class Editor extends React.Component {
239 248
                         onUpload={this.handleUpload}
240 249
                         maxUpload={maxUpload}
241 250
                         fileList={this.state.fileList}
251
+                        showError={this.props.showError}
252
+                        onError={this.props.onError}
242 253
                       />
243 254
                     </div>
244 255
                   }
@@ -314,12 +325,15 @@ Editor.propTypes = {
314 325
   value: PropTypes.string,
315 326
   onChange: PropTypes.func,
316 327
   onSubmit: PropTypes.func,
328
+  beforeSubmit: PropTypes.func,
317 329
   btnSubmitText: PropTypes.string,
318 330
   btnLoading: PropTypes.bool,
319 331
   btnDisabled: PropTypes.bool,
320 332
   button: PropTypes.node,
321 333
   emojiToolIcon: PropTypes.node,
322
-  imageToolIcon: PropTypes.node
334
+  imageToolIcon: PropTypes.node,
335
+  showError: PropTypes.bool,
336
+  onError: PropTypes.func
323 337
 };
324 338
 
325 339
 Editor.defaultProps = {
@@ -331,7 +345,8 @@ Editor.defaultProps = {
331 345
   maxUpload: 1,
332 346
   btnSubmitText: "发表",
333 347
   btnLoading: false,
334
-  btnDisabled: false
348
+  btnDisabled: false,
349
+  showError: true
335 350
 };
336 351
 
337 352
 export default Editor;

+ 21
- 2
src/index.js Näytä tiedosto

@@ -34,8 +34,27 @@ class Index extends Component {
34 34
   render() {
35 35
     // 最简单的用法
36 36
     return (
37
-      <App type={1} businessId="test">
38
-        <Editor maxUpload={4} />
37
+      <App
38
+        type={1}
39
+        businessId="test"
40
+        showAlertComment
41
+        showAlertReply
42
+        showAlertFavor
43
+        showError={false}
44
+        onError={msg => {
45
+          console.log(`-----------${msg}`);
46
+        }}
47
+      >
48
+        <Editor
49
+          maxUpload={4}
50
+          beforeSubmit={() => {
51
+            return true;
52
+          }}
53
+          showError={false}
54
+          onError={msg => {
55
+            console.log(`-----------${msg}`);
56
+          }}
57
+        />
39 58
       </App>
40 59
     );
41 60