Browse Source

支持两种分页模式

narro 6 years ago
parent
commit
a3da37f04c

+ 1
- 0
README.md View File

27
 | onError          | function(msg) |                                    | false    | 错误回调, 出错了会被调用                                                          |
27
 | onError          | function(msg) |                                    | false    | 错误回调, 出错了会被调用                                                          |
28
 | userId           | number        |                                    | false    | 用户id, comment内部不维护用户id, 调用组件时传递过来, 目前用于判断是否显示删除按钮 |
28
 | userId           | number        |                                    | false    | 用户id, comment内部不维护用户id, 调用组件时传递过来, 目前用于判断是否显示删除按钮 |
29
 | token            | string        |                                    | false    | [deprecated] token,用于身份认证,非必须。默认使用 cookie                         |
29
 | token            | string        |                                    | false    | [deprecated] token,用于身份认证,非必须。默认使用 cookie                         |
30
+| pageType         | string        | more                               | false    | 分页类别, more-加载更多 pagination-页码                                          |
30
 
31
 
31
 
32
 
32
 ## Editor
33
 ## Editor

+ 9
- 1
lib/App.css View File

3
   padding: 10px;
3
   padding: 10px;
4
   margin-bottom: 100px;
4
   margin-bottom: 100px;
5
 }
5
 }
6
-.comment .ant-spin-nested-loading > div > .ant-spin .ant-spin-dot {
6
+
7
+.comment .ant-spin-nested-loading>div>.ant-spin .ant-spin-dot {
7
   position: fixed;
8
   position: fixed;
8
   top: 45%;
9
   top: 45%;
9
 }
10
 }
11
+
10
 .comment-header-tag {
12
 .comment-header-tag {
11
   border: 1px solid #cecece;
13
   border: 1px solid #cecece;
12
   border-radius: 0;
14
   border-radius: 0;
13
   color: #666;
15
   color: #666;
14
 }
16
 }
17
+
15
 .comment-header-tip {
18
 .comment-header-tip {
16
   color: #5198eb;
19
   color: #5198eb;
17
   margin-right: 15px;
20
   margin-right: 15px;
18
   margin-left: 5px;
21
   margin-left: 5px;
19
 }
22
 }
23
+
20
 .comment-header-text {
24
 .comment-header-text {
21
   color: #666;
25
   color: #666;
22
 }
26
 }
27
+
28
+.comment-img {
29
+  max-width: 100%;
30
+}

+ 20
- 10
lib/App.js View File

164
           _ref$page = _ref.page,
164
           _ref$page = _ref.page,
165
           page = _ref$page === undefined ? 1 : _ref$page;
165
           page = _ref$page === undefined ? 1 : _ref$page;
166
 
166
 
167
+      var pageType = this.props.pageType;
168
+
167
       this.handleChangeLoading("sGetComment", true);
169
       this.handleChangeLoading("sGetComment", true);
168
       var _props = this.props,
170
       var _props = this.props,
169
           API = _props.API,
171
           API = _props.API,
178
 
180
 
