裂变星小程序-25.03.04
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.

152 lines
4.8 KiB

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