Parcourir la source

添加pageType slice

cloudzqy il y a 6 ans
Parent
révision
c53cfb83d9
3 fichiers modifiés avec 22 ajouts et 8 suppressions
  1. 2
    0
      README.md
  2. 8
    4
      src/App.js
  3. 12
    4
      src/components/CommentList/index.js

+ 2
- 0
README.md Voir le fichier

@@ -201,6 +201,8 @@ main();
201 201
 | token            | string         |                                    | false    | [deprecated] token,用于身份认证,非必须。默认使用 cookie                             |
202 202
 | pageType         | string         | more                               | false    | 分页类别, more-加载更多 pagination-页码                                              |
203 203
 | page             | number         |                                    | false    | 页码受控模式,如果传递了此参数,则需要通过onPageChange回调手动维护page.                 |
204
+| limit             | number         |10                                  | false    | 一次加载的评论数量            |
205
+| onGetMoreBtnClick      | function() |                                    | false    | 点击查看更多按钮的回调                            |
204 206
 | onPageChange     | function(page) |                                    | false    | 页码发生变化时的回调,注意:分页数据获取还是在组件内部处理的                            |
205 207
 | onDelete         | function(type) |                                    | false    | 评论或回复删除成功后的回调, type: "comment" \| "reply" , 用于区分删除的是评论还是回复 |
206 208
 

+ 8
- 4
src/App.js Voir le fichier

@@ -92,10 +92,10 @@ class App extends Component {
92 92
   sGetComment({ page = 1 } = {}) {
93 93
     const { pageType } = this.props;
94 94
     this.handleChangeLoading("sGetComment", true);
95
-    const { API, type, businessId } = this.props;
95
+    const { API, type, businessId, limit } = this.props;
96 96
     this.axios
97 97
       .get(
98
-        `${API}/comments?type=${type}&business_id=${businessId}&page=${page}&limit=${LIMIT}`
98
+        `${API}/comments?type=${type}&business_id=${businessId}&page=${page}&limit=${limit}`
99 99
       )
100 100
       .then(response => {
101 101
         const { list, page, total } = response.data;
@@ -136,9 +136,9 @@ class App extends Component {
136 136
    */
137 137
   sGetReply({ commentId, page = 1 } = {}) {
138 138
     this.handleChangeLoading("sGetReply", true);
139
-    const { API } = this.props;
139
+    const { API, limit } = this.props;
140 140
     this.axios
141
-      .get(`${API}/replies?comment_id=${commentId}&page=${page}&limit=${LIMIT}`)
141
+      .get(`${API}/replies?comment_id=${commentId}&page=${page}&limit=${limit}`)
142 142
       .then(response => {
143 143
         if (!response.data.list) {
144 144
           message.info("没有更多数据了!");
@@ -442,7 +442,9 @@ App.propTypes = {
442 442
   userId: PropTypes.number, // 用户id, comment内部不维护用户id, 调用组件时传递过来, 目前用于判断是否显示删除按钮
443 443
   pageType: PropTypes.string, // 分页类型
444 444
   page: PropTypes.number, // 页码
445
+  limit: PropTypes.number, // 一次加载评论数量
445 446
   onPageChange: PropTypes.func, // 页码变化回调
447
+  onGetMoreBtnClick: PropTypes.func, // 点击查看更多按钮回调
446 448
   onDelete: PropTypes.func
447 449
 };
448 450
 
@@ -455,6 +457,8 @@ App.defaultProps = {
455 457
   showAlertFavor: false,
456 458
   showError: true,
457 459
   pageType: "more",
460
+  limit: LIMIT,
461
+  onGetMoreBtnClick: () => {},
458 462
   onPageChange: page => {},
459 463
   onDelete: () => {}
460 464
 };

+ 12
- 4
src/components/CommentList/index.js Voir le fichier

@@ -3,7 +3,6 @@ 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";
7 6
 
8 7
 class CommentList extends Component {
9 8
   constructor(props) {
@@ -21,11 +20,20 @@ class CommentList extends Component {
21 20
       total,
22 21
       page,
23 22
       pageType,
23
+      limit,
24 24
       isNoMoreComment,
25 25
       sGetComment,
26
-      onPageChange
26
+      onPageChange,
27
+      onGetMoreBtnClick
27 28
     } = this.props.app;
28
-    if (pageType === "more") {
29
+    if (pageType === "slice") {
30
+      // 截断多余评论,通过点击查看更多跳转
31
+      return (
32
+        <div className="comment-list-show-more" onClick={onGetMoreBtnClick}>
33
+          <span>查看更多</span>
34
+        </div>
35
+      );
36
+    } else if (pageType === "more") {
29 37
       if (!isNoMoreComment && list.length !== total) {
30 38
         return (
31 39
           <div
@@ -45,7 +53,7 @@ class CommentList extends Component {
45 53
       return (
46 54
         <div className="comment-list-pagination">
47 55
           <Pagination
48
-            pageSize={LIMIT}
56
+            pageSize={limit}
49 57
             current={page}
50 58
             total={total}
51 59
             onChange={p => {