u-loadmore.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <template>
  2. <view class="u-loadmore" :style="[
  3. $u.addStyle(customStyle),
  4. {
  5. backgroundColor: bgColor,
  6. marginBottom: $u.addUnit(marginBottom),
  7. marginTop: $u.addUnit(marginTop),
  8. height: $u.addUnit(height),
  9. },
  10. ]">
  11. <u-line length="140rpx" :color="lineColor" :hairline="false" :dashed="dashed" v-if="line"></u-line>
  12. <!-- 加载中和没有更多的状态才显示两边的横线 -->
  13. <view :class="status == 'loadmore' || status == 'nomore' ? 'u-more' : ''" class="u-loadmore__content">
  14. <view class="u-loadmore__content__icon-wrap" v-if="status === 'loading' && icon">
  15. <u-loading-icon :color="iconColor" :size="iconSize" :mode="loadingIcon"></u-loading-icon>
  16. </view>
  17. <!-- 如果没有更多的状态下,显示内容为dot(粗点),加载特定样式 -->
  18. <text class="u-line-1" :style="[loadTextStyle]"
  19. :class="[(status == 'nomore' && isDot == true) ? 'u-loadmore__content__dot-text' : 'u-loadmore__content__text']"
  20. @tap="loadMore">{{ showText }}</text>
  21. </view>
  22. <u-line length="140rpx" :color="lineColor" :hairline="false" :dashed="dashed" v-if="line"></u-line>
  23. </view>
  24. </template>
  25. <script>
  26. import props from './props.js';
  27. /**
  28. * loadmore 加载更多
  29. * @description 此组件一般用于标识页面底部加载数据时的状态。
  30. * @tutorial https://www.uviewui.com/components/loadMore.html
  31. * @property {String} status 组件状态(默认 'loadmore' )
  32. * @property {String} bgColor 组件背景颜色,在页面是非白色时会用到(默认 'transparent' )
  33. * @property {Boolean} icon 加载中时是否显示图标(默认 true )
  34. * @property {String | Number} fontSize 字体大小(默认 14 )
  35. * @property {String | Number} iconSize 图标大小(默认 17 )
  36. * @property {String} color 字体颜色(默认 '#606266' )
  37. * @property {String} loadingIcon 加载图标(默认 'circle' )
  38. * @property {String} loadmoreText 加载前的提示语(默认 '加载更多' )
  39. * @property {String} loadingText 加载中提示语(默认 '正在加载...' )
  40. * @property {String} nomoreText 没有更多的提示语(默认 '没有更多了' )
  41. * @property {Boolean} isDot 到上一个相邻元素的距离 (默认 false )
  42. * @property {String} iconColor 加载中图标的颜色 (默认 '#b7b7b7' )
  43. * @property {String} lineColor 线条颜色(默认 #E6E8EB )
  44. * @property {String | Number} marginTop 上边距 (默认 10 )
  45. * @property {String | Number} marginBottom 下边距 (默认 10 )
  46. * @property {String | Number} height 高度,单位px (默认 'auto' )
  47. * @property {Boolean} line 是否显示左边分割线 (默认 false )
  48. * @property {Boolean} dashed // 是否虚线,true-虚线,false-实线 (默认 false )
  49. * @event {Function} loadmore status为loadmore时,点击组件会发出此事件
  50. * @example <u-loadmore :status="status" icon-type="iconType" load-text="loadText" />
  51. */
  52. export default {
  53. name: "u-loadmore",
  54. mixins: [uni.$u.mpMixin, uni.$u.mixin, props],
  55. data() {
  56. return {
  57. // 粗点
  58. dotText: "●"
  59. }
  60. },
  61. computed: {
  62. // 加载的文字显示的样式
  63. loadTextStyle() {
  64. return {
  65. color: this.color,
  66. fontSize: uni.$u.addUnit(this.fontSize),
  67. lineHeight: uni.$u.addUnit(this.fontSize),
  68. backgroundColor: this.bgColor,
  69. }
  70. },
  71. // 显示的提示文字
  72. showText() {
  73. let text = '';
  74. if (this.status == 'loadmore') text = this.loadmoreText
  75. else if (this.status == 'loading') text = this.loadingText
  76. else if (this.status == 'nomore' && this.isDot) text = this.dotText;
  77. else text = this.nomoreText;
  78. return text;
  79. }
  80. },
  81. methods: {
  82. loadMore() {
  83. // 只有在“加载更多”的状态下才发送点击事件,内容不满一屏时无法触发底部上拉事件,所以需要点击来触发
  84. if (this.status == 'loadmore') this.$emit('loadmore');
  85. }
  86. }
  87. }
  88. </script>
  89. <style lang="scss" scoped>
  90. @import "../../libs/css/components.scss";
  91. .u-loadmore {
  92. @include flex(row);
  93. align-items: center;
  94. justify-content: center;
  95. flex: 1;
  96. &__content {
  97. margin: 0 15px;
  98. @include flex(row);
  99. align-items: center;
  100. justify-content: center;
  101. &__icon-wrap {
  102. margin-right: 8px;
  103. }
  104. &__text {
  105. font-size: 14px;
  106. color: $u-content-color;
  107. }
  108. &__dot-text {
  109. font-size: 15px;
  110. color: $u-tips-color;
  111. }
  112. }
  113. }
  114. </style>