zzzz
2024-04-18 90dcbbc06eb2dce7d6fd6a7923f149f1f35c9361
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
<template>
    <div class="verify">
        <div class="header">
            <div @click="$router.go(-1)"><img src="../../assets/image/assets-center/left-arrow.png" alt=""
                    class="w-14 h-27" /></div>
<!--            <div class="textColor" @click="$router.push('/setFond')">{{ $t('跳过') }}</div>-->
        </div>
        <div class="content">
            <div class="title textColor" v-if="type==1">{{ $t('邮箱验证') }}</div>
            <div class="title textColor" v-if="type==2">{{ $t('手机验证') }}</div>
            <p v-if="type == 1">{{ $t('verifyEmailTips', { 'account': account }) }}</p>
            <p v-if="type == 2">{{ $t('verifyPhoneTips', { 'account': account }) }}</p>
            <div class="iptbox inputBackground">
                <input class="inputBackground textColor" type="text" :placeholder="$t('请输入验证码')" v-model="verifyCode">
                <span @click="senCode">{{ $t('重新发送验证码') }} <template v-if="time"> ({{ time }})s</template></span>
            </div>
            <div class="btn btnMain" @click="bound">{{ $t('绑定') }}</div>
        </div>
    </div>
</template>
 
<script>
import API from "@/API/login.js";
import Axios from "@/API/userCenter.js";
    export default {
        props: {
 
        },
        components: {
 
        },
        data(){
            return {
                verifyCode:'',
                type:'',
                account: '',
                timer:'',
                time:0
            }
        },
        mounted(){
            let type = this.$route.query.type;
            this.type = type;
            let account = this.$route.query.account;
            this.account = account;
            clearInterval(this.timer)
            this.senCode();
        },
        methods: {
            bound(){
                if (this.verifyCode.length<6){
                    this.$toast(this.$t('请输入6位验证码'));
                    return
                }
                switch(this.type){
                    case 1:
                        {
                            this.bindEmail()
                            break;
                        }
                    case 2:
                        {
                            this.bindPhone()
                            break;
                        }
                }
               
            },
            bindEmail() {
                Axios.bindEmail({
                    email: this.account,
                    verifcode: this.verifyCode
                }).then((res) => {
                    this.$toast(this.$t('绑定成功'));
                    this.$router.push('/setFond')
                }).catch((error) => {
                    if(error.code === 'ECONNABORTED'){this.$toast(this.$t('网络超时!'));}
                    else if(error.msg !== undefined){this.$toast(this.$t(error.msg));}  
                });
            },
            bindPhone() {
                Axios.bindPhone({
                    phone: this.account,
                    verifcode: this.verifyCode
                }).then((res) => {
                    this.$toast(this.$t('绑定成功'));
                    this.$router.push('/setFond')
                }).catch((error) => {
                    if(error.code === 'ECONNABORTED'){this.$toast(this.$t('网络超时!'));}
                    else if(error.msg !== undefined){this.$toast(this.$t(error.msg));}   
                });
            },
            senCode(){
                if (this.time>0){
                    return false
                }
                API.sendVerifyCode({
                    target: this.account,
                }).then((res) => {
                    this.time =30;
                    this.timer = setInterval(() => {
                        if(this.time>0){
                            this.time = this.time - 1
                        }else{
                            this.time = 0;
                            clearInterval(this.timer)
                        }
                    }, 1000);
                }).catch((error) => {
                    if(error.code === 'ECONNABORTED'){this.$toast(this.$t('网络超时!'));}
                    else if(error.msg !== undefined){this.$toast(this.$t(error.msg));}    
                });
            }
        },
        beforeDestroy() {
            clearInterval(this.timer)
        },
    }
</script>
 
<style lang="scss" scoped>
 
.verify{
    font-size: 26px;
    padding: 0 32px;
    width: 100%;
    box-sizing: border-box;
}
.header{
    display: flex;
    justify-content: space-between;
    padding: 0 26px;
    font-size: 28px;
    height: 100px;
    line-height: 100px;
}
.title {
    font-weight: 700;
    font-size: 52px;
    margin-top: 54px;
    margin-bottom: 33px;
}
.content{
    p{
        color: #868D9A;
        font-size: 30px;
        margin-bottom: 50px;
    }
    .iptbox {
        height: 88px;
        margin-top: 16px;
        padding: 0 20px;
        display: flex;
        justify-content: space-between;
        align-items: center;
        border-radius: 6px;
        input {
            flex: 1;
            height: 100%;
            border: none;
        }
        span{
            color: #1D91FF;
        }
    }
}
.btn {
    color: #fff;
    height: 88px;
    line-height: 88px;
    text-align: center;
    font-size: 32px;
    margin-top: 40px;
    border-radius: 10px;
}
</style>