index.vue 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. :total="total"
  10. v-bind="$attrs"
  11. @size-change="handleSizeChange"
  12. @current-change="handleCurrentChange"
  13. />
  14. </div>
  15. </template>
  16. <script>
  17. import { scrollTo } from '@/utils/scroll-to'
  18. export default {
  19. name: 'Pagination',
  20. props: {
  21. total: {
  22. required: true,
  23. type: Number
  24. },
  25. page: {
  26. type: Number,
  27. default: 1
  28. },
  29. limit: {
  30. type: Number,
  31. default: 20
  32. },
  33. pageSizes: {
  34. type: Array,
  35. default() {
  36. return [10, 20, 30, 50]
  37. }
  38. },
  39. layout: {
  40. type: String,
  41. default: 'total, sizes, prev, pager, next, jumper'
  42. },
  43. background: {
  44. type: Boolean,
  45. default: true
  46. },
  47. autoScroll: {
  48. type: Boolean,
  49. default: true
  50. },
  51. hidden: {
  52. type: Boolean,
  53. default: false
  54. }
  55. },
  56. computed: {
  57. currentPage: {
  58. get() {
  59. return this.page
  60. },
  61. set(val) {
  62. this.$emit('update:page', val)
  63. }
  64. },
  65. pageSize: {
  66. get() {
  67. return this.limit
  68. },
  69. set(val) {
  70. this.$emit('update:limit', val)
  71. }
  72. }
  73. },
  74. methods: {
  75. handleSizeChange(val) {
  76. this.$emit('pagination', { page: this.currentPage, limit: val })
  77. if (this.autoScroll) {
  78. scrollTo(0, 800)
  79. }
  80. },
  81. handleCurrentChange(val) {
  82. this.$emit('pagination', { page: val, limit: this.pageSize })
  83. if (this.autoScroll) {
  84. scrollTo(0, 800)
  85. }
  86. }
  87. }
  88. }
  89. </script>
  90. <style scoped>
  91. .pagination-container {
  92. background: #fff;
  93. padding: 32px 16px;
  94. }
  95. .pagination-container.hidden {
  96. display: none;
  97. }
  98. </style>