179
         if (list) {
181
         if (list) {
180
           var newList = list;
182
           var newList = list;
181
-          if (page > 1) {
182
-            var oldList = _this2.state.list;
183
-            // 删除临时数据
184
-
185
-            oldList = oldList.filter(function (o) {
186
-              return !o.isTemporary;
187
-            });
188
-            newList = oldList.concat(newList);
183
+          var oldList = _this2.state.list;
184
+
185
+          if (pageType === 'more') {
186
+            if (page > 1) {
187
+              // 删除临时数据
188
+              oldList = oldList.filter(function (o) {
189
+                return !o.isTemporary;
190
+              });
191
+              newList = oldList.concat(newList);
192
+            }
193
+          } else if (pageType === 'pagination') {
194
+            // TODO 滚动到顶部
195
+            window.scrollTo(0, 0);
189
           }
196
           }
197
+
190
           _this2.setState({
198
           _this2.setState({
191
             list: newList,
199
             list: newList,
192
             page: page,
200
             page: page,
554
   showAlertFavor: _propTypes2.default.bool, // 点赞/取消点赞成功之后,是否通过 Antd 的 Message 组件进行提示
562
   showAlertFavor: _propTypes2.default.bool, // 点赞/取消点赞成功之后,是否通过 Antd 的 Message 组件进行提示
555
   showError: _propTypes2.default.bool, // 是否使用Antd的Message组件提示错误信息
563
   showError: _propTypes2.default.bool, // 是否使用Antd的Message组件提示错误信息
556
   onError: _propTypes2.default.func, // 错误回调, 出错了会被调用
564
   onError: _propTypes2.default.func, // 错误回调, 出错了会被调用
557
-  userId: _propTypes2.default.number // 用户id, comment内部不维护用户id, 调用组件时传递过来, 目前用于判断是否显示删除按钮
565
+  userId: _propTypes2.default.number, // 用户id, comment内部不维护用户id, 调用组件时传递过来, 目前用于判断是否显示删除按钮
566
+  pageType: _propTypes2.default.string // 分页类型
558
 };
567
 };
559
 
568
 
560
 App.defaultProps = {
569
 App.defaultProps = {
564
   showAlertComment: false,
573
   showAlertComment: false,
565
   showAlertReply: false,
574
   showAlertReply: false,
566
   showAlertFavor: false,
575
   showAlertFavor: false,
567
-  showError: true
576
+  showError: true,
577
+  pageType: "more"
568
 };
578
 };
569
 
579
 
570
 exports.Editor = _Editor2.default;
580
 exports.Editor = _Editor2.default;

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


+ 5
- 0
lib/components/CommentList/index.css View File

8
   margin: 40px auto;
8
   margin: 40px auto;
9
   transition: all 0.3s;
9
   transition: all 0.3s;
10
 }
10
 }
11
+
11
 .comment-list-show-more:hover {
12
 .comment-list-show-more:hover {
12
   background-color: #f5f5f5;
13
   background-color: #f5f5f5;
13
   color: #1890ff;
14
   color: #1890ff;
14
 }
15
 }
16
+
17
+.comment-list-pagination {
18
+  text-align: center;
19
+}

+ 54
- 17
lib/components/CommentList/index.js View File

8
 
8
 
9
 var _spin2 = _interopRequireDefault(_spin);
9
 var _spin2 = _interopRequireDefault(_spin);
10
 
10
 
11
+var _pagination = require("antd/es/pagination");
12
+
13
+var _pagination2 = _interopRequireDefault(_pagination);
14
+
11
 var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
15
 var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
12
 
16
 
13
 require("antd/es/spin/style/css");
17
 require("antd/es/spin/style/css");
14
 
18
 
19
+require("antd/es/pagination/style/css");
20
+
15
 var _react = require("react");
21
 var _react = require("react");
16
 
22
 
17
 var _react2 = _interopRequireDefault(_react);
23
 var _react2 = _interopRequireDefault(_react);
26
 
32
 
27
 require("./index.css");
33
 require("./index.css");
28
 
34
 
35
+var _constant = require("../../constant");
36
+
29
 function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
37
 function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
30
 
38
 
31
 function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
39
 function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
52
       this.props.app.sGetComment();
60
       this.props.app.sGetComment();
53
     }
61
     }
