index.vue 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <template>
  2. <div :class="{ hidden }" class="pagination-container">
  3. <el-pagination
  4. :background="background"
  5. v-model:current-page="currentPage"
  6. v-model:page-size="pageSize"
  7. :layout="layout"
  8. :page-sizes="pageSizes"
  9. :pager-count="pagerCount"
  10. :total="total"
  11. @size-change="handleSizeChange"
  12. @current-change="handleCurrentChange"
  13. />
  14. </div>
  15. </template>
  16. <script setup>
  17. // TODO 芋艿:ts 重写
  18. // TODO 芋艿:scrollTo 接入
  19. // import { scrollTo } from '@/utils/scroll-to'
  20. import { computed } from 'vue'
  21. const props = defineProps({
  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. const emit = defineEmits(['update:page', 'update:limit', 'pagination', 'pagination'])
  63. const currentPage = computed({
  64. get() {
  65. return props.page
  66. },
  67. set(val) {
  68. emit('update:page', val)
  69. }
  70. })
  71. const pageSize = computed({
  72. get() {
  73. return props.limit
  74. },
  75. set(val) {
  76. emit('update:limit', val)
  77. }
  78. })
  79. function handleSizeChange(val) {
  80. if (currentPage.value * val > props.total) {
  81. currentPage.value = 1
  82. }
  83. emit('pagination', { page: currentPage.value, limit: val })
  84. if (props.autoScroll) {
  85. // scrollTo(0, 800)
  86. }
  87. }
  88. function handleCurrentChange(val) {
  89. emit('pagination', { page: val, limit: pageSize.value })
  90. if (props.autoScroll) {
  91. // scrollTo(0, 800)
  92. }
  93. }
  94. </script>
  95. <style scoped>
  96. .pagination-container {
  97. background: #fff;
  98. padding: 32px 16px;
  99. }
  100. .pagination-container.hidden {
  101. display: none;
  102. }
  103. </style>