3de00fdc41a62cfd27d65051ce8007fcdb1295fd.svn-base 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <template>
  2. <div :class="{'hidden':hidden}" class="pagination-container">
  3. <el-pagination
  4. ref="pagination"
  5. :background="background"
  6. :current-page.sync="currentPage"
  7. :page-size.sync="pageSize"
  8. :layout="layout"
  9. :page-sizes="pageSizes"
  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: 10
  33. },
  34. pageSizes: {
  35. type: Array,
  36. default() {
  37. return [10, 20, 30, 50, 100]
  38. // return [50, 30, 20, 10]
  39. }
  40. },
  41. layout: {
  42. type: String,
  43. default: 'total, sizes, prev, pager, next, jumper'
  44. },
  45. background: {
  46. type: Boolean,
  47. default: true
  48. },
  49. autoScroll: {
  50. type: Boolean,
  51. default: true
  52. },
  53. hidden: {
  54. type: Boolean,
  55. default: false
  56. }
  57. },
  58. computed: {
  59. currentPage: {
  60. get() {
  61. return this.page
  62. },
  63. set(val) {
  64. this.$emit('update:page', val)
  65. }
  66. },
  67. pageSize: {
  68. get() {
  69. return this.limit
  70. },
  71. set(val) {
  72. this.$emit('update:limit', val)
  73. }
  74. }
  75. },
  76. methods: {
  77. handleSizeChange(val) {
  78. this.$emit('pagination', { page: this.currentPage, limit: val })
  79. if (this.autoScroll) {
  80. scrollTo(0, 800)
  81. }
  82. },
  83. handleCurrentChange(val) {
  84. this.$emit('pagination', { page: val, limit: this.pageSize })
  85. if (this.autoScroll) {
  86. scrollTo(0, 800)
  87. }
  88. }
  89. }
  90. }
  91. </script>
  92. <style scoped>
  93. .pagination-container {
  94. background: #fff;
  95. padding: 16px 16px;
  96. }
  97. .pagination-container.hidden {
  98. display: none;
  99. }
  100. </style>