54
   }, {
62
   }, {
55
-    key: "render",
56
-    value: function render() {
63
+    key: "renderPagination",
64
+    value: function renderPagination() {
57
       var _props$app = this.props.app,
65
       var _props$app = this.props.app,
58
           list = _props$app.list,
66
           list = _props$app.list,
59
           total = _props$app.total,
67
           total = _props$app.total,
60
           page = _props$app.page,
68
           page = _props$app.page,
61
-          loading = _props$app.loading,
69
+          pageType = _props$app.pageType,
62
           isNoMoreComment = _props$app.isNoMoreComment,
70
           isNoMoreComment = _props$app.isNoMoreComment,
63
           sGetComment = _props$app.sGetComment;
71
           sGetComment = _props$app.sGetComment;
64
 
72
 
73
+      if (pageType === 'more') {
74
+        if (!isNoMoreComment && list.length !== total) {
75
+          return _react2.default.createElement(
76
+            "div",
77
+            {
78
+              className: "comment-list-show-more",
79
+              onClick: function onClick() {
80
+                return sGetComment({ page: page + 1 });
81
+              }
82
+            },
83
+            _react2.default.createElement(
84
+              "span",
85
+              null,
86
+              "\u67E5\u770B\u66F4\u591A\u8BC4\u8BBA"
87
+            )
88
+          );
89
+        } else {
90
+          return null;
91
+        }
92
+      } else if (pageType === 'pagination') {
93
+        return _react2.default.createElement(
94
+          "div",
95
+          { className: "comment-list-pagination" },
96
+          _react2.default.createElement(_pagination2.default, {
97
+            pageSize: _constant.LIMIT,
98
+            current: page,
99
+            total: total,
100
+            onChange: function onChange(p) {
101
+              sGetComment({ page: p });
102
+            }
103
+          })
104
+        );
105
+      }
106
+    }
107
+  }, {
108
+    key: "render",
109
+    value: function render() {
110
+      var _props$app2 = this.props.app,
111
+          list = _props$app2.list,
112
+          total = _props$app2.total,
113
+          loading = _props$app2.loading;
114
+
65
 
115
 
66
       var spinning = Boolean(loading.sGetComment || loading.sCommentFavor || loading.sReplyFavor);
116
       var spinning = Boolean(loading.sGetComment || loading.sCommentFavor || loading.sReplyFavor);
67
       return _react2.default.createElement(
117
       return _react2.default.createElement(
80
           list.map(function (item) {
130
           list.map(function (item) {
81
             return _react2.default.createElement(_CommentBox2.default, { content: item, key: item.id, commentId: item.id });
131
             return _react2.default.createElement(_CommentBox2.default, { content: item, key: item.id, commentId: item.id });
82
           }),
132
           }),
83
-          !isNoMoreComment && list.length !== total && _react2.default.createElement(
84
-            "div",
85
-            {
86
-              className: "comment-list-show-more",
87
-              onClick: function onClick() {
88
-                return sGetComment({ page: page + 1 });
89
-              }
90
-            },
91
-            _react2.default.createElement(
92
-              "span",
93
-              null,
94
-              "\u67E5\u770B\u66F4\u591A\u8BC4\u8BBA"
95
-            )
96
-          )
133
+          this.renderPagination()
97
         )
134
         )
98
       );
135
       );
99
     }
136
     }

+ 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","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
+{"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"]}

+ 16
- 1
lib/components/ContentItem/index.css View File

3
   padding: 15px 5px 0 5px;
3
   padding: 15px 5px 0 5px;
4
   border-top: 1px solid #eee;
4
   border-top: 1px solid #eee;
5
 }
5
 }
6
+
6
 .comment-item-left {
7
 .comment-item-left {
7
   display: inline-block;
8
   display: inline-block;
8
   vertical-align: top;
9
   vertical-align: top;
9
   width: 40px;
10
   width: 40px;
10
 }
11
 }
12
+
11
 .comment-item-right {
13
 .comment-item-right {
12
   display: inline-block;
14
   display: inline-block;
13
   width: 90%;
15
   width: 90%;
14
   margin-left: 10px;
16
   margin-left: 10px;
15
   margin-bottom: 20px;
17
   margin-bottom: 20px;
16
 }
18
 }
19
+
17
 .comment-item-content {
20
 .comment-item-content {
18
   margin: 10px 0;
21
   margin: 10px 0;
19
   word-break: break-all;
22
   word-break: break-all;
20
 }
23
 }
24
+
21
 .comment-item-bottom {
25
 .comment-item-bottom {
22
   margin: 20px auto;
26
   margin: 20px auto;
23
 }
27
 }
28
+
24
 .comment-item-bottom-left {
29
 .comment-item-bottom-left {
25
   float: left;
30
   float: left;
26
   user-select: none;
31
   user-select: none;
27
 }
32
 }
33
+
28
 .comment-item-bottom-right {
34
 .comment-item-bottom-right {
29
   float: right;
35
   float: right;
30
   margin-left: 5px;
36
   margin-left: 5px;
31
   cursor: pointer;
37
   cursor: pointer;
32
 }
38
 }
39
+
33
 .comment-favor {
40
 .comment-favor {
34
   font-size: 20px;
41
   font-size: 20px;
35
 }
42
 }
43
+
36
 .comment-favored {
44
 .comment-favored {
37
   color: #4a90e2;
45
   color: #4a90e2;
38
 }
46
 }
47
+
48
+.comment-item-image .comment-img {
49
+  margin-right: 10px;
50
+}
51
+
39
 @media screen and (max-width: 616px) and (min-width: 449px) {
52
 @media screen and (max-width: 616px) and (min-width: 449px) {
40
   .comment-item-right {
53
   .comment-item-right {
41
     display: inline-block;
54
     display: inline-block;
43
     margin-left: 10px;
56
     margin-left: 10px;
44
   }
57
   }
45
 }
58
 }
