indexNew.vue 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <template>
  2. <div :class="{'hidden':hidden}" class="pagination-container-new">
  3. <el-pagination
  4. :background="background"
  5. :current-page.sync="currentPage"
  6. :page-size.sync="pageSize"
  7. :layout="layout"
  8. :page-sizes="pageSizes"
  9. :pager-count="pagerCount"
  10. :total="total"
  11. v-bind="$attrs"
  12. @size-change="handleSizeChange"
  13. @current-change="handleCurrentChange"
  14. />
  15. </div>
  16. </template>
  17. <script>
  18. import { scrollTo } from '@/utils/scroll-to'
  19. export default {
  20. name: 'Pagination',
  21. props: {
  22. total: {
  23. required: true,
  24. type: Number
  25. },
  26. page: {
  27. type: Number,
  28. default: 1
  29. },
  30. limit: {
  31. type: Number,
  32. default: 20
  33. },
  34. pageSizes: {
  35. type: Array,
  36. default() {
  37. return [10, 20, 30, 50]
  38. }
  39. },
  40. // 移动端页码按钮的数量端默认值5
  41. pagerCount: {
  42. type: Number,
  43. default: document.body.clientWidth < 992 ? 5 : 7
  44. },
  45. layout: {
  46. type: String,
  47. default: 'total, sizes, prev, pager, next, jumper'
  48. },
  49. background: {
  50. type: Boolean,
  51. default: true
  52. },
  53. autoScroll: {
  54. type: Boolean,
  55. default: true
  56. },
  57. hidden: {
  58. type: Boolean,
  59. default: false
  60. }
  61. },
  62. data() {
  63. return {
  64. };
  65. },
  66. computed: {
  67. currentPage: {
  68. get() {
  69. return this.page
  70. },
  71. set(val) {
  72. this.$emit('update:page', val)
  73. }
  74. },
  75. pageSize: {
  76. get() {
  77. return this.limit
  78. },
  79. set(val) {
  80. this.$emit('update:limit', val)
  81. }
  82. }
  83. },
  84. methods: {
  85. handleSizeChange(val) {
  86. if (this.currentPage * val > this.total) {
  87. this.currentPage = 1
  88. }
  89. this.$emit('pagination', { page: this.currentPage, limit: val })
  90. if (this.autoScroll) {
  91. scrollTo(0, 800)
  92. }
  93. },
  94. handleCurrentChange(val) {
  95. this.$emit('pagination', { page: val, limit: this.pageSize })
  96. if (this.autoScroll) {
  97. scrollTo(0, 800)
  98. }
  99. }
  100. }
  101. }
  102. </script>
  103. <style scoped>
  104. .pagination-container-new {
  105. background: #fff;
  106. }
  107. .pagination-container-new.hidden {
  108. display: none;
  109. }
  110. </style>