index.vue 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <template>
  2. <div :class="{'hidden':hidden}" class="pagination-container">
  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. computed: {
  63. currentPage: {
  64. get() {
  65. return this.page
  66. },
  67. set(val) {
  68. this.$emit('update:page', val)
  69. }
  70. },
  71. pageSize: {
  72. get() {
  73. return this.limit
  74. },
  75. set(val) {
  76. this.$emit('update:limit', val)
  77. }
  78. }
  79. },
  80. methods: {
  81. handleSizeChange(val) {
  82. this.$emit('pagination', { page: this.currentPage, limit: val })
  83. if (this.autoScroll) {
  84. scrollTo(0, 800)
  85. }
  86. },
  87. handleCurrentChange(val) {
  88. this.$emit('pagination', { page: val, limit: this.pageSize })
  89. if (this.autoScroll) {
  90. scrollTo(0, 800)
  91. }
  92. }
  93. }
  94. }
  95. </script>
  96. <style scoped>
  97. .pagination-container {
  98. background: #fff;
  99. padding: 32px 16px;
  100. }
  101. .pagination-container.hidden {
  102. display: none;
  103. }
  104. </style>