11
jhzh
2024-08-01 4ebbadfe4c8c7aa6404dcd9b126cc8265bf03c0d
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
<template>
    <div class="changePassword">
        <assets-head :title="$t('修改资金密码')" />
        <div class="line"></div>
        <div class="content">
            <ExInput :label="$t('新密码')" :placeholderText="$t('请输入密码')" :tips="$t('请输入6位数字')" v-model="password"
                typeText="password" />
            <ExInput :label="$t('确认新密码')" :placeholderText="$t('请输入密码')" :tips="$t('请输入6位数字')" v-model="rePassword"
                typeText="password" />
            <ExChecked class="mb-42" :list="list" @checked="onChecked"></ExChecked>
            <p class="label mt-14 textColor">{{ $t('验证码') }}</p>
            <div class="iptbox inputBackground">
                <input class="inputBackground textColor" type="text" :placeholder="$t('请输入验证码')" v-model="verifyCode">
                <span v-if="type != 3" @click="senCode">{{ $t('发送验证码') }}<template v-if="time"> ({{ time
                }})s</template></span>
            </div>
            <div class="btn" @click="submit">{{ $t('确定') }}</div>
        </div>
    </div>
</template>
 
<script>
import assetsHead from "@/components/assets-head";
import ExInput from "@/components/ex-input";
import ExChecked from "@/components/ex-checked";
import Axios from "@/API/userCenter.js";
import ApiLogin from "@/API/login.js";
export default {
    props: {
 
    },
    components: {
        assetsHead,
        ExInput,
        ExChecked
    },
    data() {
        return {
            password: '', //密码
            rePassword: '',//确认密码
            verifcode_type: '',// 验证类型:1/手机;2/邮箱;3/谷歌验证器;
            verifyCode: '', //验证码
            type: 2, //默认选中邮箱
            list: [
                // {
                //     name: this.$t('手机验证'),
                //     type: 1
                // },
                {
                    name: this.$t('邮箱验证'),
                    type: 2
                },
                {
                    name: this.$t('谷歌验证'),
                    type: 3
                },
            ],
            email_authority: false, //是否绑定邮箱
            google_auth_bind: false,//是否绑定谷歌
            phone_authority: false,//是否绑定手机
            email: '',
            phone: '',
            google_auth_secret: '',
            account: '',
            timer: '',
            time: 0
        }
    },
    mounted() {
        this.getVerifTarget();
        clearInterval(this.timer)
    },
    methods: {
        onChecked(type) {
            this.type = type;
            if (this.type == 3 && !this.google_auth_bind) {
                this.$toast(this.$t('请绑定谷歌验证器'))
            }
            if (this.type == 1) {
                this.account = this.phone;
            } else if (this.type == 2) {
                this.account = this.email;
            } else if (this.type == 3) {
                this.account = this.google_auth_secret;
            }
        },
        submit() {
            if (this.password.length < 6) {
                this.$toast(this.$t('资金密码(6位数字)'))
                return false
            }
            Axios.setSafeword({
                safeword: this.password,
                verifcode_type: this.type,
                verifcode: this.verifyCode
            }).then((res) => {
                this.$toast(this.$t('修改成功'))
                setTimeout(() => {
                    this.$router.push('/home')
                }, 1000)
            }).catch((error) => {
                if (error.code === 'ECONNABORTED') { this.$toast(this.$t('网络超时!')); }
                else if (error.msg !== undefined) { this.$toast(this.$t(error.msg)); }
            });
        },
        async getVerifTarget() {
            Axios.getVerifTarget({
 
            }).then((res) => {
                this.email_authority = res.data.email_authority
                this.google_auth_bind = res.data.google_auth_bind
                this.phone_authority = res.data.phone_authority
                this.email = res.data.email
                this.phone = res.data.phone
                this.google_auth_secret = res.data.google_auth_secret
            }).catch((error) => {
                if (error.code === 'ECONNABORTED') { this.$toast(this.$t('网络超时!')); }
                else if (error.msg !== undefined) { this.$toast(this.$t(error.msg)); }
            });
 
        },
        senCode() {
            if (this.type == 1 && !this.phone_authority) {
                this.$toast(this.$t('请绑定手机'));
                return false
            }
            if (this.type == 2 && !this.email_authority) {
                this.$toast(this.$t('请绑定邮箱'));
                return false
            }
            this.onChecked(this.type)
            if (this.time > 0) {
                return false
            }
            ApiLogin.sendVerifyCode({
                target: this.account,
            }).then((res) => {
                this.$toast(this.$t('发送成功'));
                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>
.changePassword {
    width: 100%;
    box-sizing: border-box;
}
 
 
 
 
 
 
 
 
 
 
.line {
    width: 100%;
    height: 2px;
 
    @include themify() {
        background: themed("tab_background");
    }
}
 
.content {
    padding: 32px;
    font-size: 26px;
}
 
.btn {
    @include themify() {
        background: themed("btn_main");
    }
 
    color: #fff;
    height: 88px;
    line-height: 88px;
    text-align: center;
    font-size: 32px;
    margin-top: 44px;
    border-radius: 10px;
    width: 100%;
    border: none;
}
 
 
.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;
    }
}
</style>