59
+
46
 @media screen and (max-width: 449px) and (min-width: 365px) {
60
 @media screen and (max-width: 449px) and (min-width: 365px) {
47
   .comment-item-right {
61
   .comment-item-right {
48
     display: inline-block;
62
     display: inline-block;
50
     margin-left: 10px;
64
     margin-left: 10px;
51
   }
65
   }
52
 }
66
 }
67
+
53
 @media screen and (max-width: 365px) {
68
 @media screen and (max-width: 365px) {
54
   .comment-item-right {
69
   .comment-item-right {
55
     display: inline-block;
70
     display: inline-block;
56
     width: 75%;
71
     width: 75%;
57
     margin-left: 10px;
72
     margin-left: 10px;
58
   }
73
   }
59
-}
74
+}

+ 14
- 6
lib/components/ContentItem/index.js View File

188
             "div",
188
             "div",
189
             { className: "comment-item-image" },
189
             { className: "comment-item-image" },
190
             imageList.map(function (item, index) {
190
             imageList.map(function (item, index) {
191
-              return _react2.default.createElement("img", {
192
-                key: index,
193
-                src: item,
194
-                alt: item,
195
-                style: { maxWidth: "100%" }
196
-              });
191
+              return _react2.default.createElement(
192
+                "a",
193
+                {
194
+                  href: item,
195
+                  target: "_blank",
196
+                  rel: "noopener noreferrer",
197
+                  key: index
198
+                },
199
+                _react2.default.createElement("img", {
200
+                  src: item,
201
+                  alt: item,
202
+                  className: "comment-img"
203
+                })
204
+              );
197
             })
205
             })
198
           ),
206
           ),
