zhangwei
2024-09-09 87bad1af0c203865d318befd9bf3af199896931e
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
<template>
    <!--本文件由FirstUI授权予四川政采招投标咨询有限公司(会员ID:1 6 3,营业执照号:     915 1  01  3 13  32  00 6193 K)专用,请尊重知识产权,勿私下传播,违者追究法律责任。-->
    <view class="fui-loadmore__wrap" :class="['fui-loadmore__'+direction]" :style="{height:height+'rpx'}">
        <view class="fui-loadmore__icon" ref="fui_loadmore"
            :class="{'fui-loadmore__border-left':!isNvue && !activeColor}"
            :style="{width:iconWidth+'rpx',height:iconWidth+'rpx','border-left-color':getActiveColor,'border-right-color':iconColor,'border-top-color':iconColor,'border-bottom-color':iconColor}"
            v-if="!src && state==2">
        </view>
        <image class="fui-loadmore__icon-ani" ref="fui_loadmore" :src="src"
            :style="{width:iconWidth+'rpx',height:iconWidth+'rpx'}" v-if="src && state==2"></image>
        <text :class="{'fui-loadmore__text':direction==='col'}"
            :style="{color:color,'font-size':size+'rpx','line-height':size+'rpx'}">{{getStateText(state)}}</text>
    </view>
</template>
 
<script>
    // #ifdef APP-NVUE
    const animation = uni.requireNativePlugin('animation');
    // #endif
    export default {
        name: "fui-loadmore",
        props: {
            //占据高度,单位rx
            height: {
                type: [Number, String],
                default: 100
            },
            //1-上拉加载 2-正在加载... 3-没有更多了
            state: {
                type: [Number, String],
                default: 2
            },
            initText: {
                type: String,
                default: "上拉加载"
            },
            //提示文字
            text: {
                type: String,
                default: "正在加载..."
            },
            noneText: {
                type: String,
                default: "没有更多了"
            },
            //文字颜色
            color: {
                type: String,
                default: "#7F7F7F"
            },
            //文字大小,单位rpx
            size: {
                type: [Number, String],
                default: 24
            },
            //loading图标背景色
            iconColor: {
                type: String,
                default: "#B2B2B2"
            },
            //loading图标高亮部分颜色
            activeColor: {
                type: String,
                default: ""
            },
            //loading 图标的宽度,单位rpx
            iconWidth: {
                type: [Number, String],
                // #ifdef APP-NVUE
                default: 32
                // #endif
                // #ifndef APP-NVUE
                default: 28
                // #endif
            },
            //自定义loading图标image路径,若自定义图标则iconColor、activeColor属性失效
            src: {
                type: String,
                default: ''
            },
            //loading图标和文字排列方向,可取值:col,row
            direction: {
                type: String,
                default: 'row'
            }
        },
        watch: {
            state(newValue, oldValue) {
                this.$nextTick(() => {
                    // #ifdef APP-NVUE
                    if (newValue == 2) {
                        this.stop = false;
                        setTimeout(() => {
                            this._animation()
                        }, 50)
                    } else {
                        this.stop = true
                    }
                    // #endif
                })
            }
        },
        computed: {
            getActiveColor() {
                let color = this.activeColor;
                // #ifdef APP-NVUE
                if (!color || color === true) {
                    const app = uni && uni.$fui && uni.$fui.color;
                    color = (app && app.primary) || '#465CFF';
                }
                // #endif
                return color;
            }
        },
        data() {
            let isNvue = false;
            // #ifdef APP-NVUE
            isNvue = true;
            // #endif
            return {
                isNvue: isNvue,
                deg: 0,
                stop: false
            }
        },
        // #ifdef APP-NVUE
        mounted() {
            this.$nextTick(() => {
                setTimeout(() => {
                    this.deg += 360;
                    this._animation()
                }, 50)
            })
        },
        // #endif
        // #ifndef VUE3
        beforeDestroy() {
            this.deg = 0;
            this.stop = true;
        },
        // #endif
        // #ifdef VUE3
        beforeUnmount() {
            this.deg = 0;
            this.stop = true;
        },
        // #endif
        methods: {
            getStateText(state) {
                state = Number(state)
                return [this.initText, this.text, this.noneText][state - 1]
            },
            // #ifdef APP-NVUE
            _animation() {
                if (!this.$refs['fui_loadmore'] || this.stop) return;
                animation.transition(
                    this.$refs['fui_loadmore'].ref, {
                        styles: {
                            transform: `rotate(${this.deg}deg)`
                        },
                        duration: 700, //ms
                        timingFunction: 'linear',
                        iterationCount: 'infinite',
                        needLayout: false,
                        delay: 0 //ms
                    }, () => {
                        this.deg += 360;
                        this._animation()
                    }
                );
            }
            // #endif
        }
    }
</script>
 
<style scoped>
    .fui-loadmore__wrap {
        /* #ifndef APP-NVUE */
        width: 100%;
        display: flex;
        /* #endif */
        align-items: center;
        justify-content: center;
    }
 
    .fui-loadmore__col {
        flex-direction: column;
    }
 
    .fui-loadmore__row {
        flex-direction: row;
    }
 
    .fui-loadmore__icon {
        margin: 0 6px;
        border-width: 2px;
        border-style: solid;
        /* #ifdef APP-NVUE */
        border-radius: 100px;
        /* #endif */
 
        /* #ifndef APP-NVUE */
        border-radius: 50%;
        animation: fui-rotate 0.7s linear infinite;
        /* #endif */
    }
 
    .fui-loadmore__icon-ani {
        margin: 0 6px;
        /* #ifndef APP-NVUE */
        display: block;
        animation: fui-rotate 0.7s linear infinite;
        /* #endif */
    }
 
    .fui-loadmore__text {
        padding-top: 16rpx;
    }
 
    /* #ifndef APP-NVUE */
    .fui-loadmore__border-left {
        border-left-color: var(--fui-color-primary, #465CFF) !important;
    }
 
    @-webkit-keyframes fui-rotate {
        0% {
            transform: rotate(0);
        }
 
        100% {
            transform: rotate(360deg);
        }
    }
 
    @keyframes fui-rotate {
        0% {
            transform: rotate(0);
        }
 
        100% {
            transform: rotate(360deg);
        }
    }
 
    /* #endif */
</style>