Browse Source

分页器受控模式

narro 6 years ago
parent
commit
d2c6e51b95

+ 4
- 0
CHANGELOG.md View File

1
 # CHANGELOG
1
 # CHANGELOG
2
 
2
 
3
+## 0.5.12
4
+- [x] 支持两种模式的分页器
5
+- [x] 分页器支持受控模式
6
+
3
 ## 0.5.11
7
 ## 0.5.11
4
 - [x] 增加链接解析功能
8
 - [x] 增加链接解析功能
5
 
9
 

+ 18
- 16
README.md View File

2
 
2
 
3
 通用评论系统及编辑器
3
 通用评论系统及编辑器
4
 
4
 
5
-**`version 0.5.11`**
5
+**`version 0.5.12`**
6
 
6
 
7
 ```js
7
 ```js
8
 import Comment, { Editor, RenderText } from 'comment';
8
 import Comment, { Editor, RenderText } from 'comment';
13
 ## Comment
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
-| showError        | boolean       | true                               | false    | 是否使用Antd的Message组件提示错误信息                                             |
27
-| onError          | function(msg) |                                    | false    | 错误回调, 出错了会被调用                                                          |
28
-| userId           | number        |                                    | false    | 用户id, comment内部不维护用户id, 调用组件时传递过来, 目前用于判断是否显示删除按钮 |
29
-| token            | string        |                                    | false    | [deprecated] token,用于身份认证,非必须。默认使用 cookie                         |
30
-| pageType         | string        | more                               | false    | 分页类别, more-加载更多 pagination-页码                                          |
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
+| userId           | number         |                                    | false    | 用户id, comment内部不维护用户id, 调用组件时传递过来, 目前用于判断是否显示删除按钮 |
29
+| token            | string         |                                    | false    | [deprecated] token,用于身份认证,非必须。默认使用 cookie                         |
30
+| pageType         | string         | more                               | false    | 分页类别, more-加载更多 pagination-页码                                          |
31
+| page             | number         |                                    | false    | 页码受控模式,如果传递了此参数,则需要通过onPageChange回调手动维护page.             |
32
+| onPageChange     | function(page) |                                    | false    | 页码发生变化时的回调,注意:分页数据获取还是在组件内部处理的                        |
31
 
33
 
32
 
34
 
33
 ## Editor
35
 ## Editor

+ 2
- 2
lib/App.css View File

4
   margin-bottom: 100px;
4
   margin-bottom: 100px;
5
 }
5
 }
6
 
6
 
7
-.comment .ant-spin-nested-loading>div>.ant-spin .ant-spin-dot {
7
+.comment .ant-spin-nested-loading > div > .ant-spin .ant-spin-dot {
8
   position: fixed;
8
   position: fixed;
9
   top: 45%;
9
   top: 45%;
10
 }
10
 }
27
 
27
 
28
 .comment-img {
28
 .comment-img {
29
   max-width: 100%;
29
   max-width: 100%;
30
-}
30
+}

+ 7
- 4
lib/App.js View File

182
           var newList = list;
182
           var newList = list;
183
           var oldList = _this2.state.list;
183
           var oldList = _this2.state.list;
184
 
184
 
185
-          if (pageType === 'more') {
185
+          if (pageType === "more") {
186
             if (page > 1) {
186
             if (page > 1) {
187
               // 删除临时数据
187
               // 删除临时数据
188
               oldList = oldList.filter(function (o) {
188
               oldList = oldList.filter(function (o) {
190
               });
190
               });
191
               newList = oldList.concat(newList);
191
               newList = oldList.concat(newList);
192
             }
192
             }
193
-          } else if (pageType === 'pagination') {
193
+          } else if (pageType === "pagination") {
194
             // TODO 滚动到顶部
194
             // TODO 滚动到顶部
195
             window.scrollTo(0, 0);
195
             window.scrollTo(0, 0);
196
           }
196
           }
563
   showError: _propTypes2.default.bool, // 是否使用Antd的Message组件提示错误信息
563
   showError: _propTypes2.default.bool, // 是否使用Antd的Message组件提示错误信息
564
   onError: _propTypes2.default.func, // 错误回调, 出错了会被调用
564
   onError: _propTypes2.default.func, // 错误回调, 出错了会被调用
