智慧画屏客户端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

187 lines
3.9 KiB

3 years ago
  1. <template>
  2. <view class="uni-pagination">
  3. <view class="uni-pagination__btns">
  4. <view :class="['uni-pagination__btn',{'uni-pagination--disabled':currentIndex === 1}]" :hover-class="currentIndex === 1 ? '' : 'uni-pagination--hover'" :hover-start-time="20" :hover-stay-time="70" @click="clickLeft">
  5. <template v-if="showIcon===true || showIcon === 'true'">
  6. <uni-icons color="#000" size="20" type="arrowleft" />
  7. </template>
  8. <template v-else>
  9. {{ prevText }}
  10. </template>
  11. </view>
  12. <view :class="['uni-pagination__btn',{'uni-pagination--disabled':currentIndex === maxPage}]" :hover-class="currentIndex === maxPage ? '' : 'uni-pagination--hover'" :hover-start-time="20" :hover-stay-time="70" @click="clickRight">
  13. <template v-if="showIcon===true || showIcon === 'true'">
  14. <uni-icons color="#000" size="20" type="arrowright" />
  15. </template>
  16. <template v-else>
  17. {{ nextText }}
  18. </template>
  19. </view>
  20. </view>
  21. <view class="uni-pagination__num" v-if="total>0">
  22. <text class="uni-pagination__num-current">{{ currentIndex }}</text>/{{ maxPage }}
  23. <text class="zongye" >(:{{ total }})</text>
  24. </view>
  25. </view>
  26. </template>
  27. <script>
  28. import uniIcons from '../uni-icons/uni-icons.vue'
  29. export default {
  30. name: 'UniPagination',
  31. components: {
  32. uniIcons
  33. },
  34. props: {
  35. prevText: {
  36. type: String,
  37. default: '上一页'
  38. },
  39. nextText: {
  40. type: String,
  41. default: '下一页'
  42. },
  43. current: {
  44. type: [Number, String],
  45. default: 1
  46. },
  47. total: { // 数据总量
  48. type: [Number, String],
  49. default: 0
  50. },
  51. pageSize: { // 每页数据量
  52. type: [Number, String],
  53. default: 10
  54. },
  55. showIcon: { // 是否以 icon 形式展示按钮
  56. type: [Boolean, String],
  57. default: false
  58. }
  59. },
  60. data() {
  61. return {
  62. currentIndex: 1
  63. }
  64. },
  65. computed: {
  66. maxPage() {
  67. let maxPage = 1
  68. let total = Number(this.total)
  69. let pageSize = Number(this.pageSize)
  70. if (total && pageSize) {
  71. maxPage = Math.ceil(total / pageSize)
  72. }
  73. return maxPage
  74. }
  75. },
  76. watch: {
  77. current(val) {
  78. this.currentIndex = +val
  79. }
  80. },
  81. created() {
  82. this.currentIndex = +this.current
  83. },
  84. methods: {
  85. clickLeft() {
  86. if (Number(this.currentIndex) === 1) {
  87. return
  88. }
  89. this.currentIndex -= 1
  90. this.change('prev')
  91. },
  92. clickRight() {
  93. if (Number(this.currentIndex) === this.maxPage) {
  94. return
  95. }
  96. this.currentIndex += 1
  97. this.change('next')
  98. },
  99. change(e) {
  100. this.$emit('change', {
  101. type: e,
  102. current: this.currentIndex
  103. })
  104. }
  105. }
  106. }
  107. </script>
  108. <style>
  109. @charset "UTF-8";
  110. .uni-pagination {
  111. width: 100%;
  112. box-sizing: border-box;
  113. padding: 0 40upx;
  114. position: relative;
  115. overflow: hidden;
  116. display: flex;
  117. flex-direction: row
  118. }
  119. .uni-pagination__btns {
  120. flex: 1;
  121. display: flex;
  122. justify-content: space-between;
  123. align-items: center;
  124. flex-direction: row
  125. }
  126. .uni-pagination__btn {
  127. width: 120upx;
  128. height: 60upx;
  129. padding: 0 16upx;
  130. line-height: 60upx;
  131. font-size: 28upx;
  132. box-sizing: border-box;
  133. position: relative;
  134. /* background-color: #f8f8f8; */
  135. display: flex;
  136. flex-direction: row;
  137. justify-content: center;
  138. align-items: center
  139. }
  140. .uni-pagination__btn:after {
  141. content: "";
  142. width: 200%;
  143. height: 200%;
  144. position: absolute;
  145. top: 0;
  146. left: 0;
  147. /* border: 1px solid #e5e5e5; */
  148. transform: scale(.5);
  149. transform-origin: 0 0;
  150. box-sizing: border-box;
  151. border-radius: 12upx
  152. }
  153. .uni-pagination__num {
  154. width: 150upx;
  155. /* width: 100upx; */
  156. height: 60upx;
  157. line-height: 60upx;
  158. font-size: 28upx;
  159. color: rgb(171,178,191);
  160. position: absolute;
  161. left: 50%;
  162. top: 0;
  163. transform: translateX(-50%)
  164. }
  165. .uni-pagination__num-current {
  166. color: rgb(0,163,201)
  167. }
  168. .uni-pagination--disabled {
  169. opacity: .3
  170. }
  171. .uni-pagination--hover {
  172. color: rgba(0, 0, 0, .6);
  173. /* background-color: #f1f1f1 */
  174. }
  175. .zongye{
  176. margin-left: 30upx;
  177. }
  178. </style>