u-loadmore.vue 4.5 KB

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