index.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <template >
  2. <div class="tuwe">
  3. <div :class="{'hidden':hidden}" class="pagination-container ">
  4. <el-pagination
  5. :current-page.sync="currentPage"
  6. :page-size.sync="pageSize"
  7. :layout="layout"
  8. :small="true"
  9. :page-sizes="pageSizes"
  10. :pager-count="pagerCount"
  11. :total="total"
  12. v-bind="$attrs"
  13. @size-change="handleSizeChange"
  14. @current-change="handleCurrentChange"
  15. />
  16. </div>
  17. </div>
  18. </template>
  19. <script>
  20. import { scrollTo } from '@/utils/scroll-to'
  21. export default {
  22. name: 'Pagination',
  23. props: {
  24. total: {
  25. required: true,
  26. type: Number
  27. },
  28. page: {
  29. type: Number,
  30. default: 1
  31. },
  32. limit: {
  33. type: Number,
  34. default: 20
  35. },
  36. pageSizes: {
  37. type: Array,
  38. default() {
  39. return [3,10, 20, 30, 50]
  40. }
  41. },
  42. // 移动端页码按钮的数量端默认值5
  43. pagerCount: {
  44. type: Number,
  45. default: document.body.clientWidth < 992 ? 5 : 7
  46. },
  47. layout: {
  48. type: String,
  49. default: 'total, prev, pager, next'
  50. },
  51. background: {
  52. type: Boolean,
  53. default: true
  54. },
  55. autoScroll: {
  56. type: Boolean,
  57. default: true
  58. },
  59. hidden: {
  60. type: Boolean,
  61. default: false
  62. }
  63. },
  64. data() {
  65. return {
  66. };
  67. },
  68. computed: {
  69. currentPage: {
  70. get() {
  71. return this.page
  72. },
  73. set(val) {
  74. this.$emit('update:page', val)
  75. }
  76. },
  77. pageSize: {
  78. get() {
  79. return this.limit
  80. },
  81. set(val) {
  82. this.$emit('update:limit', val)
  83. }
  84. }
  85. },
  86. methods: {
  87. handleSizeChange(val) {
  88. if (this.currentPage * val > this.total) {
  89. this.currentPage = 1
  90. }
  91. this.$emit('pagination', { page: this.currentPage, limit: val })
  92. if (this.autoScroll) {
  93. scrollTo(0, 800)
  94. }
  95. },
  96. handleCurrentChange(val) {
  97. this.$emit('pagination', { page: val, limit: this.pageSize })
  98. if (this.autoScroll) {
  99. scrollTo(0, 800)
  100. }
  101. }
  102. }
  103. }
  104. </script>
  105. <style scoped>
  106. .pagination-container {
  107. /* background: #fff; */
  108. /* padding: 32px 16px; */
  109. }
  110. .tuwe {
  111. .el-input__inner{
  112. border: 0;
  113. background: #DDEBE7;
  114. }
  115. .el-pagination button:disabled{
  116. background-color:#DDEBE7;
  117. color: #4B5A6D;
  118. }
  119. .el-pagination .btn-prev, .el-pagination .btn-next{
  120. background-color:#DDEBE7;
  121. color: #4B5A6D;
  122. }
  123. .el-pager li{
  124. margin-right: 5px;
  125. background-color:#DDEBE7;
  126. color: #4B5A6D;
  127. }
  128. .el-pagination.is-background .el-pager li:not(.disabled).active{
  129. background-color:#03BF8A;
  130. color: #fff;
  131. }
  132. .el-pager li.active{
  133. background-color:#03BF8A;
  134. color: #fff;
  135. }
  136. .el-pager li:nth-child(1){
  137. margin-left: 5px;
  138. }
  139. }
  140. .tuwe .pagination-container .el-pagination{
  141. left: 50%;
  142. transform: translateX(-50%);
  143. text-align: center;
  144. }
  145. .pagination-container.hidden {
  146. display: none;
  147. }
  148. </style>