tn-load-more.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. <template>
  2. <view class="tn-load-more-class tn-load-more">
  3. <view
  4. class="tn-load-more__wrap"
  5. :class="[backgroundColorClass]"
  6. :style="[loadStyle]"
  7. >
  8. <view class="tn-load-more__line"></view>
  9. <view
  10. class="tn-load-more__content"
  11. :class="[{'tn-load-more__content--more': (status === 'loadmore' || status === 'nomore')}]"
  12. >
  13. <view class="tn-load-more__loading">
  14. <tn-loading
  15. class="tn-load-more__loading__icon"
  16. :mode="loadingIconType"
  17. :show="status === 'loading' && loadingIcon"
  18. :color="loadingIconColor"
  19. ></tn-loading>
  20. </view>
  21. <view
  22. class="tn-load-more__text"
  23. :class="[fontColorClass, {'tn-load-more__text--dot': (status === 'nomore' && dot)}]"
  24. :style="[loadTextStyle]"
  25. >{{ showText }}</view>
  26. </view>
  27. <view class="tn-load-more__line"></view>
  28. </view>
  29. </view>
  30. </template>
  31. <script>
  32. import componentsColorMixin from '../../libs/mixin/components_color.js'
  33. export default {
  34. name: 'tn-load-more',
  35. mixins: [componentsColorMixin],
  36. props: {
  37. // 加载状态
  38. // loadmore -> 加载更多
  39. // loading -> 加载中
  40. // nomore -> 没有更多
  41. status: {
  42. type: String,
  43. default: 'loadmore'
  44. },
  45. // 显示加载图标
  46. loadingIcon: {
  47. type: Boolean,
  48. default: true
  49. },
  50. // 加载图标样式,参考tn-loading组件的加载类型
  51. loadingIconType: {
  52. type: String,
  53. default: 'circle'
  54. },
  55. // 在圆圈加载状态下,圆圈的颜色
  56. loadingIconColor: {
  57. type: String,
  58. default: ''
  59. },
  60. // 显示的文字
  61. loadText: {
  62. type: Object,
  63. default() {
  64. return {
  65. loadmore: '加载更多',
  66. loading: '正在加载...',
  67. nomore: '没有更多了'
  68. }
  69. }
  70. },
  71. // 是否显示粗点,在nomore状态下生效
  72. dot: {
  73. type: Boolean,
  74. default: false
  75. },
  76. // 自定义组件样式
  77. customStyle: {
  78. type: Object,
  79. default() {
  80. return {}
  81. }
  82. }
  83. },
  84. computed: {
  85. loadStyle() {
  86. let style = {}
  87. if (this.backgroundColorStyle) {
  88. style.backgroundColor = this.backgroundColorStyle
  89. }
  90. // 合并用户自定义样式
  91. if (Object.keys(this.customStyle).length > 0) {
  92. Object.assign(style, this.customStyle)
  93. }
  94. return style
  95. },
  96. loadTextStyle() {
  97. let style = {}
  98. if (this.fontColorStyle) {
  99. style.color = this.fontColorStyle
  100. }
  101. if (this.fontSizeStyle) {
  102. style.fontSize = this.fontSizeStyle
  103. style.lineHeight = this.$t.string.getLengthUnitValue(this.fontSize + 2, this.fontUnit)
  104. }
  105. return style
  106. },
  107. // 显示的提示文字
  108. showText() {
  109. let text = ''
  110. if (this.status === 'loadmore') text = this.loadText.loadmore || '加载更多'
  111. else if (this.status === 'loading') text = this.loadText.loading || '正在加载...'
  112. else if (this.status === 'nomore' && this.dot) text = this.dotText
  113. else text = this.loadText.nomore || '没有更多了'
  114. return text
  115. }
  116. },
  117. data() {
  118. return {
  119. // 粗点
  120. dotText: '●'
  121. }
  122. },
  123. methods: {
  124. // 处理加载更多事件
  125. loadMore() {
  126. // 只有在 loadmore 状态下点击才会发送点击事件,内容不满一屏时无法触发底部上拉事件,所以需要点击来触发
  127. if (this.status === 'loadmore') this.$emit('loadmore')
  128. }
  129. }
  130. }
  131. </script>
  132. <style lang="scss" scoped>
  133. .tn-load-more {
  134. &__wrap {
  135. background-color: transparent;
  136. display: flex;
  137. flex-direction: row;
  138. justify-content: center;
  139. align-items: center;
  140. color: $tn-content-color;
  141. }
  142. &__line {
  143. vertical-align: middle;
  144. border: 1px solid $tn-content-color;
  145. width: 50rpx;
  146. transform: scaleY(0.5);
  147. }
  148. &__content {
  149. display: flex;
  150. flex-direction: row;
  151. justify-content: center;
  152. align-items: center;
  153. padding: 0 12rpx;
  154. &--more {
  155. position: relative;
  156. }
  157. }
  158. &__loading {
  159. margin-right: 8rpx;
  160. &__icon {
  161. display: flex;
  162. flex-direction: row;
  163. justify-content: center;
  164. align-items: center;
  165. }
  166. }
  167. &__text {
  168. overflow: hidden;
  169. white-space: nowrap;
  170. text-overflow: ellipsis;
  171. line-height: 30rpx;
  172. &--dot {
  173. font-size: 28rpx;
  174. }
  175. }
  176. }
  177. </style>