u-loadmore.vue 5.7 KB

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