Kaynağa Gözat

app增加onCountChange回调

narrowizard 5 yıl önce
ebeveyn
işleme
8d549fb870

+ 3
- 0
CHANGELOG.md Dosyayı Görüntüle

1
 # CHANGELOG
1
 # CHANGELOG
2
 
2
 
3
+## 1.0.2
4
+- [x] App增加onCountChange回调
5
+
3
 ## 1.0.1
6
 ## 1.0.1
4
 - [x] App增加business_user_id属性
7
 - [x] App增加business_user_id属性
5
 
8
 

+ 24
- 23
README.md Dosyayı Görüntüle

2
 
2
 
3
 通用评论系统及编辑器
3
 通用评论系统及编辑器
4
 
4
 
5
-**`version 0.5.14`**
5
+**`version 1.0.2`**
6
 
6
 
7
 ```js
7
 ```js
8
 import Comment, { Editor, RenderText } from 'comment';
8
 import Comment, { Editor, RenderText } from 'comment';
188
 - 标记了`deprecated`的配置项表示不推荐使用,并且可能在将来版本中不再受支持。
188
 - 标记了`deprecated`的配置项表示不推荐使用,并且可能在将来版本中不再受支持。
189
 
189
 
190
 
190
 
191
-| props             | type           | default                            | required | description                                       |                          |
192
-|-------------------|----------------|------------------------------------|----------|---------------------------------------------------|--------------------------|
193
-| type              | number         |                                    | true     | 评论的 type                                          |                          |
194
-| businessId        | string         |                                    | true     | 评论的 business id                                   |                          |
195
-| API               | string         | http://api.links123.net/comment/v1 | false    | API 前缀                                            |                          |
196
-| showList          | boolean        | true                               | false    | 是否显示评论列表                                          |                          |
197
-| showEditor        | boolean        | true                               | false    | 是否显示评论输入框                                         |                          |
198
-| showAlertComment  | boolean        | false                              | false    | 评论成功之后,是否通过 Antd 的 Message 组件进行提示                 |                          |
199
-| showAlertReply    | boolean        | false                              | false    | 回复成功之后,是否通过 Antd 的 Message 组件进行提示                 |                          |
200
-| showAlertFavor    | boolean        | false                              | false    | 点赞/取消点赞成功之后,是否通过 Antd 的 Message 组件进行提示            |                          |
201
-| showError         | boolean        | true                               | false    | 是否使用Antd的Message组件提示错误信息                          |                          |
202
-| onError           | function(msg)  |                                    | false    | 错误回调, 出错了会被调用                                     |                          |
203
-| userId            | number         |                                    | false    | 用户id, comment内部不维护用户id, 调用组件时传递过来, 目前用于判断是否显示删除按钮 |                          |
204
-| token             | string         |                                    | false    | [deprecated] token,用于身份认证,非必须。默认使用 cookie         |                          |
205
-| pageType          | string         | more                               | false    | 分页类别, more-加载更多 pagination-页码                     |                          |
206
-| page              | number         |                                    | false    | 页码受控模式,如果传递了此参数,则需要通过onPageChange回调手动维护page.      |                          |
207
-| limit             | number         | 10                                 | false    | 一次加载的评论数量                                         |                          |
208
-| onGetMoreBtnClick | function()     |                                    | false    | 点击查看更多按钮的回调                                       |                          |
209
-| onPageChange      | function(page) |                                    | false    | 页码发生变化时的回调,注意:分页数据获取还是在组件内部处理的                    |                          |
210
-| onDelete          | function(type) |                                    | false    | 评论或回复删除成功后的回调, type: "comment" \                  | "reply" , 用于区分删除的是评论还是回复 |
211
-| locales           | string         | 语言                                 | false    |                                                   |                          |
212
-| businessUserId    | number         |                                    | false    | 评论目标的用户id, 用于发送通知                                 |                          |
191
+| props             | type            | default                            | required | description                                       |                          |
192
+|-------------------|-----------------|------------------------------------|----------|---------------------------------------------------|--------------------------|
193
+| type              | number          |                                    | true     | 评论的 type                                          |                          |
194
+| businessId        | string          |                                    | true     | 评论的 business id                                   |                          |
195
+| API               | string          | http://api.links123.net/comment/v1 | false    | API 前缀                                            |                          |
196
+| showList          | boolean         | true                               | false    | 是否显示评论列表                                          |                          |
197
+| showEditor        | boolean         | true                               | false    | 是否显示评论输入框                                         |                          |
198
+| showAlertComment  | boolean         | false                              | false    | 评论成功之后,是否通过 Antd 的 Message 组件进行提示                 |                          |
199
+| showAlertReply    | boolean         | false                              | false    | 回复成功之后,是否通过 Antd 的 Message 组件进行提示                 |                          |
200
+| showAlertFavor    | boolean         | false                              | false    | 点赞/取消点赞成功之后,是否通过 Antd 的 Message 组件进行提示            |                          |
201
+| showError         | boolean         | true                               | false    | 是否使用Antd的Message组件提示错误信息                          |                          |
202
+| onError           | function(msg)   |                                    | false    | 错误回调, 出错了会被调用                                     |                          |
203
+| userId            | number          |                                    | false    | 用户id, comment内部不维护用户id, 调用组件时传递过来, 目前用于判断是否显示删除按钮 |                          |
204
+| token             | string          |                                    | false    | [deprecated] token,用于身份认证,非必须。默认使用 cookie         |                          |
205
+| pageType          | string          | more                               | false    | 分页类别, more-加载更多 pagination-页码                     |                          |
206
+| page              | number          |                                    | false    | 页码受控模式,如果传递了此参数,则需要通过onPageChange回调手动维护page.      |                          |
207
+| limit             | number          | 10                                 | false    | 一次加载的评论数量                                         |                          |
208
+| onGetMoreBtnClick | function()      |                                    | false    | 点击查看更多按钮的回调                                       |                          |
209
+| onPageChange      | function(page)  |                                    | false    | 页码发生变化时的回调,注意:分页数据获取还是在组件内部处理的                    |                          |
210
+| onDelete          | function(type)  |                                    | false    | 评论或回复删除成功后的回调, type: "comment" \                  | "reply" , 用于区分删除的是评论还是回复 |
211
+| locales           | string          | 语言                                 | false    |                                                   |                          |
212
+| businessUserId    | number          |                                    | false    | 评论目标的用户id, 用于发送通知                                 |                          |
213
+| onCountChange     | function(count) |                                    | false    | 评论数量发生变更时的回调(初次获取也会调用)                            |                          |
213
 
