page.html 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <ul aria-label="Page navigation" id="pages"></ul>
  2. <script type="text/javascript">
  3. let options = {
  4. bootstrapMajorVersion: 3,
  5. currentPage: "<%= pages.current %>",
  6. totalPages: "<%= pages.total %>",
  7. size: "normal",
  8. itemContainerClass: function(type, page, current) {
  9. let className = 'page-item';
  10. this.currentPage = parseInt(this.currentPage);
  11. this.totalPages = parseInt(this.totalPages);
  12. switch (type) {
  13. case "prev":
  14. className = this.currentPage === 1 ? className + ' disabled' : className;
  15. break;
  16. case "next":
  17. className = this.currentPage === this.totalPages ? className + ' disabled' : className;
  18. break;
  19. case "page":
  20. className = page === this.currentPage ? className + ' active' : className;
  21. break;
  22. }
  23. return className;
  24. },
  25. itemContentClass: function(type, page, current) {
  26. return 'page-link';
  27. },
  28. itemTexts: function(type, page, current) {
  29. switch (type) {
  30. case "first":
  31. return "&laquo;";
  32. case "prev":
  33. return "上一页";
  34. case "next":
  35. return "下一页";
  36. case "last":
  37. return "最后一页";
  38. case "page":
  39. return page;
  40. }
  41. },
  42. shouldShowPage: function (type, page, current) {
  43. let result = true;
  44. switch (type) {
  45. case "first":
  46. result = (current !== 1);
  47. break;
  48. case "prev":
  49. break;
  50. case "next":
  51. break;
  52. case "last":
  53. result = false;
  54. break;
  55. case "page":
  56. result = true;
  57. break;
  58. }
  59. return result;
  60. },
  61. pageUrl: function(type, page, current){
  62. let queryData = JSON.parse('<%- pages.queryData %>');
  63. // 如果没有附带查询条件则直接返回
  64. if (Object.keys(queryData).length <= 0) {
  65. return "?page=" + page;
  66. }
  67. // 有其它数据则重新赋值page,然后组合字符串
  68. queryData.page = page;
  69. let queryArray = [];
  70. for(let tmp in queryData) {
  71. let tempString = tmp + '=' + queryData[tmp];
  72. queryArray.push(tempString);
  73. }
  74. let firstQuery = queryArray.shift();
  75. let queryString = queryArray.join('&');
  76. return queryString === '' ? '?' + firstQuery : '?' + firstQuery + '&' + queryString;
  77. }
  78. };
  79. if (options.totalPages > 0) {
  80. $("#pages").bootstrapPaginator(options);
  81. }
  82. </script>