565
   userId: _propTypes2.default.number, // 用户id, comment内部不维护用户id, 调用组件时传递过来, 目前用于判断是否显示删除按钮
565
   userId: _propTypes2.default.number, // 用户id, comment内部不维护用户id, 调用组件时传递过来, 目前用于判断是否显示删除按钮
566
-  pageType: _propTypes2.default.string // 分页类型
566
+  pageType: _propTypes2.default.string, // 分页类型
567
+  page: _propTypes2.default.number, // 页码
568
+  onPageChange: _propTypes2.default.func // 页码变化回调
567
 };
569
 };
568
 
570
 
569
 App.defaultProps = {
571
 App.defaultProps = {
574
   showAlertReply: false,
576
   showAlertReply: false,
575
   showAlertFavor: false,
577
   showAlertFavor: false,
576
   showError: true,
578
   showError: true,
577
-  pageType: "more"
579
+  pageType: "more",
580
+  onPageChange: function onPageChange(page) {}
578
 };
581
 };
579
 
582
 
580
 exports.Editor = _Editor2.default;
583
 exports.Editor = _Editor2.default;

+ 1
- 1
lib/App.js.map
File diff suppressed because it is too large
View File


+ 1
- 1
lib/components/CommentList/index.css View File

16
 
16
 
17
 .comment-list-pagination {
17
 .comment-list-pagination {
18
   text-align: center;
18
   text-align: center;
19
-}
19
+}

+ 8
- 5
lib/components/CommentList/index.js View File