214
 
214
 ## Editor
215
 ## Editor
215
 
216
 

+ 1
- 1
assets/example.html Dosyayı Görüntüle

20
   </div>
20
   </div>
21
   
21
   
22
   <script src="http://gosspublic.alicdn.com/aliyun-oss-sdk.min.js"></script>
22
   <script src="http://gosspublic.alicdn.com/aliyun-oss-sdk.min.js"></script>
23
-  <script type="text/javascript" src="./static/js/main.d5cd277c.js"></script>
23
+  <script type="text/javascript" src="./static/js/main.8d850e35.js"></script>
24
   <script type="text/javascript" src="example.js"></script>
24
   <script type="text/javascript" src="example.js"></script>
25
 </body>
25
 </body>
26
 </html>
26
 </html>

+ 2
- 0
assets/static/js/main.8d850e35.js
Dosya farkı çok büyük olduğundan ihmal edildi
Dosyayı Görüntüle


+ 1
- 0
assets/static/js/main.8d850e35.js.map
Dosya farkı çok büyük olduğundan ihmal edildi
Dosyayı Görüntüle


+ 0
- 2
assets/static/js/main.d5cd277c.js
Dosya farkı çok büyük olduğundan ihmal edildi
Dosyayı Görüntüle


+ 0
- 1
assets/static/js/main.d5cd277c.js.map
Dosya farkı çok büyük olduğundan ihmal edildi
Dosyayı Görüntüle


+ 7
- 2
lib/App.js Dosyayı Görüntüle

254
             page: page,
254
             page: page,
255
             total: total
255
             total: total
256
           });
256
           });
