2024-08-20 19:54:37 +08:00
|
|
|
|
<template>
|
|
|
|
|
|
<view>
|
2025-02-06 11:37:41 +08:00
|
|
|
|
<input
|
|
|
|
|
|
class="input"
|
|
|
|
|
|
:password="true"
|
|
|
|
|
|
:value="password"
|
|
|
|
|
|
maxlength="20"
|
|
|
|
|
|
placeholder="请输入新密码"
|
|
|
|
|
|
placeholder-class="input-placeholder"
|
|
|
|
|
|
@input="updateNewPassword"
|
|
|
|
|
|
/>
|
2024-08-27 10:12:56 +08:00
|
|
|
|
<view class="view-top">
|
2025-02-06 11:37:41 +08:00
|
|
|
|
<input
|
|
|
|
|
|
type="number"
|
|
|
|
|
|
class="input-verify"
|
|
|
|
|
|
:value="verificationCode"
|
|
|
|
|
|
maxlength="6"
|
|
|
|
|
|
placeholder="请输入验证码"
|
|
|
|
|
|
placeholder-class="input-placeholder"
|
|
|
|
|
|
@input="updateInputCode"
|
|
|
|
|
|
/>
|
|
|
|
|
|
<view class="button-verify" @click="getPhoneCode">{{ text }}</view>
|
2024-08-27 10:12:56 +08:00
|
|
|
|
</view>
|
2024-08-20 19:54:37 +08:00
|
|
|
|
<view class="text-tips">密码必须是8-20位,至少包括数字/字母/符号中的2种</view>
|
|
|
|
|
|
<view class="button" @click="updatePassword">保存</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 { changePasswordRequest, getEmailCodeRequest } from '@/api/user'
|
|
|
|
|
|
import { useBasicStore } from '@/stores/basic'
|
2024-08-20 19:54:37 +08:00
|
|
|
|
|
2025-02-06 11:37:41 +08:00
|
|
|
|
export default {
|
|
|
|
|
|
data() {
|
|
|
|
|
|
return {
|
|
|
|
|
|
text: '获取验证码',
|
|
|
|
|
|
password: '',
|
|
|
|
|
|
pending: false,
|
|
|
|
|
|
verificationCode: ''
|
2024-08-27 10:12:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
},
|
2025-02-06 11:37:41 +08:00
|
|
|
|
computed: {
|
|
|
|
|
|
...mapState(useUserStore, ['userInfo'])
|
2024-08-20 19:54:37 +08:00
|
|
|
|
},
|
2025-02-06 11:37:41 +08:00
|
|
|
|
methods: {
|
|
|
|
|
|
...mapActions(useUserStore, ['updateUserInfo']),
|
|
|
|
|
|
...mapActions(useBasicStore, ['backAndToast', 'getNetworkType']),
|
|
|
|
|
|
updateNewPassword(data) {
|
|
|
|
|
|
this.password = data.detail.value
|
|
|
|
|
|
},
|
|
|
|
|
|
updateInputCode(data) {
|
|
|
|
|
|
this.verificationCode = data.detail.value
|
|
|
|
|
|
},
|
|
|
|
|
|
async getPhoneCode() {
|
|
|
|
|
|
if (this.text !== '获取验证码') {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
const netWork = await this.getNetworkType()
|
|
|
|
|
|
if (!netWork) {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
const { code, message } = await getEmailCodeRequest({
|
|
|
|
|
|
channel: '1',
|
|
|
|
|
|
codeType: 9
|
2024-08-20 19:54:37 +08:00
|
|
|
|
})
|
2025-02-06 11:37:41 +08:00
|
|
|
|
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, 10)
|
|
|
|
|
|
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
|
|
|
|
|
|
}
|
|
|
|
|
|
const netWork = await this.getNetworkType()
|
|
|
|
|
|
if (!netWork) {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
if (this.pending) {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
this.pending = true
|
|
|
|
|
|
const { code, message } = await changePasswordRequest({
|
|
|
|
|
|
verificationCode: this.verificationCode,
|
|
|
|
|
|
password: this.password,
|
|
|
|
|
|
channel: '1'
|
2024-08-20 19:54:37 +08:00
|
|
|
|
})
|
2025-02-06 11:37:41 +08:00
|
|
|
|
if (code === 0) {
|
|
|
|
|
|
this.backAndToast('密码重置成功')
|
|
|
|
|
|
} else {
|
|
|
|
|
|
uni.showToast({
|
|
|
|
|
|
title: message,
|
|
|
|
|
|
icon: 'none'
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
this.pending = false
|
2024-08-20 19:54:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<style lang="scss">
|
2025-02-06 11:37:41 +08:00
|
|
|
|
page {
|
|
|
|
|
|
background-color: $uni-bg-color-grey;
|
|
|
|
|
|
}
|
2024-08-20 19:54:37 +08:00
|
|
|
|
</style>
|
|
|
|
|
|
|
|
|
|
|
|
<style scoped lang="scss">
|
2025-02-06 11:37:41 +08:00
|
|
|
|
.input {
|
|
|
|
|
|
width: 616rpx;
|
2025-06-09 14:37:37 +08:00
|
|
|
|
height: 108rpx;
|
2025-02-06 11:37:41 +08:00
|
|
|
|
padding-right: 32rpx;
|
2025-06-09 14:37:37 +08:00
|
|
|
|
padding-left: 32rpx;
|
|
|
|
|
|
margin-top: 48rpx;
|
|
|
|
|
|
margin-left: 35rpx;
|
|
|
|
|
|
background: #ffffff;
|
|
|
|
|
|
border-radius: 16rpx;
|
2025-02-06 11:37:41 +08:00
|
|
|
|
}
|
2024-08-20 19:54:37 +08:00
|
|
|
|
|
2025-02-06 11:37:41 +08:00
|
|
|
|
.input-placeholder {
|
|
|
|
|
|
height: 108rpx;
|
|
|
|
|
|
font-size: 36rpx;
|
|
|
|
|
|
font-weight: bold;
|
|
|
|
|
|
line-height: 108rpx;
|
|
|
|
|
|
}
|
2024-08-20 19:54:37 +08:00
|
|
|
|
|
2025-02-06 11:37:41 +08:00
|
|
|
|
.button {
|
|
|
|
|
|
width: 680rpx;
|
|
|
|
|
|
height: 96rpx;
|
2025-06-09 14:37:37 +08:00
|
|
|
|
margin-top: 32rpx;
|
|
|
|
|
|
margin-left: 35rpx;
|
2025-02-06 11:37:41 +08:00
|
|
|
|
font-size: 32rpx;
|
2025-06-09 14:37:37 +08:00
|
|
|
|
line-height: 96rpx;
|
2025-02-06 11:37:41 +08:00
|
|
|
|
color: #ffffff;
|
2025-06-09 14:37:37 +08:00
|
|
|
|
text-align: center;
|
2025-07-29 11:07:43 +08:00
|
|
|
|
background: #4777ee;
|
2025-06-09 14:37:37 +08:00
|
|
|
|
border-radius: 16rpx;
|
2025-02-06 11:37:41 +08:00
|
|
|
|
}
|
2024-08-20 19:54:37 +08:00
|
|
|
|
|
2025-02-06 11:37:41 +08:00
|
|
|
|
.text-tips {
|
|
|
|
|
|
margin-top: 32rpx;
|
|
|
|
|
|
font-size: 28rpx;
|
|
|
|
|
|
color: #9b9b9b;
|
2025-06-09 14:37:37 +08:00
|
|
|
|
text-align: center;
|
2025-02-06 11:37:41 +08:00
|
|
|
|
}
|
2024-08-27 10:12:56 +08:00
|
|
|
|
|
2025-02-06 11:37:41 +08:00
|
|
|
|
.view-top {
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
align-items: center;
|
|
|
|
|
|
}
|
2024-08-27 10:12:56 +08:00
|
|
|
|
|
2025-02-06 11:37:41 +08:00
|
|
|
|
.input-verify {
|
|
|
|
|
|
width: 316rpx;
|
2025-06-09 14:37:37 +08:00
|
|
|
|
height: 108rpx;
|
2025-02-06 11:37:41 +08:00
|
|
|
|
padding-right: 32rpx;
|
2025-06-09 14:37:37 +08:00
|
|
|
|
padding-left: 32rpx;
|
|
|
|
|
|
margin-top: 48rpx;
|
|
|
|
|
|
margin-left: 35rpx;
|
|
|
|
|
|
background: #ffffff;
|
|
|
|
|
|
border-radius: 16rpx;
|
2025-02-06 11:37:41 +08:00
|
|
|
|
}
|
2024-08-27 10:12:56 +08:00
|
|
|
|
|
2025-02-06 11:37:41 +08:00
|
|
|
|
.button-verify {
|
|
|
|
|
|
width: 265rpx;
|
2025-06-09 14:37:37 +08:00
|
|
|
|
height: 108rpx;
|
|
|
|
|
|
margin-top: 48rpx;
|
|
|
|
|
|
margin-left: 35rpx;
|
|
|
|
|
|
font-size: 32rpx;
|
2025-02-06 11:37:41 +08:00
|
|
|
|
line-height: 108rpx;
|
2025-06-09 14:37:37 +08:00
|
|
|
|
color: #ffffff;
|
2025-02-06 11:37:41 +08:00
|
|
|
|
text-align: center;
|
2025-07-29 11:07:43 +08:00
|
|
|
|
background: #4777ee;
|
2025-06-09 14:37:37 +08:00
|
|
|
|
border-radius: 16rpx;
|
2025-02-06 11:37:41 +08:00
|
|
|
|
}
|
2024-08-20 19:54:37 +08:00
|
|
|
|
</style>
|