wx-starlock/pages/user/verifyEmail.vue

173 lines
4.1 KiB
Vue
Raw Normal View History

<template>
<view>
<view class="tips">为了你的账号安全修改账号前请先使用验证码验证</view>
<view class="view-top">
2025-02-06 11:37:41 +08:00
<input
type="number"
class="input"
:value="verificationCode"
maxlength="6"
placeholder="请输入验证码"
placeholder-class="input-placeholder"
@input="updateInput"
/>
<view class="button-verify" @click="getEmailCode">{{ text }}</view>
</view>
<view class="button" @click="toUpdateEmail">下一步</view>
</view>
</template>
<script>
2025-02-06 11:37:41 +08:00
import { mapActions, mapState } from 'pinia'
import { test } from 'uview-plus'
import { useUserStore } from '@/stores/user'
import { getEmailCodeRequest, unbindEmailTokenRequest } from '@/api/user'
import { useBasicStore } from '@/stores/basic'
2025-02-06 11:37:41 +08:00
export default {
data() {
return {
text: '获取验证码',
verificationCode: ''
}
},
2025-02-06 11:37:41 +08:00
computed: {
...mapState(useUserStore, ['userInfo'])
},
methods: {
...mapActions(useUserStore, ['updateUserInfo']),
...mapActions(useBasicStore, ['routeJump', 'getNetworkType']),
async getEmailCode() {
if (this.text !== '获取验证码') {
return
}
2024-09-07 13:56:25 +08:00
const netWork = await this.getNetworkType()
2025-02-06 11:37:41 +08:00
if (!netWork) {
2024-09-07 13:56:25 +08:00
return
}
2025-02-06 11:37:41 +08:00
const { code } = await getEmailCodeRequest({
channel: '2',
codeType: 7
})
2025-02-06 11:37:41 +08:00
if (code === 0) {
this.updateTime()
} else {
uni.showToast({
title: '验证码获取失败',
icon: 'none'
})
}
},
async toUpdateEmail() {
if (this.verificationCode.length === 6 && test.digits(this.verificationCode)) {
const netWork = await this.getNetworkType()
if (!netWork) {
return
}
const { code, data, message } = await unbindEmailTokenRequest({
verificationCode: this.verificationCode
})
2025-02-06 11:37:41 +08:00
if (code === 0) {
this.routeJump({
type: 'redirectTo',
name: 'updateEmail',
params: {
token: data.token
}
})
} else {
uni.showToast({
title: message,
icon: 'none'
})
}
} else {
uni.showToast({
2025-02-06 11:37:41 +08:00
title: '验证码为6位纯数字',
icon: 'none'
})
}
2025-02-06 11:37:41 +08:00
},
updateTime() {
let time = 120
this.text = `${time} s`
const now = new Date().getTime()
const timer = setInterval(() => {
const second = parseInt((new Date().getTime() - now) / 1000, 10)
this.text = `${time - second} s`
if (time <= second) {
clearInterval(timer)
this.text = '获取验证码'
}
}, 1000)
},
updateInput(data) {
this.verificationCode = data.detail.value
}
}
}
</script>
<style lang="scss">
2025-02-06 11:37:41 +08:00
page {
background-color: $uni-bg-color-grey;
}
</style>
<style scoped lang="scss">
2025-02-06 11:37:41 +08:00
.tips {
padding: 24rpx 32rpx 0 32rpx;
font-size: 28rpx;
color: #999999;
}
2025-02-06 11:37:41 +08:00
.button-verify {
width: 265rpx;
height: 108rpx;
margin-top: 48rpx;
margin-left: 35rpx;
font-size: 32rpx;
2025-02-06 11:37:41 +08:00
line-height: 108rpx;
color: #ffffff;
2025-02-06 11:37:41 +08:00
text-align: center;
background: #63b8af;
border-radius: 16rpx;
2025-02-06 11:37:41 +08:00
}
2025-02-06 11:37:41 +08:00
.view-top {
display: flex;
align-items: center;
}
2025-02-06 11:37:41 +08:00
.input {
width: 316rpx;
height: 108rpx;
2025-02-06 11:37:41 +08:00
padding-right: 32rpx;
padding-left: 32rpx;
margin-top: 48rpx;
margin-left: 35rpx;
background: #ffffff;
border-radius: 16rpx;
2025-02-06 11:37:41 +08:00
}
2025-02-06 11:37:41 +08:00
.input-placeholder {
height: 108rpx;
font-size: 36rpx;
font-weight: bold;
line-height: 108rpx;
}
2025-02-06 11:37:41 +08:00
.button {
width: 680rpx;
height: 96rpx;
margin-top: 32rpx;
margin-left: 35rpx;
2025-02-06 11:37:41 +08:00
font-size: 32rpx;
line-height: 96rpx;
2025-02-06 11:37:41 +08:00
color: #ffffff;
text-align: center;
background: #63b8af;
border-radius: 16rpx;
2025-02-06 11:37:41 +08:00
}
</style>