-
zhangwei
2025-03-06 8c047f7da19d7e59136a322e1a851d4b6b0eab97
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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
<template>
    <!--本文件由FirstUI授权予四川政采招投标咨询有限公司(会员ID: 1 63,营业执照号:9  1510 1  3 1  332 00    61 9  3 K)专用,请尊重知识产权,勿私下传播,违者追究法律责任。-->
    <view class="fui-countdown__verify" :class="{'fui-cdv__disabled':status>1}"
        :style="{ width: width+'rpx', height: height+'rpx', marginLeft: marginLeft+'rpx',marginRight:marginRight+'rpx', borderRadius: radius+'rpx',  background: background,borderColor:!getBorderColor || getBorderColor===true?background:getBorderColor }">
        <text :style="{fontSize: size + 'rpx',lineHeight:size + 'rpx', color: getColor}"
            class="fui-countdown__verify-text" :class="{'fui-cdv__color':!getColor}">{{ showText }}</text>
        <view class="fui-countdown__verify-main fui-countdown__verify-active" :style="{borderRadius: radius+'rpx'}"
            @tap.stop="sendCode" v-if="status===1"></view>
        <!-- #ifndef APP-NVUE -->
        <view class="fui-countdown__verify-line" :class="{'fui-cdv__border-color':!getBorderColor}"
            :style="{borderColor: getBorderColor, borderRadius: (radius * 2)+'rpx'}">
        </view>
        <!-- #endif -->
    </view>
</template>
 
<script>
    export default {
        name: 'fui-countdown-verify',
        emits: ['send', 'countdown', 'end'],
        props: {
            //发送前显示文本
            text: {
                type: String,
                default: '发送验证码'
            },
            //发送中显示文本
            sending: {
                type: String,
                default: '正在发送...'
            },
            //发送后倒计时显示文本(前面会自动拼接时间)
            sent: {
                type: String,
                default: 's后重新获取'
            },
            //倒计时秒数
            seconds: {
                type: [Number, String],
                default: 60
            },
            //宽度
            width: {
                type: [Number, String],
                default: 192
            },
            //高度
            height: {
                type: [Number, String],
                default: 60
            },
            marginLeft: {
                type: [Number, String],
                default: 0
            },
            marginRight: {
                type: [Number, String],
                default: 0
            },
            //圆角
            radius: {
                type: [Number, String],
                default: 8
            },
            //字体大小 rpx
            size: {
                type: [Number, String],
                default: 24
            },
            //字体颜色
            color: {
                type: String,
                default: ''
            },
            //背景色
            background: {
                type: String,
                default: 'transparent'
            },
            //边框颜色
            borderColor: {
                type: String,
                default: ''
            },
            //自定义参数
            param: {
                type: [Number, String],
                default: 0
            }
        },
        computed: {
            getColor() {
                let color = this.color;
                // #ifdef APP-NVUE
                if (!color || color === true) {
                    const app = uni && uni.$fui && uni.$fui.color;
                    color = (app && app.primary) || '#465CFF';
                }
                // #endif
                return color
            },
            getBorderColor() {
                let color = this.borderColor;
                // #ifdef APP-NVUE
                if (!color || color === true) {
                    const app = uni && uni.$fui && uni.$fui.color;
                    color = (app && app.primary) || '#465CFF';
                }
                // #endif
                return color
            }
        },
        data() {
            return {
                showText: '',
                //1-发送前,2-发送中 3-发送成功,倒计时
                status: 1,
                timer: null
            };
        },
        created() {
            if (this.start) {
                this.doLoop();
            } else {
                this.showText = this.text;
                this.clearTimer();
            }
        },
        // #ifndef VUE3
        beforeDestroy() {
            this.clearTimer();
        },
        // #endif
        // #ifdef VUE3
        beforeUnmount() {
            this.clearTimer();
        },
        // #endif
        methods: {
            sendCode(e) {
                // #ifdef APP-NVUE
                e.stopPropagation();
                // #endif
                if (this.status > 1) return;
                this.clearTimer();
                this.status = 2;
                this.showText = this.sending;
                this.$emit('send', {
                    param: this.param
                });
            },
            doLoop() {
                this.clearTimer();
                this.status = 3;
                let seconds = Number(this.seconds || 60);
                this.showText = seconds + this.sent;
                this.timer = setInterval(() => {
                    if (seconds > 1) {
                        --seconds;
                        this.showText = seconds + this.sent;
                        this.$emit('countdown', {
                            seconds: seconds,
                            param: this.param
                        });
                    } else {
                        this.reset();
                        this.$emit('end', {
                            param: this.param
                        });
                    }
                }, 1000);
            },
            success() {
                this.doLoop();
            },
            reset() {
                this.clearTimer();
                this.showText = this.text;
                this.status = 1;
            },
            clearTimer() {
                clearInterval(this.timer);
                this.timer = null;
            }
        }
    };
</script>
 
<style scoped>
    .fui-countdown__verify {
        position: relative;
        /* #ifndef APP-NVUE */
        display: flex;
        box-sizing: border-box;
        white-space: nowrap;
        /* #endif */
        align-items: center;
        justify-content: center;
        overflow: hidden;
        /* #ifdef APP-NVUE */
        border-width: 0.5px;
        border-style: solid;
        /* #endif */
 
        /* #ifndef APP-NVUE */
        border-width: 0;
        /* #endif */
    }
 
    .fui-countdown__verify-main {
        position: absolute;
        left: 0;
        top: 0;
        right: 0;
        bottom: 0;
        background-color: transparent;
        /* #ifndef APP-NVUE */
        z-index: 3;
        /* #endif */
 
        /* #ifdef H5 */
        cursor: pointer;
        /* #endif */
    }
 
    .fui-countdown__verify-active:active {
        background-color: rgba(0, 0, 0, .2);
    }
 
    .fui-cdv__disabled {
        opacity: .5;
    }
 
    .fui-countdown__verify-text {
        font-weight: normal;
        text-align: center;
    }
 
    /* #ifndef APP-NVUE */
    .fui-countdown__verify-line {
        position: absolute;
        width: 200%;
        height: 200%;
        transform-origin: 0 0;
        transform: scale(0.5, 0.5) translateZ(0);
        box-sizing: border-box;
        border-style: solid;
        border-width: 1px;
        left: 0;
        top: 0;
        pointer-events: none;
        z-index: 2;
    }
 
    .fui-cdv__color {
        color: var(--fui-color-primary, #465CFF) !important;
    }
 
    .fui-cdv__border-color {
        border-color: var(--fui-color-primary, #465CFF) !important;
    }
 
    /* #endif */
</style>