You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

155 lines
4.7 KiB

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