57
   _createClass(CommentList, [{
57
   _createClass(CommentList, [{
58
     key: "componentWillMount",
58
     key: "componentWillMount",
59
     value: function componentWillMount() {
59
     value: function componentWillMount() {
60
-      this.props.app.sGetComment();
60
+      this.props.app.sGetComment({ page: this.props.app.page });
61
     }
61
     }
62
   }, {
62
   }, {
63
     key: "renderPagination",
63
     key: "renderPagination",
68
           page = _props$app.page,
68
           page = _props$app.page,
69
           pageType = _props$app.pageType,
69
           pageType = _props$app.pageType,
70
           isNoMoreComment = _props$app.isNoMoreComment,
70
           isNoMoreComment = _props$app.isNoMoreComment,
71
-          sGetComment = _props$app.sGetComment;
71
+          sGetComment = _props$app.sGetComment,
72
+          onPageChange = _props$app.onPageChange;
72
 
73
 
73
-      if (pageType === 'more') {
74
+      if (pageType === "more") {
74
         if (!isNoMoreComment && list.length !== total) {
75
         if (!isNoMoreComment && list.length !== total) {
75
           return _react2.default.createElement(
76
           return _react2.default.createElement(
76
             "div",
77
             "div",
77
             {
78
             {
78
               className: "comment-list-show-more",
79
               className: "comment-list-show-more",
79
               onClick: function onClick() {
80
               onClick: function onClick() {
80
-                return sGetComment({ page: page + 1 });
81
+                sGetComment({ page: page + 1 });
82
+                onPageChange(page + 1);
81
               }
83
               }
82
             },
84
             },
83
             _react2.default.createElement(
85
             _react2.default.createElement(
89
         } else {
91
         } else {
90
           return null;
92
           return null;
91
         }
93
         }
92
-      } else if (pageType === 'pagination') {
94
+      } else if (pageType === "pagination") {
93
         return _react2.default.createElement(
95
         return _react2.default.createElement(
94
           "div",
96
           "div",
95
           { className: "comment-list-pagination" },
97
           { className: "comment-list-pagination" },
99
             total: total,
101
             total: total,
100
             onChange: function onChange(p) {
102
             onChange: function onChange(p) {
101
               sGetComment({ page: p });
103
               sGetComment({ page: p });
104
+              onPageChange(p);
102
             }
105
             }
103
           })
106
           })
104
         );
107
         );

+ 1
- 1
lib/components/CommentList/index.js.map View File

1
-{"version":3,"sources":["../../../src/components/CommentList/index.js"],"names":["CommentList","props","state","app","sGetComment","list","total","page","pageType","isNoMoreComment","length","LIMIT","p","loading","spinning","Boolean","sCommentFavor","sReplyFavor","map","item","id","renderPagination","Component","propTypes"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;;;;AAEA;;;;AACA;;;;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;;;uCAEkB;AAAA,uBAQb,KAAKH,KAAL,CAAWE,GARE;AAAA,UAEfE,IAFe,cAEfA,IAFe;AAAA,UAGfC,KAHe,cAGfA,KAHe;AAAA,UAIfC,IAJe,cAIfA,IAJe;AAAA,UAKfC,QALe,cAKfA,QALe;AAAA,UAMfC,eANe,cAMfA,eANe;AAAA,UAOfL,WAPe,cAOfA,WAPe;;AASjB,UAAII,aAAa,MAAjB,EAAyB;AACvB,YAAI,CAACC,eAAD,IAAoBJ,KAAKK,MAAL,KAAgBJ,KAAxC,EAA+C;AAC7C,iBACE;AAAA;AAAA;AACE,yBAAU,wBADZ;AAEE,uBAAS;AAAA,uBAAMF,YAAY,EAAEG,MAAMA,OAAO,CAAf,EAAZ,CAAN;AAAA;AAFX;AAIE;AAAA;AAAA;AAAA;AAAA;AAJF,WADF;AAQD,SATD,MASO;AACL,iBAAO,IAAP;AACD;AACF,OAbD,MAaO,IAAIC,aAAa,YAAjB,EAA+B;AACpC,eACE;AAAA;AAAA,YAAK,WAAU,yBAAf;AACE;AACE,sBAAUG,eADZ;AAEE,qBAASJ,IAFX;AAGE,mBAAOD,KAHT;AAIE,sBAAU,kBAACM,CAAD,EAAO;AACfR,0BAAY,EAAEG,MAAMK,CAAR,EAAZ;AACD;AANH;AADF,SADF;AAYD;AACF;;;6BAEQ;AAAA,wBAKH,KAAKX,KAAL,CAAWE,GALR;AAAA,UAELE,IAFK,eAELA,IAFK;AAAA,UAGLC,KAHK,eAGLA,KAHK;AAAA,UAILO,OAJK,eAILA,OAJK;;;AAOP,UAAMC,WAAWC,QACfF,QAAQT,WAAR,IAAuBS,QAAQG,aAA/B,IAAgDH,QAAQI,WADzC,CAAjB;AAGA,aACE;AAAA;AAAA;AACE;AAAA;AAAA,YAAM,UAAUH,QAAhB;AACE;AAAA;AAAA;AAAA;AAAQR,iBAAR;AAAA;AAAA,WADF;AAEGD,eAAKa,GAAL,CAAS;AAAA,mBACR,8BAAC,oBAAD,IAAY,SAASC,IAArB,EAA2B,KAAKA,KAAKC,EAArC,EAAyC,WAAWD,KAAKC,EAAzD,GADQ;AAAA,WAAT,CAFH;AAMI,eAAKC,gBAAL;AANJ;AADF,OADF;AAaD;;;;EAvEuBC,gB;;AA0E1BtB,YAAYuB,SAAZ,GAAwB,EAAxB;;kBAEe,uBAAQvB,WAAR,C","file":"index.js","sourcesContent":["import React, { Component } from \"react\";\r\nimport { Spin, Pagination } from \"antd\";\r\nimport Comment from \"../../Comment\";\r\nimport CommentBox from \"../CommentBox\";\r\nimport \"./index.css\";\r\nimport { LIMIT } from \"../../constant\";\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  renderPagination() {\r\n    const {\r\n      list,\r\n      total,\r\n      page,\r\n      pageType,\r\n      isNoMoreComment,\r\n      sGetComment\r\n    } = this.props.app;\r\n    if (pageType === 'more') {\r\n      if (!isNoMoreComment && list.length !== total) {\r\n        return (\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      } else {\r\n        return null;\r\n      }\r\n    } else if (pageType === 'pagination') {\r\n      return (\r\n        <div className=\"comment-list-pagination\">\r\n          <Pagination\r\n            pageSize={LIMIT}\r\n            current={page}\r\n            total={total}\r\n            onChange={(p) => {\r\n              sGetComment({ page: p })\r\n            }}\r\n          />\r\n        </div>\r\n      )\r\n    }\r\n  }\r\n\r\n  render() {\r\n    const {\r\n      list,\r\n      total,\r\n      loading,\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            this.renderPagination()\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
+{"version":3,"sources":["../../../src/components/CommentList/index.js"],"names":["CommentList","props","state","app","sGetComment","page","list","total","pageType","isNoMoreComment","onPageChange","length","LIMIT","p","loading","spinning","Boolean","sCommentFavor","sReplyFavor","map","item","id","renderPagination","Component","propTypes"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;;;;AAEA;;;;AACA;;;;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,CAA2B,EAAEC,MAAM,KAAKJ,KAAL,CAAWE,GAAX,CAAeE,IAAvB,EAA3B;AACD;;;uCAEkB;AAAA,uBASb,KAAKJ,KAAL,CAAWE,GATE;AAAA,UAEfG,IAFe,cAEfA,IAFe;AAAA,UAGfC,KAHe,cAGfA,KAHe;AAAA,UAIfF,IAJe,cAIfA,IAJe;AAAA,UAKfG,QALe,cAKfA,QALe;AAAA,UAMfC,eANe,cAMfA,eANe;AAAA,UAOfL,WAPe,cAOfA,WAPe;AAAA,UAQfM,YARe,cAQfA,YARe;;AAUjB,UAAIF,aAAa,MAAjB,EAAyB;AACvB,YAAI,CAACC,eAAD,IAAoBH,KAAKK,MAAL,KAAgBJ,KAAxC,EAA+C;AAC7C,iBACE;AAAA;AAAA;AACE,yBAAU,wBADZ;AAEE,uBAAS,mBAAM;AACbH,4BAAY,EAAEC,MAAMA,OAAO,CAAf,EAAZ;AACAK,6BAAaL,OAAO,CAApB;AACD;AALH;AAQE;AAAA;AAAA;AAAA;AAAA;AARF,WADF;AAYD,SAbD,MAaO;AACL,iBAAO,IAAP;AACD;AACF,OAjBD,MAiBO,IAAIG,aAAa,YAAjB,EAA+B;AACpC,eACE;AAAA;AAAA,YAAK,WAAU,yBAAf;AACE;AACE,sBAAUI,eADZ;AAEE,qBAASP,IAFX;AAGE,mBAAOE,KAHT;AAIE,sBAAU,qBAAK;AACbH,0BAAY,EAAEC,MAAMQ,CAAR,EAAZ;AACAH,2BAAaG,CAAb;AACD;AAPH;AADF,SADF;AAaD;AACF;;;6BAEQ;AAAA,wBAC0B,KAAKZ,KAAL,CAAWE,GADrC;AAAA,UACCG,IADD,eACCA,IADD;AAAA,UACOC,KADP,eACOA,KADP;AAAA,UACcO,OADd,eACcA,OADd;;;AAGP,UAAMC,WAAWC,QACfF,QAAQV,WAAR,IAAuBU,QAAQG,aAA/B,IAAgDH,QAAQI,WADzC,CAAjB;AAGA,aACE;AAAA;AAAA;AACE;AAAA;AAAA,YAAM,UAAUH,QAAhB;AACE;AAAA;AAAA;AAAA;AAAQR,iBAAR;AAAA;AAAA,WADF;AAEGD,eAAKa,GAAL,CAAS;AAAA,mBACR,8BAAC,oBAAD,IAAY,SAASC,IAArB,EAA2B,KAAKA,KAAKC,EAArC,EAAyC,WAAWD,KAAKC,EAAzD,GADQ;AAAA,WAAT,CAFH;AAKG,eAAKC,gBAAL;AALH;AADF,OADF;AAWD;;;;EAvEuBC,gB;;AA0E1BvB,YAAYwB,SAAZ,GAAwB,EAAxB;;kBAEe,uBAAQxB,WAAR,C","file":"index.js","sourcesContent":["import React, { Component } from \"react\";\r\nimport { Spin, Pagination } from \"antd\";\r\nimport Comment from \"../../Comment\";\r\nimport CommentBox from \"../CommentBox\";\r\nimport \"./index.css\";\r\nimport { LIMIT } from \"../../constant\";\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({ page: this.props.app.page });\r\n  }\r\n\r\n  renderPagination() {\r\n    const {\r\n      list,\r\n      total,\r\n      page,\r\n      pageType,\r\n      isNoMoreComment,\r\n      sGetComment,\r\n      onPageChange,\r\n    } = this.props.app;\r\n    if (pageType === \"more\") {\r\n      if (!isNoMoreComment && list.length !== total) {\r\n        return (\r\n          <div\r\n            className=\"comment-list-show-more\"\r\n            onClick={() => {\r\n              sGetComment({ page: page + 1 })\r\n              onPageChange(page + 1);\r\n            }\r\n            }\r\n          >\r\n            <span>查看更多评论</span>\r\n          </div>\r\n        );\r\n      } else {\r\n        return null;\r\n      }\r\n    } else if (pageType === \"pagination\") {\r\n      return (\r\n        <div className=\"comment-list-pagination\">\r\n          <Pagination\r\n            pageSize={LIMIT}\r\n            current={page}\r\n            total={total}\r\n            onChange={p => {\r\n              sGetComment({ page: p });\r\n              onPageChange(p);\r\n            }}\r\n          />\r\n        </div>\r\n      );\r\n    }\r\n  }\r\n\r\n  render() {\r\n    const { list, total, loading } = 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          {this.renderPagination()}\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.css View File

71
     width: 75%;
71
     width: 75%;
72
     margin-left: 10px;
72
     margin-left: 10px;
73
   }
73
   }
74
-}
74
+}

+ 1
- 5
lib/components/ContentItem/index.js View File

196
                   rel: "noopener noreferrer",
196
                   rel: "noopener noreferrer",
197
                   key: index
197
                   key: index
198
                 },
198
                 },
199
-                _react2.default.createElement("img", {
200
-                  src: item,
201
-                  alt: item,
202
-                  className: "comment-img"
203
-                })
199
+                _react2.default.createElement("img", { src: item, alt: item, className: "comment-img" })
204
               );
200
               );
205
             })
201
             })