257
+          _this3.props.onCountChange(total);
257
         } else {
258
         } else {
258
           _message3.default.info(_reactIntlUniversal2.default.get("message.noMoreComment"));
259
           _message3.default.info(_reactIntlUniversal2.default.get("message.noMoreComment"));
259
           _this3.setState({
260
           _this3.setState({
364
           isTemporary: true // 临时的数据
365
           isTemporary: true // 临时的数据
365
         }));
366
         }));
366
         _this5.setState({ list: list, total: total + 1 });
367
         _this5.setState({ list: list, total: total + 1 });
368
+        _this5.props.onCountChange(total + 1);
367
       }).catch(this.errorHandler).finally(function () {
369
       }).catch(this.errorHandler).finally(function () {
368
         _this5.handleChangeLoading("sCreateComment", false);
370
         _this5.handleChangeLoading("sCreateComment", false);
369
       });
371
       });
394
         });
396
         });
395
         _this6.setState({ list: res, total: total - 1 });
397
         _this6.setState({ list: res, total: total - 1 });
396
         _this6.props.onDelete(_constant.COMMENT_TYPE.COMMENT);
398
         _this6.props.onDelete(_constant.COMMENT_TYPE.COMMENT);
399
+        _this6.props.onCountChange(total - 1);
397
       }).catch(this.errorHandler).finally(function () {
400
       }).catch(this.errorHandler).finally(function () {
398
         _this6.handleChangeLoading("sDeleteComment", false);
401
         _this6.handleChangeLoading("sDeleteComment", false);
399
       });
402
       });
630
   onPageChange: _propTypes2.default.func, // 页码变化回调
633
   onPageChange: _propTypes2.default.func, // 页码变化回调
631
   onGetMoreBtnClick: _propTypes2.default.func, // 点击查看更多按钮回调
634
   onGetMoreBtnClick: _propTypes2.default.func, // 点击查看更多按钮回调
632
   onDelete: _propTypes2.default.func,
635
   onDelete: _propTypes2.default.func,
633
-  locales: _propTypes2.default.string //  传入的语言环境, en-US/zh-CN
636
+  locales: _propTypes2.default.string, //  传入的语言环境, en-US/zh-CN
637
+  onCountChange: _propTypes2.default.func // 评论数量变更时的回调
634
 };
638
 };
635
 
639
 
636
 App.defaultProps = {
640
 App.defaultProps = {
646
   limit: _constant.LIMIT,
650
   limit: _constant.LIMIT,
647
   onGetMoreBtnClick: function onGetMoreBtnClick() {},
651
   onGetMoreBtnClick: function onGetMoreBtnClick() {},
648
   onPageChange: function onPageChange(page) {},
652
   onPageChange: function onPageChange(page) {},
649
-  onDelete: function onDelete() {}
653
+  onDelete: function onDelete() {},
654
+  onCountChange: function onCountChange() {}
650
 };
655
 };
651
 
656
 
652
 exports.Editor = _Editor2.default;
657
 exports.Editor = _Editor2.default;

+ 1
- 1
lib/App.js.map
Dosya farkı çok büyük olduğundan ihmal edildi
Dosyayı Görüntüle


+ 5
- 1
lib/index.js Dosyayı Görüntüle

62
   id: "root-comment",
62
   id: "root-comment",
63
   type: 1,
63
   type: 1,
64
   businessId: "test",
64
   businessId: "test",
65
-  businessUserId: 4
65
+  businessUserId: 4,
66
+  userId: 71299,
67
+  onCountChange: function onCountChange(c) {
68
+    console.log(c);
69
+  }
66
 });
70
 });
67
 
71
 
68
 // renderComment({
72
 // renderComment({

+ 1
- 1
lib/index.js.map Dosyayı Görüntüle

