index.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. <template>
  2. <view class="u-pagination-container">
  3. <view class="total-bix">
  4. 共 {{total}} 项
  5. </view>
  6. <view class="page-change-box">
  7. <button class="go-btn go-pre-btn page-item" :disabled="currentPage === 1"
  8. @click="changeCurrentPage(currentPage-1)">
  9. <i class="iconfont icon-Left"></i>
  10. </button>
  11. <template v-if="pageNum<=5">
  12. <view class="page-item" :class="{'active': n+1 === currentPage}" v-for="n in pageNum" :key="n"
  13. @click="changeCurrentPage(n+1)">
  14. {{n+1}}
  15. </view>
  16. </template>
  17. <template v-else>
  18. <view class="page-item" :class="{'active': currentPage === 1}" @click="changeCurrentPage(1)">
  19. 1
  20. </view>
  21. <view class="page-item" :class="{'active': currentPage === 2}" v-if="currentPage<4"
  22. @click="changeCurrentPage(2)">
  23. 2
  24. </view>
  25. <view class="page-item" :class="{'active': currentPage === 3}" v-if="currentPage<4"
  26. @click="changeCurrentPage(3)">
  27. 3
  28. </view>
  29. <view class="page-item munber-point" v-if="currentPage>=4">
  30. ...
  31. </view>
  32. <view class="page-item active" v-if="currentPage>=4 && currentPage<pageNum-2">
  33. {{currentPage}}
  34. </view>
  35. <view class="page-item munber-point" v-if="currentPage<pageNum-2">
  36. ...
  37. </view>
  38. <view class="page-item" :class="{'active': currentPage === pageNum-2}" v-if="currentPage>=pageNum-2"
  39. @click="changeCurrentPage(pageNum-2)">
  40. {{pageNum-2}}
  41. </view>
  42. <view class="page-item" :class="{'active': currentPage === pageNum-1}" v-if="currentPage>=pageNum-2"
  43. @click="changeCurrentPage(pageNum-1)">
  44. {{pageNum-1}}
  45. </view>
  46. <view class="page-item" :class="{'active': currentPage === pageNum}" @click="changeCurrentPage(pageNum)">
  47. {{pageNum}}
  48. </view>
  49. </template>
  50. <button class="go-btn go-next-btn page-item" :disabled="currentPage === pageNum"
  51. @click="changeCurrentPage(currentPage+1)">
  52. <i class="iconfont icon-Left-1"></i>
  53. </button>
  54. </view>
  55. <view class="jump-page-box">
  56. <view class="junp-text">
  57. 前往
  58. </view>
  59. <input type="text" v-model="jumpPage" @confirm="changeCurrentPage(jumpPage)" />
  60. <view class="junp-text">
  61. </view>
  62. </view>
  63. </view>
  64. </template>
  65. <script>
  66. export default {
  67. props: {
  68. title: String,
  69. page: {
  70. type: Number,
  71. default: 1
  72. },
  73. pageSize: {
  74. type: Number,
  75. default: 10
  76. },
  77. total: {
  78. type: Number,
  79. default: 0
  80. },
  81. },
  82. computed: {
  83. pageNum() {
  84. return Math.ceil(this.total / this.pageSize)
  85. }
  86. },
  87. watch: {
  88. page(val) {
  89. this.currentPage = val
  90. }
  91. },
  92. data() {
  93. return {
  94. jumpPage: 1,
  95. currentPage: 1
  96. }
  97. },
  98. created() {},
  99. mounted() {},
  100. methods: {
  101. changeCurrentPage(page) {
  102. let goPage = Number(page)
  103. if (goPage > this.pageNum || goPage < 1) {
  104. uni.showToast({
  105. title: '所选页面不存在,请重新选择!',
  106. icon: 'none',
  107. duration: 2000
  108. });
  109. } else {
  110. this.currentPage = goPage
  111. this.$emit('page-change', this.currentPage)
  112. uni.pageScrollTo({
  113. scrollTop: 0, // 滚动到顶部
  114. duration: 300 // 滚动时间,单位为毫秒
  115. });
  116. }
  117. }
  118. }
  119. }
  120. </script>
  121. <style lang="scss">
  122. .u-pagination-container {
  123. display: flex;
  124. align-items: center;
  125. grid-gap: 26rpx;
  126. font-size: 20rpx;
  127. color: #555555;
  128. margin-top: 40rpx;
  129. .page-change-box {
  130. display: flex;
  131. grid-gap: 10rpx;
  132. .page-item {
  133. width: 46rpx;
  134. height: 46rpx;
  135. background-color: #F5F6F8;
  136. border-radius: 3rpx;
  137. display: flex;
  138. justify-content: center;
  139. align-items: center;
  140. color: #94A3B8;
  141. &.go-btn {
  142. padding: unset;
  143. margin: unset;
  144. &::after {
  145. border: unset;
  146. }
  147. }
  148. &.active {
  149. background-color: #E57519;
  150. color: #FFFFFF;
  151. }
  152. &>i {
  153. font-size: 24rpx;
  154. }
  155. }
  156. }
  157. .jump-page-box {
  158. display: flex;
  159. grid-gap: 10rpx;
  160. align-items: center;
  161. input {
  162. width: 50rpx;
  163. height: 50rpx;
  164. background-color: #FFFFFF;
  165. border-radius: 6rpx;
  166. border: 1rpx solid #94A3B8;
  167. text-align: center;
  168. }
  169. }
  170. }
  171. </style>