u-loadmore.vue 4.6 KB

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