1
-{"version":3,"sources":["../src/index.js"],"names":["Index","props","editorProps","renderComment","config","id","Error","type","businessId","console","warn","API","ReactDOM","render","document","getElementById","window","businessUserId"],"mappings":";;;;AAAA;;;;AACA;;;;AACA;;;;;;AACA;;AAEA,IAAMA,QAAQ,SAARA,KAAQ;AAAA,SACZ;AAAC,iBAAD;AAAA,eAAK,sBAAL,EAAsB,oBAAtB,EAAqC,oBAArC,EAAoD,eAApD,IAAkEC,KAAlE;AACE,kCAAC,WAAD,aAAQ,WAAW,CAAnB,EAAsB,eAAtB,IAAoCA,MAAMC,WAA1C;AADF,GADY;AAAA,CAAd;;AAMA;;;;;;;;AAQA,SAASC,aAAT,CAAuBC,MAAvB,EAA+B;AAC7B,MAAI,CAACA,OAAOC,EAAZ,EAAgB;AACd,UAAM,IAAIC,KAAJ,CAAU,gBAAV,CAAN;AACD;AACD,MAAI,CAACF,OAAOG,IAAZ,EAAkB;AAChB,UAAM,IAAID,KAAJ,CAAU,kBAAV,CAAN;AACD;AACD,MAAI,CAACF,OAAOI,UAAZ,EAAwB;AACtB;AACAJ,WAAOI,UAAP,GAAoB,MAApB;AACAC,YAAQC,IAAR,CAAa,+BAAb;AACD;AACD,MAAI,CAACN,OAAOO,GAAZ,EAAiB;AACf;AACAP,WAAOO,GAAP,GAAa,oCAAb;AACAF,YAAQC,IAAR,CACE,sDADF;AAGD;;AAEDE,qBAASC,MAAT,CAAgB,8BAAC,KAAD,EAAWT,MAAX,CAAhB,EAAuCU,SAASC,cAAT,CAAwBX,OAAOC,EAA/B,CAAvC;AACA;AACD;;AAEDW,OAAOb,aAAP,GAAuBA,aAAvB;;AAEAA,cAAc;AACZE,MAAI,cADQ;AAEZE,QAAM,CAFM;AAGZC,cAAY,MAHA;AAIZS,kBAAgB;AAJJ,CAAd;;AAOA;AACA;AACA;AACA;AACA;AACA","file":"index.js","sourcesContent":["import React from \"react\";\r\nimport ReactDOM from \"react-dom\";\r\nimport App, { Editor } from \"./App\";\r\n// import registerServiceWorker from \"./registerServiceWorker\";\r\n\r\nconst Index = props => (\r\n  <App showAlertComment showAlertReply showAlertFavor showError {...props}>\r\n    <Editor maxUpload={9} autoFocus {...props.editorProps} />\r\n  </App>\r\n);\r\n\r\n/**\r\n * 渲染评论组件\r\n * @param {object} config 编辑器配置\r\n *  - {string} id 渲染评论的DOM的 ID\r\n *  - {number} type 评论的 type\r\n *  - {string} businessId 评论的 businessId\r\n *  - {string} API, API 前缀, 默认 http://api.links123.net/comment/v1\r\n */\r\nfunction renderComment(config) {\r\n  if (!config.id) {\r\n    throw new Error(\"id is required\");\r\n  }\r\n  if (!config.type) {\r\n    throw new Error(\"type is required\");\r\n  }\r\n  if (!config.businessId) {\r\n    // throw new Error(\"businessId is required\");\r\n    config.businessId = \"test\";\r\n    console.warn(\"没有传入 businessId 参数,默认使用: test\");\r\n  }\r\n  if (!config.API) {\r\n    // throw new Error(\"API is required\");\r\n    config.API = \"http://api.links123.net/comment/v1\";\r\n    console.warn(\r\n      \"没有传入 API 参数,默认使用: http://api.links123.net/comment/v1\"\r\n    );\r\n  }\r\n\r\n  ReactDOM.render(<Index {...config} />, document.getElementById(config.id));\r\n  // registerServiceWorker();\r\n}\r\n\r\nwindow.renderComment = renderComment;\r\n\r\nrenderComment({\r\n  id: \"root-comment\",\r\n  type: 1,\r\n  businessId: \"test\",\r\n  businessUserId: 4,\r\n});\r\n\r\n// renderComment({\r\n//   id: \"root-comment\",\r\n//   type: 1,\r\n//   businessId: \"test\",\r\n//   API: 'http://api.links123.net/comment/v1',\r\n// });\r\n"]}
1
+{"version":3,"sources":["../src/index.js"],"names":["Index","props","editorProps","renderComment","config","id","Error","type","businessId","console","warn","API","ReactDOM","render","document","getElementById","window","businessUserId","userId","onCountChange","c","log"],"mappings":";;;;AAAA;;;;AACA;;;;AACA;;;;;;AACA;;AAEA,IAAMA,QAAQ,SAARA,KAAQ;AAAA,SACZ;AAAC,iBAAD;AAAA,eAAK,sBAAL,EAAsB,oBAAtB,EAAqC,oBAArC,EAAoD,eAApD,IAAkEC,KAAlE;AACE,kCAAC,WAAD,aAAQ,WAAW,CAAnB,EAAsB,eAAtB,IAAoCA,MAAMC,WAA1C;AADF,GADY;AAAA,CAAd;;AAMA;;;;;;;;AAQA,SAASC,aAAT,CAAuBC,MAAvB,EAA+B;AAC7B,MAAI,CAACA,OAAOC,EAAZ,EAAgB;AACd,UAAM,IAAIC,KAAJ,CAAU,gBAAV,CAAN;AACD;AACD,MAAI,CAACF,OAAOG,IAAZ,EAAkB;AAChB,UAAM,IAAID,KAAJ,CAAU,kBAAV,CAAN;AACD;AACD,MAAI,CAACF,OAAOI,UAAZ,EAAwB;AACtB;AACAJ,WAAOI,UAAP,GAAoB,MAApB;AACAC,YAAQC,IAAR,CAAa,+BAAb;AACD;AACD,MAAI,CAACN,OAAOO,GAAZ,EAAiB;AACf;AACAP,WAAOO,GAAP,GAAa,oCAAb;AACAF,YAAQC,IAAR,CACE,sDADF;AAGD;;AAEDE,qBAASC,MAAT,CAAgB,8BAAC,KAAD,EAAWT,MAAX,CAAhB,EAAuCU,SAASC,cAAT,CAAwBX,OAAOC,EAA/B,CAAvC;AACA;AACD;;AAEDW,OAAOb,aAAP,GAAuBA,aAAvB;;AAEAA,cAAc;AACZE,MAAI,cADQ;AAEZE,QAAM,CAFM;AAGZC,cAAY,MAHA;AAIZS,kBAAgB,CAJJ;AAKZC,UAAQ,KALI;AAMZC,iBAAe,uBAACC,CAAD,EAAO;AAAEX,YAAQY,GAAR,CAAYD,CAAZ;AAAgB;AAN5B,CAAd;;AASA;AACA;AACA;AACA;AACA;AACA","file":"index.js","sourcesContent":["import React from \"react\";\r\nimport ReactDOM from \"react-dom\";\r\nimport App, { Editor } from \"./App\";\r\n// import registerServiceWorker from \"./registerServiceWorker\";\r\n\r\nconst Index = props => (\r\n  <App showAlertComment showAlertReply showAlertFavor showError {...props}>\r\n    <Editor maxUpload={9} autoFocus {...props.editorProps} />\r\n  </App>\r\n);\r\n\r\n/**\r\n * 渲染评论组件\r\n * @param {object} config 编辑器配置\r\n *  - {string} id 渲染评论的DOM的 ID\r\n *  - {number} type 评论的 type\r\n *  - {string} businessId 评论的 businessId\r\n *  - {string} API, API 前缀, 默认 http://api.links123.net/comment/v1\r\n */\r\nfunction renderComment(config) {\r\n  if (!config.id) {\r\n    throw new Error(\"id is required\");\r\n  }\r\n  if (!config.type) {\r\n    throw new Error(\"type is required\");\r\n  }\r\n  if (!config.businessId) {\r\n    // throw new Error(\"businessId is required\");\r\n    config.businessId = \"test\";\r\n    console.warn(\"没有传入 businessId 参数,默认使用: test\");\r\n  }\r\n  if (!config.API) {\r\n    // throw new Error(\"API is required\");\r\n    config.API = \"http://api.links123.net/comment/v1\";\r\n    console.warn(\r\n      \"没有传入 API 参数,默认使用: http://api.links123.net/comment/v1\"\r\n    );\r\n  }\r\n\r\n  ReactDOM.render(<Index {...config} />, document.getElementById(config.id));\r\n  // registerServiceWorker();\r\n}\r\n\r\nwindow.renderComment = renderComment;\r\n\r\nrenderComment({\r\n  id: \"root-comment\",\r\n  type: 1,\r\n  businessId: \"test\",\r\n  businessUserId: 4,\r\n  userId: 71299,\r\n  onCountChange: (c) => { console.log(c) }\r\n});\r\n\r\n// renderComment({\r\n//   id: \"root-comment\",\r\n//   type: 1,\r\n//   businessId: \"test\",\r\n//   API: 'http://api.links123.net/comment/v1',\r\n// });\r\n"]}

