index.vue 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <template>
  2. <div :class="{'hidden':hidden}" :style="{'float':float}" 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. :hide-on-single-page="hideOnSinglePage"
  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. layout: {
  41. type: String,
  42. default: 'total, sizes, prev, pager, next, jumper'
  43. },
  44. background: {
  45. type: Boolean,
  46. default: true
  47. },
  48. autoScroll: {
  49. type: Boolean,
  50. default: true
  51. },
  52. hidden: {
  53. type: Boolean,
  54. default: false
  55. },
  56. float: {
  57. type: String,
  58. default: 'right'
  59. },
  60. hideOnSinglePage: {
  61. type: Boolean,
  62. default: true
  63. }
  64. },
  65. computed: {
  66. currentPage: {
  67. get() {
  68. return this.page
  69. },
  70. set(val) {
  71. this.$emit('update:page', val)
  72. }
  73. },
  74. pageSize: {
  75. get() {
  76. return this.limit
  77. },
  78. set(val) {
  79. this.$emit('update:limit', val)
  80. }
  81. }
  82. },
  83. methods: {
  84. handleSizeChange(val) {
  85. this.$emit('pagination', { page: this.currentPage, limit: val })
  86. if (this.autoScroll) {
  87. scrollTo(0, 800)
  88. }
  89. },
  90. handleCurrentChange(val) {
  91. this.$emit('pagination', { page: val, limit: this.pageSize })
  92. if (this.autoScroll) {
  93. scrollTo(0, 800)
  94. }
  95. }
  96. }
  97. }
  98. </script>
  99. <style scoped>
  100. .pagination-container {
  101. background: #fff;
  102. padding: 32px 16px;
  103. }
  104. .pagination-container.hidden {
  105. display: none;
  106. }
  107. </style>