Showing
1 changed file
with
7 additions
and
4 deletions
@@ -731,9 +731,9 @@ exports.handlePagerData = (total, params) => { | @@ -731,9 +731,9 @@ exports.handlePagerData = (total, params) => { | ||
731 | pages: [] | 731 | pages: [] |
732 | }; | 732 | }; |
733 | 733 | ||
734 | - let currentPage = parseInt((_.isEmpty(params.page) ? 1 : params.page), 10); // 当前页 | ||
735 | - let perPageCount = parseInt((_.isEmpty(params.limit) ? 60 : params.limit), 10); // 每页商品数 | ||
736 | - let totalPage = parseInt(total / perPageCount, 10) + 1; // 总页数 | 734 | + let currentPage = parseInt(_.get(params, 'page', 1), 10); // 当前页 |
735 | + let perPageCount = parseInt(_.get(params, 'limit', 60), 10); // 每页商品数 | ||
736 | + let totalPage = Math.ceil(total / perPageCount); // 总页数 | ||
737 | 737 | ||
738 | if (currentPage === 1) { | 738 | if (currentPage === 1) { |
739 | // 当前页为 1,一定没有上一页 | 739 | // 当前页为 1,一定没有上一页 |
@@ -773,12 +773,15 @@ exports.handlePagerData = (total, params) => { | @@ -773,12 +773,15 @@ exports.handlePagerData = (total, params) => { | ||
773 | } | 773 | } |
774 | } else if (currentPage > totalPage - 2) { | 774 | } else if (currentPage > totalPage - 2) { |
775 | for (let i = totalPage; i >= totalPage - 4; i--) { | 775 | for (let i = totalPage; i >= totalPage - 4; i--) { |
776 | + | ||
777 | + if (i > 0) { | ||
776 | pages.push({ | 778 | pages.push({ |
777 | url: handleFilterUrl(params, {page: i}), | 779 | url: handleFilterUrl(params, {page: i}), |
778 | num: i, | 780 | num: i, |
779 | cur: currentPage === i | 781 | cur: currentPage === i |
780 | }); | 782 | }); |
781 | } | 783 | } |
784 | + } | ||
782 | pages = _.sortBy(pages, ['num']); | 785 | pages = _.sortBy(pages, ['num']); |
783 | } | 786 | } |
784 | 787 | ||
@@ -795,7 +798,7 @@ exports.handlePagerData = (total, params) => { | @@ -795,7 +798,7 @@ exports.handlePagerData = (total, params) => { | ||
795 | num: '...' | 798 | num: '...' |
796 | }); | 799 | }); |
797 | } | 800 | } |
798 | - if (currentPage < totalPage - 2) { | 801 | + if (currentPage < totalPage - 2 && totalPage > 5) { |
799 | nextPages.push({ | 802 | nextPages.push({ |
800 | num: '...' | 803 | num: '...' |
801 | }); | 804 | }); |
-
Please register or login to post a comment