+ 1
- 1
package.json Dosyayı Görüntüle

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

+ 7
- 2
src/App.js Dosyayı Görüntüle

158
             page,
158
             page,
159
             total
159
             total
160
           });
160
           });
161
+          this.props.onCountChange(total);
161
         } else {
162
         } else {
162
           message.info(intl.get("message.noMoreComment"));
163
           message.info(intl.get("message.noMoreComment"));
163
           this.setState({
164
           this.setState({
245
           isTemporary: true // 临时的数据
246
           isTemporary: true // 临时的数据
246
         });
247
         });
247
         this.setState({ list, total: total + 1 });
248
         this.setState({ list, total: total + 1 });
249
+        this.props.onCountChange(total + 1);
248
       })
250
       })
249
       .catch(this.errorHandler)
251
       .catch(this.errorHandler)
250
       .finally(() => {
252
       .finally(() => {
267
         const res = list.filter(item => item.id !== commentId);
269
         const res = list.filter(item => item.id !== commentId);
268
         this.setState({ list: res, total: total - 1 });
270
         this.setState({ list: res, total: total - 1 });
269
         this.props.onDelete(COMMENT_TYPE.COMMENT);
271
         this.props.onDelete(COMMENT_TYPE.COMMENT);
272
+        this.props.onCountChange(total - 1);
270
       })
273
       })
