wx-starlock/pages/verifyEmail/verifyEmail.vue
范鹏 2a55f76d6a 1. 添加说明性文案
2. 修复开关门bug
2024-08-30 10:48:30 +08:00

159 lines
3.5 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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