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