271
       .catch(this.errorHandler)
274
       .catch(this.errorHandler)
272
       .finally(() => {
275
       .finally(() => {
498
   onPageChange: PropTypes.func, // 页码变化回调
501
   onPageChange: PropTypes.func, // 页码变化回调
499
   onGetMoreBtnClick: PropTypes.func, // 点击查看更多按钮回调
502
   onGetMoreBtnClick: PropTypes.func, // 点击查看更多按钮回调
500
   onDelete: PropTypes.func,
503
   onDelete: PropTypes.func,
501
-  locales: PropTypes.string //  传入的语言环境, en-US/zh-CN
504
+  locales: PropTypes.string, //  传入的语言环境, en-US/zh-CN
505
+  onCountChange: PropTypes.func // 评论数量变更时的回调
502
 };
506
 };
503
 
507
 
504
 App.defaultProps = {
508
 App.defaultProps = {
514
   limit: LIMIT,
518
   limit: LIMIT,
515
   onGetMoreBtnClick: () => {},
519
   onGetMoreBtnClick: () => {},
516
   onPageChange: page => {},
520
   onPageChange: page => {},
517
-  onDelete: () => {}
521
+  onDelete: () => {},
522
+  onCountChange: () => {}
518
 };
523
 };
519
 
524
 
520
 export { Editor, RenderText };
525
 export { Editor, RenderText };

+ 5
- 1
src/index.js Dosyayı Görüntüle

47
   id: "root-comment",
47
   id: "root-comment",
48
   type: 1,
48
   type: 1,
49
   businessId: "test",
49
   businessId: "test",
50
-  businessUserId: 4
50
+  businessUserId: 4,
51
+  userId: 71299,
52
+  onCountChange: c => {
53
+    console.log(c);
54
+  }
51
 });
55
 });
52
 
56
 
53
 // renderComment({
57
 // renderComment({