wx-starlock/pages/updatePassword/updatePassword.vue
范鹏 2fc7ad7ed7 1. 完成手机验证码修改账号密码功能
2. 完成更换账号绑定手机号功能
2024-08-27 10:12:56 +08:00

202 lines
4.6 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>
<input class="input" :password="true" :value="password" maxlength="20" placeholder="请输入新密码"
placeholder-class="input-placeholder" @input="updateNewPassword"></input>
<view class="view-top">
<input type="number" class="input-verify" :value="verificationCode" maxlength="6" placeholder="请输入验证码"
placeholder-class="input-placeholder" @input="updateInputCode"></input>
<view class="button-verify" @click="getPhoneCode">{{text}}</view>
</view>
<view class="text-tips">密码必须是8-20至少包括数字/字母/符号中的2种</view>
<view class="button" @click="updatePassword">保存</view>
</view>
</template>
<script>
import { mapActions, mapState } from 'pinia'
import { useUserStore } from '@/stores/user'
import { changePasswordRequest, getEmailCodeRequest, updatePasswordRequest } from '@/api/user'
import { test } from 'uview-plus'
export default {
data () {
return {
text: '获取验证码',
password: '',
pending: false,
verificationCode: ''
}
},
computed: {
...mapState(useUserStore, ['userInfo'])
},
methods: {
...mapActions(useUserStore, ['updateUserInfo']),
updateNewPassword (data) {
this.password = data.detail.value
},
updateInputCode (data) {
this.verificationCode = data.detail.value
},
async getPhoneCode () {
if (this.text !== '获取验证码') {
return
}
const { code, message } = await getEmailCodeRequest({
channel: '1',
codeType: 9
})
if (code === 0) {
this.updateTime()
} else {
uni.showToast({
title: message,
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)
},
async updatePassword () {
if (this.password === '') {
uni.showToast({
title: '密码不能为空',
icon: 'none'
})
return
}
if (this.password.length < 8 || this.password.length > 20) {
uni.showToast({
title: '密码长度必须是8-20位',
icon: 'none'
})
return
}
if (!(this.verificationCode.length === 6 && test.digits(this.verificationCode))) {
uni.showToast({
title: '验证码为6位纯数字',
icon: 'none'
})
return
}
if(this.pending) {
return
}
this.pending = true
const { code, message } = await changePasswordRequest({
verificationCode: this.verificationCode,
password: this.password,
channel: '1'
})
if (code === 0) {
this.updateUserInfo({
...this.userInfo,
nickname: this.nickname
})
uni.navigateBack({
complete () {
uni.showToast({
title: '密码重置成功',
icon: 'none'
})
}
})
} else {
uni.showToast({
title: message,
icon: 'none'
})
}
this.pending = false
}
}
}
</script>
<style lang="scss">
page {
background-color: $uni-bg-color-grey;
}
</style>
<style scoped lang="scss">
.input {
border-radius: 16rpx;
background: #FFFFFF;
margin-left: 35rpx;
margin-top: 48rpx;
height: 108rpx;
width: 616rpx;
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;
}
.text-tips {
text-align: center;
margin-top: 32rpx;
font-size: 28rpx;
color: #9B9B9B;
}
.view-top {
display: flex;
align-items: center;
}
.input-verify {
border-radius: 16rpx;
background: #FFFFFF;
margin-left: 35rpx;
margin-top: 48rpx;
height: 108rpx;
width: 316rpx;
padding-left: 32rpx;
padding-right: 32rpx;
}
.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;
}
</style>