u-loadmore.vue 4.6 KB

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