206
           ),
202
           ),

+ 1
- 1
lib/components/ContentItem/index.js.map
File diff suppressed because it is too large
View File


+ 1
- 1
lib/helper.js.map
File diff suppressed because it is too large
View File


+ 12
- 1
lib/index.js View File

39
     var _this = _possibleConstructorReturn(this, (Index.__proto__ || Object.getPrototypeOf(Index)).call(this, props));
39
     var _this = _possibleConstructorReturn(this, (Index.__proto__ || Object.getPrototypeOf(Index)).call(this, props));
40
 
40
 
41
     _this.state = {
41
     _this.state = {
42
+      page: 1,
42
       value: ""
43
       value: ""
43
     };
44
     };
45
+    _this.onPageChange = _this.onPageChange.bind(_this);
44
     _this.handleChangeValue = _this.handleChangeValue.bind(_this);
46
     _this.handleChangeValue = _this.handleChangeValue.bind(_this);
45
     _this.handleChangeSubmit = _this.handleChangeSubmit.bind(_this);
47
     _this.handleChangeSubmit = _this.handleChangeSubmit.bind(_this);
46
     return _this;
48
     return _this;
47
   }
49
   }
48
 
50
 
49
   _createClass(Index, [{
51
   _createClass(Index, [{
52
+    key: "onPageChange",
53
+    value: function onPageChange(page) {
54
+      this.setState({
55
+        page: page
56
+      });
57
+    }
58
+  }, {
50
     key: "handleChangeValue",
59
     key: "handleChangeValue",
51
     value: function handleChangeValue(value) {
60
     value: function handleChangeValue(value) {
52
       this.setState({ value: value });
61
       this.setState({ value: value });
82
           showAlertFavor: true,
91
           showAlertFavor: true,
83
           showError: false,
92
           showError: false,
84
           userId: 71299,
93
           userId: 71299,
85
-          pageType: "pagination",
94
+          page: this.state.page,
95
+          onPageChange: this.onPageChange,
96
+          pageType: "more",
86
           onError: function onError(msg, _ref2) {
97
           onError: function onError(msg, _ref2) {
87
             var response = _ref2.response;
98
             var response = _ref2.response;
88
 
99
 

+ 1
- 1
lib/index.js.map
File diff suppressed because it is too large
View File


+ 1
- 1
package.json View File

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

+ 5
- 2
src/App.js View File

437
   showError: PropTypes.bool, // 是否使用Antd的Message组件提示错误信息
437
   showError: PropTypes.bool, // 是否使用Antd的Message组件提示错误信息
438
   onError: PropTypes.func, // 错误回调, 出错了会被调用
438
   onError: PropTypes.func, // 错误回调, 出错了会被调用
439
   userId: PropTypes.number, // 用户id, comment内部不维护用户id, 调用组件时传递过来, 目前用于判断是否显示删除按钮
439
   userId: PropTypes.number, // 用户id, comment内部不维护用户id, 调用组件时传递过来, 目前用于判断是否显示删除按钮
440
-  pageType: PropTypes.string // 分页类型
440
+  pageType: PropTypes.string, // 分页类型
441
+  page: PropTypes.number, // 页码
442
+  onPageChange: PropTypes.func // 页码变化回调
441
 };
443
 };
442
 
444
 
443
 App.defaultProps = {
445
 App.defaultProps = {
448
   showAlertReply: false,
450
   showAlertReply: false,
449
   showAlertFavor: false,
451
   showAlertFavor: false,
450
   showError: true,
452
   showError: true,
451
-  pageType: "more"
453
+  pageType: "more",
454
+  onPageChange: page => {}
452
 };
455
 };
453
 
456
 
454
 export { Editor, RenderText };
457
 export { Editor, RenderText };

+ 8
- 3
src/components/CommentList/index.js View File

12
   }
12
   }
13
 
13
 
14
   componentWillMount() {
14
   componentWillMount() {
15
-    this.props.app.sGetComment();
15
+    this.props.app.sGetComment({ page: this.props.app.page });
16
   }
16
   }
17
 
17
 
18
   renderPagination() {
18
   renderPagination() {
22
       page,
22
       page,
23
       pageType,
23
       pageType,
24
       isNoMoreComment,
24
       isNoMoreComment,
25
-      sGetComment
25
+      sGetComment,
26
+      onPageChange
26
     } = this.props.app;
27
     } = this.props.app;
27
     if (pageType === "more") {
28
     if (pageType === "more") {
28
       if (!isNoMoreComment && list.length !== total) {
29
       if (!isNoMoreComment && list.length !== total) {
29
         return (
30
         return (
30
           <div
31
           <div
31
             className="comment-list-show-more"
32
             className="comment-list-show-more"
32
-            onClick={() => sGetComment({ page: page + 1 })}
33
+            onClick={() => {
34
+              sGetComment({ page: page + 1 });
35
+              onPageChange(page + 1);
36
+            }}
33
           >
37
           >
34
             <span>查看更多评论</span>
38
             <span>查看更多评论</span>
35
           </div>
39
           </div>
46
             total={total}
50
             total={total}
47
             onChange={p => {
51
             onChange={p => {
48
               sGetComment({ page: p });
52
               sGetComment({ page: p });
53
+              onPageChange(p);
49
             }}
54
             }}
50
           />
55
           />
51
         </div>
56
         </div>

+ 11
- 1
src/index.js View File

10
   constructor(props) {
10
   constructor(props) {
11
     super(props);
11
     super(props);
12
     this.state = {
12
     this.state = {
13
+      page: 1,
13
       value: ""
14
       value: ""
14
     };
15
     };
16
+    this.onPageChange = this.onPageChange.bind(this);
15
     this.handleChangeValue = this.handleChangeValue.bind(this);
17
     this.handleChangeValue = this.handleChangeValue.bind(this);
16
     this.handleChangeSubmit = this.handleChangeSubmit.bind(this);
18
     this.handleChangeSubmit = this.handleChangeSubmit.bind(this);
17
   }
19
   }
18
 
20
 
21
+  onPageChange(page) {
22
+    this.setState({
23
+      page
24
+    });
25
+  }
26
+
19
   handleChangeValue(value) {
27
   handleChangeValue(value) {
20
     this.setState({ value });
28
     this.setState({ value });
21
     console.log("handleChangeValue value: ", value);
29
     console.log("handleChangeValue value: ", value);
42
         showAlertFavor
50
         showAlertFavor
43
         showError={false}
51
         showError={false}
44
         userId={71299}
52
         userId={71299}
45
-        pageType="pagination"
53
+        page={this.state.page}
54
+        onPageChange={this.onPageChange}
55
+        pageType="more"
46
         onError={(msg, { response }) => {
56
         onError={(msg, { response }) => {
47
           if (response.status === 401) {
57
           if (response.status === 401) {
48
             console.log("unlogined");
58
             console.log("unlogined");