tui-pagination.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. <template>
  2. <view class="tui-pagination__box">
  3. <view class="tui-pagination__btn"
  4. :class="{'tui-pagination__disabled':currentIndex === 1,'tui-pagination__hover':currentIndex !== 1}"
  5. :style="{width:width+'rpx',height:height+'rpx',borderColor:borderColor,backgroundColor:backgroundColor,borderRadius:radius}"
  6. @click="clickPrev">
  7. <text :style="{color:color,fontSize:size+'rpx'}" v-if="!custom">{{prevText}}</text>
  8. <slot name="prev"></slot>
  9. </view>
  10. <view class="tui-pagination__num" v-if="isPage">
  11. <text :style="{color:currentColor,fontSize:pageFontSize+'rpx'}">{{currentIndex}}</text>
  12. <text :style="{color:pageColor,fontSize:pageFontSize+'rpx'}">/{{maxPage || 0}}</text>
  13. </view>
  14. <view class="tui-pagination__btn"
  15. :class="{'tui-pagination__disabled':currentIndex === maxPage,'tui-pagination__hover':currentIndex !== maxPage}"
  16. :style="{width:width+'rpx',height:height+'rpx',borderColor:borderColor,backgroundColor:backgroundColor,borderRadius:radius}"
  17. @click="clickNext">
  18. <text :style="{color:color,fontSize:size+'rpx'}" v-if="!custom">{{nextText}}</text>
  19. <slot name="next"></slot>
  20. </view>
  21. </view>
  22. </template>
  23. <script>
  24. export default {
  25. name: "tui-pagination",
  26. emits: ['prev', 'next', 'change'],
  27. props: {
  28. prevText: {
  29. type: String,
  30. default: '上一页'
  31. },
  32. nextText: {
  33. type: String,
  34. default: '下一页'
  35. },
  36. width: {
  37. type: Number,
  38. default: 156
  39. },
  40. height: {
  41. type: Number,
  42. default: 68
  43. },
  44. borderColor: {
  45. type: String,
  46. default: 'transparent'
  47. },
  48. backgroundColor: {
  49. type: String,
  50. default: '#fff'
  51. },
  52. color: {
  53. type: String,
  54. default: '#333'
  55. },
  56. size: {
  57. type: [Number, String],
  58. default: 28
  59. },
  60. radius: {
  61. type: String,
  62. default: '8rpx'
  63. },
  64. //是否自定义按钮显示内容
  65. custom: {
  66. type: Boolean,
  67. default: false
  68. },
  69. //当前页码
  70. current: {
  71. type: [Number, String],
  72. default: 1
  73. },
  74. //当前页码字体颜色
  75. currentColor: {
  76. type: String,
  77. default: '#5677fc'
  78. },
  79. //页码字体颜色
  80. pageColor: {
  81. type: String,
  82. default: '#333'
  83. },
  84. //页码字体大小
  85. pageFontSize: {
  86. type: [Number, String],
  87. default: 36
  88. },
  89. //是否需要展示页码
  90. isPage: {
  91. type: Boolean,
  92. default: true
  93. },
  94. //数据总量
  95. total: {
  96. type: [Number, String],
  97. default: 0
  98. },
  99. //每页数据量
  100. pageSize: {
  101. type: [Number, String],
  102. default: 10
  103. }
  104. },
  105. computed: {
  106. maxPage() {
  107. let maxPage = 1
  108. let total = Number(this.total)
  109. let pageSize = Number(this.pageSize)
  110. if (total && pageSize) {
  111. maxPage = Math.ceil(total / pageSize)
  112. }
  113. return maxPage
  114. }
  115. },
  116. watch: {
  117. current(val) {
  118. this.currentIndex = +val
  119. }
  120. },
  121. created() {
  122. this.currentIndex = +this.current
  123. },
  124. data() {
  125. return {
  126. currentIndex: 1
  127. };
  128. },
  129. methods: {
  130. clickPrev() {
  131. if (Number(this.currentIndex) === 1) return;
  132. this.currentIndex -= 1
  133. this.change('prev')
  134. },
  135. clickNext() {
  136. if (Number(this.currentIndex) === this.maxPage) return;
  137. this.currentIndex += 1
  138. this.change('next')
  139. },
  140. change(e) {
  141. this.$emit('change', {
  142. type: e,
  143. current: this.currentIndex
  144. })
  145. }
  146. }
  147. }
  148. </script>
  149. <style scoped>
  150. .tui-pagination__box {
  151. flex: 1;
  152. /* #ifndef APP-NVUE */
  153. width: 100%;
  154. display: flex;
  155. /* #endif */
  156. position: relative;
  157. overflow: hidden;
  158. flex-direction: row;
  159. justify-content: space-between;
  160. align-items: center;
  161. }
  162. .tui-pagination__btn {
  163. /* #ifndef APP-NVUE */
  164. display: flex;
  165. box-sizing: border-box;
  166. /* #endif */
  167. position: relative;
  168. flex-direction: row;
  169. justify-content: center;
  170. align-items: center;
  171. text-align: center;
  172. /* #ifdef APP-NVUE */
  173. border-width: 0.5px;
  174. /* #endif */
  175. /* #ifndef APP-NVUE */
  176. border-width: 1rpx;
  177. /* #endif */
  178. border-style: solid;
  179. flex-shrink: 0;
  180. /* #ifdef H5 */
  181. cursor: pointer;
  182. /* #endif */
  183. }
  184. .tui-pagination__hover:active {
  185. opacity: 0.5;
  186. }
  187. .tui-pagination__num {
  188. /* #ifndef APP-NVUE */
  189. display: flex;
  190. /* #endif */
  191. flex: 1;
  192. flex-direction: row;
  193. justify-content: center;
  194. align-items: center;
  195. }
  196. .tui-pagination__disabled {
  197. opacity: 0.3;
  198. /* #ifdef H5 */
  199. cursor: not-allowed;
  200. /* #endif */
  201. }
  202. </style>