199
           _react2.default.createElement(
207
           _react2.default.createElement(

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


+ 2
- 2
lib/helper.js View File

74
     // 兼容旧的评
74
     // 兼容旧的评
75
     // 因为旧的评论用 [img url] 方式存储的
75
     // 因为旧的评论用 [img url] 方式存储的
76
     if (isUrl(src)) {
76
     if (isUrl(src)) {
77
-      return "<br/><img src=\"" + src + "\" alt=\"" + src + "\" style=\"max-width: 100%\" />";
77
+      return "<a href=\"" + src + "\" rel=\"noopener noreferrer\" target=\"_blank\"><img class=\"comment-img\" src=\"" + src + "\" alt=\"" + src + "\" /></a>";
78
     }
78
     }
79
     // 如果不存在对应的表情, 则返回原文
79
     // 如果不存在对应的表情, 则返回原文
80
     var emoji = emojiObejct[src];
80
     var emoji = emojiObejct[src];
81
     if (emoji) {
81
     if (emoji) {
82
-      return "<img src=\"" + _emoji.prefixUrl + emoji.value + "." + emoji.ext + "\" alt=\"" + emoji.title + "\" />";
82
+      return "<img class=\"comment-emoji\" src=\"" + _emoji.prefixUrl + emoji.value + "." + emoji.ext + "\" alt=\"" + emoji.title + "\" />";
83
     }
83
     }
84
     return "[" + src + "]";
84
     return "[" + src + "]";
85
   }).replace(innerUrl, function (a, b) {
85
   }).replace(innerUrl, function (a, b) {

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


+ 1
- 0
lib/index.js View File

82
           showAlertFavor: true,
82
           showAlertFavor: true,
83
           showError: false,
83
           showError: false,
84
           userId: 71299,
84
           userId: 71299,
85
+          pageType: "pagination",
85
           onError: function onError(msg, _ref2) {
86
           onError: function onError(msg, _ref2) {
86
             var response = _ref2.response;
87
             var response = _ref2.response;
87
 
88
 

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


+ 8
- 0
src/App.css View File

3
   padding: 10px;
3
   padding: 10px;
4
   margin-bottom: 100px;
4
   margin-bottom: 100px;
5
 }
5
 }
6
+
6
 .comment .ant-spin-nested-loading > div > .ant-spin .ant-spin-dot {
7
 .comment .ant-spin-nested-loading > div > .ant-spin .ant-spin-dot {
7
   position: fixed;
8
   position: fixed;
8
   top: 45%;
9
   top: 45%;
9
 }
10
 }
11
+
10
 .comment-header-tag {
12
 .comment-header-tag {
11
   border: 1px solid #cecece;
13
   border: 1px solid #cecece;
12
   border-radius: 0;
14
   border-radius: 0;
13
   color: #666;
15
   color: #666;
14
 }
16
 }
17
+
15
 .comment-header-tip {
18
 .comment-header-tip {
16
   color: #5198eb;
19
   color: #5198eb;
17
   margin-right: 15px;
20
   margin-right: 15px;
18
   margin-left: 5px;
21
   margin-left: 5px;
19
 }
22
 }
23
+
20
 .comment-header-text {
24
 .comment-header-text {
21
   color: #666;
25
   color: #666;
22
 }
26
 }
27
+
28
+.comment-img {
29
+  max-width: 100%;
30
+}

+ 16
- 7
src/App.js View File

89
    * 获取评论列表
89
    * 获取评论列表
90
    */
90
    */
91
   sGetComment({ page = 1 } = {}) {
91
   sGetComment({ page = 1 } = {}) {
92
+    const { pageType } = this.props;
92
     this.handleChangeLoading("sGetComment", true);
93
     this.handleChangeLoading("sGetComment", true);
93
     const { API, type, businessId } = this.props;
94
     const { API, type, businessId } = this.props;
94
     this.axios
95
     this.axios
99
         const { list, page, total } = response.data;
100
         const { list, page, total } = response.data;
100
         if (list) {
101
         if (list) {
101
           let newList = list;
102
           let newList = list;
102
-          if (page > 1) {
103
-            let { list: oldList } = this.state;
104
-            // 删除临时数据
105
-            oldList = oldList.filter(o => !o.isTemporary);
106
-            newList = oldList.concat(newList);
103
+          let { list: oldList } = this.state;
104
+          if (pageType === "more") {
105
+            if (page > 1) {
106
+              // 删除临时数据
107
+              oldList = oldList.filter(o => !o.isTemporary);
108
+              newList = oldList.concat(newList);
109
+            }
110
+          } else if (pageType === "pagination") {
111
+            // TODO 滚动到顶部
112
+            window.scrollTo(0, 0);
107
           }
113
           }
114
+
108
           this.setState({
115
           this.setState({
109
             list: newList,
116
             list: newList,
110
             page,
117
             page,
429
   showAlertFavor: PropTypes.bool, // 点赞/取消点赞成功之后,是否通过 Antd 的 Message 组件进行提示
436
   showAlertFavor: PropTypes.bool, // 点赞/取消点赞成功之后,是否通过 Antd 的 Message 组件进行提示
430
   showError: PropTypes.bool, // 是否使用Antd的Message组件提示错误信息
437
   showError: PropTypes.bool, // 是否使用Antd的Message组件提示错误信息
431
   onError: PropTypes.func, // 错误回调, 出错了会被调用
438
   onError: PropTypes.func, // 错误回调, 出错了会被调用
432
-  userId: PropTypes.number // 用户id, comment内部不维护用户id, 调用组件时传递过来, 目前用于判断是否显示删除按钮
439
+  userId: PropTypes.number, // 用户id, comment内部不维护用户id, 调用组件时传递过来, 目前用于判断是否显示删除按钮
440
+  pageType: PropTypes.string // 分页类型
433
 };
441
 };
434
 
442
 
435
 App.defaultProps = {
443
 App.defaultProps = {
439
   showAlertComment: false,
447
   showAlertComment: false,
440
   showAlertReply: false,
448
   showAlertReply: false,
441
   showAlertFavor: false,
449
   showAlertFavor: false,
442
-  showError: true
450
+  showError: true,
451
+  pageType: "more"
443
 };
452
 };
444
 
453
 
445
 export { Editor, RenderText };
454
 export { Editor, RenderText };

+ 5
- 0
src/components/CommentList/index.css View File

8
   margin: 40px auto;
8
   margin: 40px auto;
9
   transition: all 0.3s;
9
   transition: all 0.3s;
10
 }
10
 }
11
+
11
 .comment-list-show-more:hover {
12
 .comment-list-show-more:hover {
12
   background-color: #f5f5f5;
13
   background-color: #f5f5f5;
13
   color: #1890ff;
14
   color: #1890ff;
14
 }
15
 }
16
+
17
+.comment-list-pagination {
18
+  text-align: center;
19
+}

+ 36
- 13
src/components/CommentList/index.js View File

1
 import React, { Component } from "react";
1
 import React, { Component } from "react";
2
-import { Spin } from "antd";
2
+import { Spin, Pagination } from "antd";
3
 import Comment from "../../Comment";
3
 import Comment from "../../Comment";
4
 import CommentBox from "../CommentBox";
4
 import CommentBox from "../CommentBox";
5
 import "./index.css";
5
 import "./index.css";
6
+import { LIMIT } from "../../constant";
6
 
7
 
7
 class CommentList extends Component {
8
 class CommentList extends Component {
8
   constructor(props) {
9
   constructor(props) {
14
     this.props.app.sGetComment();
15
     this.props.app.sGetComment();
15
   }
16
   }
16
 
17
 
17
-  render() {
18
+  renderPagination() {
18
     const {
19
     const {
19
       list,
20
       list,
20
       total,
21
       total,
21
       page,
22
       page,
22
-      loading,
23
+      pageType,
23
       isNoMoreComment,
24
       isNoMoreComment,
24
       sGetComment
25
       sGetComment
25
     } = this.props.app;
26
     } = this.props.app;
27
+    if (pageType === "more") {
28
+      if (!isNoMoreComment && list.length !== total) {
29
+        return (
30
+          <div
31
+            className="comment-list-show-more"
32
+            onClick={() => sGetComment({ page: page + 1 })}
33
+          >
34
+            <span>查看更多评论</span>
35
+          </div>
36
+        );
37
+      } else {
38
+        return null;
39
+      }
40
+    } else if (pageType === "pagination") {
41
+      return (
42
+        <div className="comment-list-pagination">
43
+          <Pagination
44
+            pageSize={LIMIT}
45
+            current={page}
46
+            total={total}
47
+            onChange={p => {
48
+              sGetComment({ page: p });
49
+            }}
50
+          />
51
+        </div>
52
+      );
53
+    }
54
+  }
55
+
56
+  render() {
57
+    const { list, total, loading } = this.props.app;
26
 
58
 
27
     const spinning = Boolean(
59
     const spinning = Boolean(
28
       loading.sGetComment || loading.sCommentFavor || loading.sReplyFavor
60
       loading.sGetComment || loading.sCommentFavor || loading.sReplyFavor
34
           {list.map(item => (
66
           {list.map(item => (
35
             <CommentBox content={item} key={item.id} commentId={item.id} />
67
             <CommentBox content={item} key={item.id} commentId={item.id} />
36
           ))}
68
           ))}
37
-
38
-          {!isNoMoreComment &&
39
-            list.length !== total && (
40
-              <div
41
-                className="comment-list-show-more"
42
-                onClick={() => sGetComment({ page: page + 1 })}
43
-              >
44
-                <span>查看更多评论</span>
45
-              </div>
46
-            )}
69
+          {this.renderPagination()}
47
         </Spin>
70
         </Spin>
48
       </div>
71
       </div>
49
     );
72
     );

+ 15
- 0
src/components/ContentItem/index.css View File

3
   padding: 15px 5px 0 5px;
3
   padding: 15px 5px 0 5px;
4
   border-top: 1px solid #eee;
4
   border-top: 1px solid #eee;
5
 }
5
 }
6
+
6
 .comment-item-left {
7
 .comment-item-left {
7
   display: inline-block;
8
   display: inline-block;
8
   vertical-align: top;
9
   vertical-align: top;
9
   width: 40px;
10
   width: 40px;
10
 }
11
 }
12
+
11
 .comment-item-right {
13
 .comment-item-right {
12
   display: inline-block;
14
   display: inline-block;
13
   width: 90%;
15
   width: 90%;
14
   margin-left: 10px;
16
   margin-left: 10px;
15
   margin-bottom: 20px;
17
   margin-bottom: 20px;
16
 }
18
 }
19
+
17
 .comment-item-content {
20
 .comment-item-content {
18
   margin: 10px 0;
21
   margin: 10px 0;
19
   word-break: break-all;
22
   word-break: break-all;
20
 }
23
 }
24
+
21
 .comment-item-bottom {
25
 .comment-item-bottom {
22
   margin: 20px auto;
26
   margin: 20px auto;
23
 }
27
 }
28
+
24
 .comment-item-bottom-left {
29
 .comment-item-bottom-left {
25
   float: left;
30
   float: left;
26
   user-select: none;
31
   user-select: none;
27
 }
32
 }
33
+
28
 .comment-item-bottom-right {
34
 .comment-item-bottom-right {
29
   float: right;
35
   float: right;
30
   margin-left: 5px;
36
   margin-left: 5px;
31
   cursor: pointer;
37
   cursor: pointer;
32
 }
38
 }
39
+
33
 .comment-favor {
40
 .comment-favor {
34
   font-size: 20px;
41
   font-size: 20px;
35
 }
42
 }
43
+
36
 .comment-favored {
44
 .comment-favored {
37
   color: #4a90e2;
45
   color: #4a90e2;
38
 }
46
 }
47
+
48
+.comment-item-image .comment-img {
49
+  margin-right: 10px;
50
+}
51
+
39
 @media screen and (max-width: 616px) and (min-width: 449px) {
52
 @media screen and (max-width: 616px) and (min-width: 449px) {
40
   .comment-item-right {
53
   .comment-item-right {
41
     display: inline-block;
54
     display: inline-block;
43
     margin-left: 10px;
56
     margin-left: 10px;
44
   }
57
   }
45
 }
58
 }
59
+
46
 @media screen and (max-width: 449px) and (min-width: 365px) {
60
 @media screen and (max-width: 449px) and (min-width: 365px) {
47
   .comment-item-right {
61
   .comment-item-right {
48
     display: inline-block;
62
     display: inline-block;
50
     margin-left: 10px;
64
     margin-left: 10px;
51
   }
65
   }
52
 }
66
 }
67
+
53
 @media screen and (max-width: 365px) {
68
 @media screen and (max-width: 365px) {
54
   .comment-item-right {
69
   .comment-item-right {
55
     display: inline-block;
70
     display: inline-block;

+ 7
- 5
src/components/ContentItem/index.js View File

108
               <div className="comment-item-image">
108
               <div className="comment-item-image">
109
                 {imageList.map((item, index) => {
109
                 {imageList.map((item, index) => {
110
                   return (
110
                   return (
111
-                    <img
111
+                    <a
112
+                      href={item}
113
+                      target="_blank"
114
+                      rel="noopener noreferrer"
112
                       key={index}
115
                       key={index}
113
-                      src={item}
114
-                      alt={item}
115
-                      style={{ maxWidth: "100%" }}
116
-                    />
116
+                    >
117
+                      <img src={item} alt={item} className="comment-img" />
118
+                    </a>
117
                   );
119
                   );
118
                 })}
120
                 })}
119
               </div>
121
               </div>

+ 4
- 4
src/helper.js View File

62
       // 兼容旧的评
62
       // 兼容旧的评
63
       // 因为旧的评论用 [img url] 方式存储的
63
       // 因为旧的评论用 [img url] 方式存储的
64
       if (isUrl(src)) {
64
       if (isUrl(src)) {
65
-        return `<br/><img src="${src}" alt="${src}" style="max-width: 100%" />`;
65
+        return `<a href="${src}" rel="noopener noreferrer" target="_blank"><img class="comment-img" src="${src}" alt="${src}" /></a>`;
66
       }
66
       }
67
       // 如果不存在对应的表情, 则返回原文
67
       // 如果不存在对应的表情, 则返回原文
68
       const emoji = emojiObejct[src];
68
       const emoji = emojiObejct[src];
69
       if (emoji) {
69
       if (emoji) {
70
-        return `<img src="${prefixUrl}${emoji.value}.${emoji.ext}" alt="${
71
-          emoji.title
72
-        }" />`;
70
+        return `<img class="comment-emoji" src="${prefixUrl}${emoji.value}.${
71
+          emoji.ext
72
+        }" alt="${emoji.title}" />`;
73
       }
73
       }
74
       return `[${src}]`;
74
       return `[${src}]`;
75
     })
75
     })

+ 1
- 0
src/index.js View File

42
         showAlertFavor
42
         showAlertFavor
43
         showError={false}
43
         showError={false}
44
         userId={71299}
44
         userId={71299}
45
+        pageType="pagination"
45
         onError={(msg, { response }) => {
46
         onError={(msg, { response }) => {
46
           if (response.status === 401) {
47
           if (response.status === 401) {
47
             console.log("unlogined");
48
             console.log("unlogined");