index.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <template>
  2. <div :class="{'hidden':hidden}"
  3. class="pagination-container">
  4. <!-- :background="background" -->
  5. <el-pagination :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. </div>
  14. </template>
  15. <script>
  16. import { scrollTo } from '@/utils/scroll-to'
  17. import { Searchs } from '@/helpers'
  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: 10
  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. sync: {
  56. type: Boolean,
  57. default: false
  58. }
  59. },
  60. computed: {
  61. currentPage: {
  62. get () {
  63. console.log(this.page)
  64. return this.page
  65. },
  66. set (val) {
  67. this.$emit('update:page', val)
  68. }
  69. },
  70. pageSize: {
  71. get () {
  72. return this.limit
  73. },
  74. set (val) {
  75. this.$emit('update:limit', val)
  76. }
  77. }
  78. },
  79. mounted() {
  80. if (this.sync) {
  81. const searchs = new Searchs(this.$route.fullPath)
  82. const active = searchs.get()
  83. // for (const key in active.page) {
  84. // if (active.page.hasOwnProperty(key)) {
  85. // const item = active.page[key];
  86. // this[key] = item
  87. // // this.$emit('update:' + key, item)
  88. // }
  89. // }
  90. this.$emit('update:page', active.page.page)
  91. this.$emit('currentPage', active.page.page)
  92. // this.page = active.page.page
  93. }
  94. },
  95. methods: {
  96. syncStore() {
  97. if (this.sync) {
  98. const searchs = new Searchs(this.$route.fullPath)
  99. searchs.update(this._props, undefined, 'page')
  100. }
  101. },
  102. handleSizeChange (val) {
  103. this.$emit('pagination', { page: this.currentPage, limit: val })
  104. if (this.autoScroll) {
  105. scrollTo(0, 800)
  106. }
  107. this.syncStore()
  108. },
  109. handleCurrentChange (val) {
  110. this.$emit('pagination', { page: val, limit: this.pageSize })
  111. if (this.autoScroll) {
  112. scrollTo(0, 800)
  113. }
  114. this.syncStore()
  115. }
  116. }
  117. }
  118. </script>
  119. <style scoped>
  120. .pagination-container {
  121. background: #fff;
  122. padding: 32px 16px;
  123. width: 100%;
  124. display: flex;
  125. flex-direction: row;
  126. justify-content: center;
  127. }
  128. .pagination-container.hidden {
  129. display: none;
  130. }
  131. </style>