narro 6 лет назад
Родитель
Сommit
a3da37f04c

+ 1
- 0
README.md Просмотреть файл

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

+ 9
- 1
lib/App.css Просмотреть файл

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

+ 20
- 10
lib/App.js Просмотреть файл

@@ -164,6 +164,8 @@ var App = function (_Component) {
164 164
           _ref$page = _ref.page,
165 165
           page = _ref$page === undefined ? 1 : _ref$page;
166 166
 
167
+      var pageType = this.props.pageType;
168
+
167 169
       this.handleChangeLoading("sGetComment", true);
168 170
       var _props = this.props,
169 171
           API = _props.API,
@@ -178,15 +180,21 @@ var App = function (_Component) {
178 180
 
179 181
         if (list) {
180 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 198
           _this2.setState({
191 199
             list: newList,
192 200
             page: page,
@@ -554,7 +562,8 @@ App.propTypes = {
554 562
   showAlertFavor: _propTypes2.default.bool, // 点赞/取消点赞成功之后,是否通过 Antd 的 Message 组件进行提示
555 563
   showError: _propTypes2.default.bool, // 是否使用Antd的Message组件提示错误信息
556 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 569
 App.defaultProps = {
@@ -564,7 +573,8 @@ App.defaultProps = {
564 573
   showAlertComment: false,
565 574
   showAlertReply: false,
566 575
   showAlertFavor: false,
567
-  showError: true
576
+  showError: true,
577
+  pageType: "more"
568 578
 };
569 579
 
570 580
 exports.Editor = _Editor2.default;

+ 1
- 1
lib/App.js.map
Разница между файлами не показана из-за своего большого размера
Просмотреть файл


+ 5
- 0
lib/components/CommentList/index.css Просмотреть файл

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

+ 54
- 17
lib/components/CommentList/index.js Просмотреть файл

@@ -8,10 +8,16 @@ var _spin = require("antd/es/spin");
8 8
 
9 9
 var _spin2 = _interopRequireDefault(_spin);
10 10
 
11
+var _pagination = require("antd/es/pagination");
12
+
13
+var _pagination2 = _interopRequireDefault(_pagination);
14
+
11 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 17
 require("antd/es/spin/style/css");
14 18
 
19
+require("antd/es/pagination/style/css");
20
+
15 21
 var _react = require("react");
16 22
 
17 23
 var _react2 = _interopRequireDefault(_react);
@@ -26,6 +32,8 @@ var _CommentBox2 = _interopRequireDefault(_CommentBox);
26 32
 
27 33
 require("./index.css");
28 34
 
35
+var _constant = require("../../constant");
36
+
29 37
 function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
30 38
 
31 39
 function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
@@ -52,16 +60,58 @@ var CommentList = function (_Component) {
52 60
       this.props.app.sGetComment();
53 61
     }
54 62
   }, {
55
-    key: "render",
56
-    value: function render() {
63
+    key: "renderPagination",
64
+    value: function renderPagination() {
57 65
       var _props$app = this.props.app,
58 66
           list = _props$app.list,
59 67
           total = _props$app.total,
60 68
           page = _props$app.page,
61
-          loading = _props$app.loading,
69
+          pageType = _props$app.pageType,
62 70
           isNoMoreComment = _props$app.isNoMoreComment,
63 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 116
       var spinning = Boolean(loading.sGetComment || loading.sCommentFavor || loading.sReplyFavor);
67 117
       return _react2.default.createElement(
@@ -80,20 +130,7 @@ var CommentList = function (_Component) {
80 130
           list.map(function (item) {
81 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 Просмотреть файл

@@ -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\";\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 Просмотреть файл

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

+ 14
- 6
lib/components/ContentItem/index.js Просмотреть файл

@@ -188,12 +188,20 @@ var CommentItem = function (_Component) {
188 188
             "div",
189 189
             { className: "comment-item-image" },
190 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 207
           _react2.default.createElement(

+ 1
- 1
lib/components/ContentItem/index.js.map
Разница между файлами не показана из-за своего большого размера
Просмотреть файл


+ 2
- 2
lib/helper.js Просмотреть файл

@@ -74,12 +74,12 @@ function renderContent(content, onClick) {
74 74
     // 兼容旧的评
75 75
     // 因为旧的评论用 [img url] 方式存储的
76 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 80
     var emoji = emojiObejct[src];
81 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 84
     return "[" + src + "]";
85 85
   }).replace(innerUrl, function (a, b) {

+ 1
- 1
lib/helper.js.map
Разница между файлами не показана из-за своего большого размера
Просмотреть файл


+ 1
- 0
lib/index.js Просмотреть файл

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

+ 1
- 1
lib/index.js.map
Разница между файлами не показана из-за своего большого размера
Просмотреть файл


+ 8
- 0
src/App.css Просмотреть файл

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

+ 16
- 7
src/App.js Просмотреть файл

@@ -89,6 +89,7 @@ class App extends Component {
89 89
    * 获取评论列表
90 90
    */
91 91
   sGetComment({ page = 1 } = {}) {
92
+    const { pageType } = this.props;
92 93
     this.handleChangeLoading("sGetComment", true);
93 94
     const { API, type, businessId } = this.props;
94 95
     this.axios
@@ -99,12 +100,18 @@ class App extends Component {
99 100
         const { list, page, total } = response.data;
100 101
         if (list) {
101 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 115
           this.setState({
109 116
             list: newList,
110 117
             page,
@@ -429,7 +436,8 @@ App.propTypes = {
429 436
   showAlertFavor: PropTypes.bool, // 点赞/取消点赞成功之后,是否通过 Antd 的 Message 组件进行提示
430 437
   showError: PropTypes.bool, // 是否使用Antd的Message组件提示错误信息
431 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 443
 App.defaultProps = {
@@ -439,7 +447,8 @@ App.defaultProps = {
439 447
   showAlertComment: false,
440 448
   showAlertReply: false,
441 449
   showAlertFavor: false,
442
-  showError: true
450
+  showError: true,
451
+  pageType: "more"
443 452
 };
444 453
 
445 454
 export { Editor, RenderText };

+ 5
- 0
src/components/CommentList/index.css Просмотреть файл

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

+ 36
- 13
src/components/CommentList/index.js Просмотреть файл

@@ -1,8 +1,9 @@
1 1
 import React, { Component } from "react";
2
-import { Spin } from "antd";
2
+import { Spin, Pagination } from "antd";
3 3
 import Comment from "../../Comment";
4 4
 import CommentBox from "../CommentBox";
5 5
 import "./index.css";
6
+import { LIMIT } from "../../constant";
6 7
 
7 8
 class CommentList extends Component {
8 9
   constructor(props) {
@@ -14,15 +15,46 @@ class CommentList extends Component {
14 15
     this.props.app.sGetComment();
15 16
   }
16 17
 
17
-  render() {
18
+  renderPagination() {
18 19
     const {
19 20
       list,
20 21
       total,
21 22
       page,
22
-      loading,
23
+      pageType,
23 24
       isNoMoreComment,
24 25
       sGetComment
25 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 59
     const spinning = Boolean(
28 60
       loading.sGetComment || loading.sCommentFavor || loading.sReplyFavor
@@ -34,16 +66,7 @@ class CommentList extends Component {
34 66
           {list.map(item => (
35 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 70
         </Spin>
48 71
       </div>
49 72
     );

+ 15
- 0
src/components/ContentItem/index.css Просмотреть файл

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

+ 7
- 5
src/components/ContentItem/index.js Просмотреть файл

@@ -108,12 +108,14 @@ class CommentItem extends Component {
108 108
               <div className="comment-item-image">
109 109
                 {imageList.map((item, index) => {
110 110
                   return (
111
-                    <img
111
+                    <a
112
+                      href={item}
113
+                      target="_blank"
114
+                      rel="noopener noreferrer"
112 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 121
               </div>

+ 4
- 4
src/helper.js Просмотреть файл

@@ -62,14 +62,14 @@ export function renderContent(content, onClick) {
62 62
       // 兼容旧的评
63 63
       // 因为旧的评论用 [img url] 方式存储的
64 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 68
       const emoji = emojiObejct[src];
69 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 74
       return `[${src}]`;
75 75
     })

+ 1
- 0
src/index.js Просмотреть файл

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