u-loadmore.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. <template>
  2. <view class="u-load-more-wrap" :style="{
  3. backgroundColor: bgColor,
  4. marginBottom: marginBottom + 'rpx',
  5. marginTop: marginTop + 'rpx'
  6. }">
  7. <!-- 加载中和没有更多的状态才显示两边的横线 -->
  8. <view :class="status == 'loadmore' || status == 'nomore' ? 'u-more' : ''" class="u-load-more-inner">
  9. <u-loading class="u-loadmore-icon" :color="iconColor" :mode="iconType == 'circle' ? 'circle' : 'flower'" :show="status == 'loading' && icon"></u-loading>
  10. <!-- 如果没有更多的状态下,显示内容为dot(粗点),加载特定样式 -->
  11. <view :style="[loadTextStyle]" :class="[(status == 'nomore' && isDot == true) ? 'u-dot-text' : 'u-more-text']" @tap="loadMore">
  12. {{ showText }}
  13. </view>
  14. </view>
  15. </view>
  16. </template>
  17. <script>
  18. /**
  19. * loadmore 加载更多
  20. * @description 此组件一般用于标识页面底部加载数据时的状态。
  21. * @tutorial https://www.uviewui.com/components/loadMore.html
  22. * @property {String} status 组件状态(默认loadmore)
  23. * @property {String} bg-color 组件背景颜色,在页面是非白色时会用到(默认#ffffff)
  24. * @property {Boolean} icon 加载中时是否显示图标(默认true)
  25. * @property {String} icon-type 加载中时的图标类型(默认circle)
  26. * @property {String} icon-color icon-type为circle时有效,加载中的动画图标的颜色(默认#b7b7b7)
  27. * @property {Boolean} is-dot status为nomore时,内容显示为一个"●"(默认false)
  28. * @property {String} color 字体颜色(默认#606266)
  29. * @property {String Number} font-size 字体大小,单位rpx(默认28)
  30. * @property {Object} load-text 自定义显示的文字,见上方说明示例
  31. * @event {Function} loadmore status为loadmore时,点击组件会发出此事件
  32. * @example <u-loadmore :status="status" icon-type="iconType" load-text="loadText" />
  33. */
  34. export default {
  35. name: "u-loadmore",
  36. props: {
  37. //当前页面背景颜色,如果背景为非白色的时候,需要把此值设置为背景的颜色
  38. bgColor: {
  39. type: String,
  40. default: '#fff'
  41. },
  42. // 是否显示加载中的图标
  43. icon: {
  44. type: Boolean,
  45. default: true
  46. },
  47. // 字体大小
  48. fontSize: {
  49. type: String,
  50. default: '28'
  51. },
  52. // 字体颜色
  53. color: {
  54. type: String,
  55. default: '#606266'
  56. },
  57. // 组件状态,loadmore-加载前的状态,loading-加载中的状态,nomore-没有更多的状态
  58. status: {
  59. type: String,
  60. default: 'loadmore'
  61. },
  62. // 加载中状态的图标,flower-花朵状图标,circle-圆圈状图标
  63. iconType: {
  64. type: String,
  65. default: 'circle'
  66. },
  67. // 显示的文字
  68. loadText: {
  69. type: Object,
  70. default () {
  71. return {
  72. loadmore: '加载更多',
  73. loading: '正在加载...',
  74. nomore: '没有更多了'
  75. }
  76. }
  77. },
  78. // 在“没有更多”状态下,是否显示粗点
  79. isDot: {
  80. type: Boolean,
  81. default: false
  82. },
  83. // 加载中显示圆圈动画时,动画的颜色
  84. iconColor: {
  85. type: String,
  86. default: '#b7b7b7'
  87. },
  88. // 上边距
  89. marginTop: {
  90. type: [String, Number],
  91. default: 0
  92. },
  93. // 下边距
  94. marginBottom: {
  95. type: [String, Number],
  96. default: 0
  97. },
  98. },
  99. data() {
  100. return {
  101. // 粗点
  102. dotText: "●"
  103. }
  104. },
  105. computed: {
  106. // 加载的文字显示的样式
  107. loadTextStyle() {
  108. return {
  109. color: this.color,
  110. fontSize: this.fontSize + 'rpx',
  111. position: 'relative',
  112. zIndex: 1,
  113. backgroundColor: this.bgColor,
  114. // 如果是加载中状态,动画和文字需要距离近一点
  115. padding: this.status == 'loading' ? '0 8px' : '0 12px',
  116. }
  117. },
  118. // 加载中圆圈动画的样式
  119. cricleStyle() {
  120. return {
  121. borderColor: `#e5e5e5 #e5e5e5 #e5e5e5 ${this.circleColor}`
  122. }
  123. },
  124. // 加载中花朵动画形式
  125. // 动画由base64图片生成,暂不支持修改
  126. flowerStyle() {
  127. return {
  128. }
  129. },
  130. // 显示的提示文字
  131. showText() {
  132. let text = '';
  133. if(this.status == 'loadmore') text = this.loadText.loadmore;
  134. else if(this.status == 'loading') text = this.loadText.loading;
  135. else if(this.status == 'nomore' && this.isDot) text = this.dotText;
  136. else text = this.loadText.nomore;
  137. return text;
  138. }
  139. },
  140. methods: {
  141. loadMore() {
  142. // 只有在“加载更多”的状态下才发送点击事件,内容不满一屏时无法触发底部上拉事件,所以需要点击来触发
  143. if(this.status == 'loadmore') this.$emit('loadmore');
  144. }
  145. }
  146. }
  147. </script>
  148. <style scoped lang="scss">
  149. .u-load-more-wrap {
  150. width: 100%;
  151. display: flex;
  152. justify-content: center;
  153. }
  154. .u-load-more-inner {
  155. display: flex;
  156. justify-content: center;
  157. align-items: center;
  158. }
  159. .u-more {
  160. width: 60%;
  161. position: relative;
  162. display: flex;
  163. justify-content: center;
  164. }
  165. .u-more::before {
  166. content: ' ';
  167. position: absolute;
  168. border-bottom: 1px solid #d4d4d4;
  169. -webkit-transform: scaleY(0.5);
  170. transform: scaleY(0.5);
  171. width: 100%;
  172. top: 50%;
  173. left: 0;
  174. }
  175. .u-dot-text {
  176. font-size: 28rpx;
  177. }
  178. .u-loadmore-icon {
  179. display: flex;
  180. align-items: center;
  181. justify-content: center;
  182. }
  183. </style>