2024-08-20 19:54:37 +08:00
|
|
|
|
<template>
|
|
|
|
|
|
<view>
|
2025-07-15 11:24:54 +08:00
|
|
|
|
<view class="tips">
|
|
|
|
|
|
<!-- #ifdef MP-WEIXIN -->
|
|
|
|
|
|
{{
|
|
|
|
|
|
type === 'email'
|
|
|
|
|
|
? '在APP上找回密码和登录新设备时,可通过绑定的邮箱验证'
|
|
|
|
|
|
: '在APP上找回密码和登录新设备时,可通过绑定的手机号验证'
|
|
|
|
|
|
}}
|
|
|
|
|
|
<!-- #endif -->
|
|
|
|
|
|
<!-- #ifdef APP-PLUS -->
|
|
|
|
|
|
{{
|
|
|
|
|
|
type === 'email'
|
|
|
|
|
|
? '找回密码和登录新设备时,可通过绑定的邮箱验证'
|
|
|
|
|
|
: '找回密码和登录新设备时,可通过绑定的手机号验证'
|
|
|
|
|
|
}}
|
|
|
|
|
|
<!-- #endif -->
|
|
|
|
|
|
</view>
|
|
|
|
|
|
<view class="view-country" v-if="type === 'mobile'" @click="toJump('countryList')">
|
|
|
|
|
|
<view>国家/地区</view>
|
|
|
|
|
|
<view class="text-#63b8af">{{ country.name }} +{{ country.code }}</view>
|
|
|
|
|
|
</view>
|
2025-02-06 11:37:41 +08:00
|
|
|
|
<input
|
2025-07-15 11:24:54 +08:00
|
|
|
|
:type="type === 'email' ? 'text' : 'number'"
|
|
|
|
|
|
class="input-account"
|
2025-02-06 11:37:41 +08:00
|
|
|
|
:value="email"
|
2025-07-15 11:24:54 +08:00
|
|
|
|
:placeholder="type === 'email' ? '请输入邮箱' : '请输入手机号'"
|
2025-02-06 11:37:41 +08:00
|
|
|
|
placeholder-class="input-placeholder"
|
|
|
|
|
|
:focus="true"
|
|
|
|
|
|
@input="updateInputEmail"
|
|
|
|
|
|
/>
|
2024-08-20 19:54:37 +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="getEmailCode">{{ text }}</view>
|
2024-08-20 19:54:37 +08:00
|
|
|
|
</view>
|
|
|
|
|
|
<view class="button" @click="toUpdateEmail">确定</view>
|
|
|
|
|
|
</view>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<script>
|
2025-02-06 11:37:41 +08:00
|
|
|
|
import { mapActions, mapState } from 'pinia'
|
|
|
|
|
|
import { useUserStore } from '@/stores/user'
|
2025-07-15 11:24:54 +08:00
|
|
|
|
import { getEmailCodeRequest, updateEmailRequest, updatePhoneRequest } from '@/api/user'
|
2025-02-06 11:37:41 +08:00
|
|
|
|
import { useBasicStore } from '@/stores/basic'
|
2025-07-15 11:24:54 +08:00
|
|
|
|
import { PHONE_REG, EMAIL_REG } from '@/constant/reg'
|
2024-08-20 19:54:37 +08:00
|
|
|
|
|
2025-02-06 11:37:41 +08:00
|
|
|
|
export default {
|
|
|
|
|
|
data() {
|
|
|
|
|
|
return {
|
|
|
|
|
|
text: '获取验证码',
|
|
|
|
|
|
verificationCode: '',
|
|
|
|
|
|
token: '',
|
|
|
|
|
|
email: '',
|
2025-07-15 11:24:54 +08:00
|
|
|
|
pending: false,
|
|
|
|
|
|
type: '',
|
|
|
|
|
|
country: {
|
|
|
|
|
|
name: '中国',
|
|
|
|
|
|
code: '86'
|
|
|
|
|
|
}
|
2025-02-06 11:37:41 +08:00
|
|
|
|
}
|
2024-08-20 19:54:37 +08:00
|
|
|
|
},
|
2025-02-06 11:37:41 +08:00
|
|
|
|
computed: {
|
2025-07-15 11:24:54 +08:00
|
|
|
|
...mapState(useUserStore, ['userInfo']),
|
|
|
|
|
|
isAccountValid() {
|
|
|
|
|
|
if (!this.email) {
|
|
|
|
|
|
return false
|
|
|
|
|
|
}
|
|
|
|
|
|
if (this.type === 'email') {
|
|
|
|
|
|
return EMAIL_REG.test(this.email)
|
|
|
|
|
|
}
|
|
|
|
|
|
if (this.type === 'mobile') {
|
|
|
|
|
|
return PHONE_REG.test(this.email)
|
|
|
|
|
|
}
|
|
|
|
|
|
return false
|
|
|
|
|
|
}
|
2024-08-20 19:54:37 +08:00
|
|
|
|
},
|
2025-02-06 11:37:41 +08:00
|
|
|
|
onLoad(option) {
|
2025-07-15 11:24:54 +08:00
|
|
|
|
this.type = option.type
|
|
|
|
|
|
uni.setNavigationBarTitle({
|
|
|
|
|
|
title: this.type === 'email' ? '验证邮箱' : '验证手机号'
|
|
|
|
|
|
})
|
2025-02-06 11:37:41 +08:00
|
|
|
|
if (option.token) {
|
|
|
|
|
|
this.token = option.token
|
2024-08-20 19:54:37 +08:00
|
|
|
|
} else {
|
2025-02-06 11:37:41 +08:00
|
|
|
|
uni.setNavigationBarTitle({
|
2025-07-15 11:24:54 +08:00
|
|
|
|
title: this.type === 'email' ? '绑定邮箱' : '绑定手机号'
|
2024-08-20 19:54:37 +08:00
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
2025-02-06 11:37:41 +08:00
|
|
|
|
methods: {
|
|
|
|
|
|
...mapActions(useUserStore, ['updateUserInfo']),
|
|
|
|
|
|
...mapActions(useBasicStore, ['routeJump', 'backAndToast', 'getNetworkType']),
|
2025-07-15 11:24:54 +08:00
|
|
|
|
toJump(path) {
|
|
|
|
|
|
this.routeJump({
|
|
|
|
|
|
name: path,
|
|
|
|
|
|
events: {
|
|
|
|
|
|
country: data => {
|
|
|
|
|
|
this.country = data
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
},
|
2025-02-06 11:37:41 +08:00
|
|
|
|
updateInputEmail(data) {
|
|
|
|
|
|
this.email = data.detail.value
|
|
|
|
|
|
},
|
|
|
|
|
|
updateInputCode(data) {
|
|
|
|
|
|
this.verificationCode = data.detail.value
|
|
|
|
|
|
},
|
|
|
|
|
|
async getEmailCode() {
|
|
|
|
|
|
if (this.text !== '获取验证码') {
|
2024-09-07 13:56:25 +08:00
|
|
|
|
return
|
|
|
|
|
|
}
|
2025-07-15 11:24:54 +08:00
|
|
|
|
if (!this.isAccountValid) {
|
2025-02-06 11:37:41 +08:00
|
|
|
|
uni.showToast({
|
2025-07-15 11:24:54 +08:00
|
|
|
|
title: this.type === 'email' ? '请输入正确的邮箱' : '请输入正确的手机号',
|
2025-02-06 11:37:41 +08:00
|
|
|
|
icon: 'none'
|
|
|
|
|
|
})
|
2024-08-21 16:20:11 +08:00
|
|
|
|
return
|
|
|
|
|
|
}
|
2025-02-06 11:37:41 +08:00
|
|
|
|
const netWork = await this.getNetworkType()
|
|
|
|
|
|
if (!netWork) {
|
|
|
|
|
|
return
|
2024-08-20 19:54:37 +08:00
|
|
|
|
}
|
2025-07-15 11:24:54 +08:00
|
|
|
|
const { code, message } = await getEmailCodeRequest({
|
2025-02-06 11:37:41 +08:00
|
|
|
|
account: this.email,
|
2025-07-15 11:24:54 +08:00
|
|
|
|
channel: this.type === 'email' ? '2' : '1',
|
|
|
|
|
|
codeType: this.type === 'email' ? 6 : 3,
|
|
|
|
|
|
countryCode: this.type === 'mobile' ? this.country.code : undefined
|
2025-02-06 11:37:41 +08:00
|
|
|
|
})
|
2024-08-20 19:54:37 +08:00
|
|
|
|
if (code === 0) {
|
2025-02-06 11:37:41 +08:00
|
|
|
|
this.updateTime()
|
|
|
|
|
|
} else {
|
|
|
|
|
|
uni.showToast({
|
2025-07-15 11:24:54 +08:00
|
|
|
|
title: message,
|
2025-02-06 11:37:41 +08:00
|
|
|
|
icon: 'none'
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
async toUpdateEmail() {
|
2025-07-15 11:24:54 +08:00
|
|
|
|
if (!this.isAccountValid) {
|
2025-02-06 11:37:41 +08:00
|
|
|
|
uni.showToast({
|
2025-07-15 11:24:54 +08:00
|
|
|
|
title: this.type === 'email' ? '请输入正确的邮箱' : '请输入正确的手机号',
|
2025-02-06 11:37:41 +08:00
|
|
|
|
icon: 'none'
|
2024-08-20 19:54:37 +08:00
|
|
|
|
})
|
2025-02-06 11:37:41 +08:00
|
|
|
|
return
|
|
|
|
|
|
}
|
2025-07-15 11:24:54 +08:00
|
|
|
|
if (/^\d{6}$/.test(this.verificationCode)) {
|
2025-02-06 11:37:41 +08:00
|
|
|
|
const netWork = await this.getNetworkType()
|
|
|
|
|
|
if (!netWork) {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
if (this.pending) {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
this.pending = true
|
|
|
|
|
|
const params = {
|
2025-07-15 11:24:54 +08:00
|
|
|
|
verificationCode: this.verificationCode
|
|
|
|
|
|
}
|
|
|
|
|
|
if (this.type === 'email') {
|
|
|
|
|
|
params.email = this.email
|
|
|
|
|
|
} else {
|
|
|
|
|
|
params.account = this.email
|
|
|
|
|
|
params.countryCode = this.country.code
|
2025-02-06 11:37:41 +08:00
|
|
|
|
}
|
|
|
|
|
|
if (this.token !== '') {
|
|
|
|
|
|
params.unbindToken = this.token
|
|
|
|
|
|
}
|
2025-07-15 11:24:54 +08:00
|
|
|
|
const request = this.type === 'email' ? updateEmailRequest : updatePhoneRequest
|
|
|
|
|
|
const { code, message } = await request(params)
|
2025-02-06 11:37:41 +08:00
|
|
|
|
if (code === 0) {
|
|
|
|
|
|
this.updateUserInfo({
|
|
|
|
|
|
...this.userInfo,
|
2025-07-15 11:24:54 +08:00
|
|
|
|
[this.type]: this.email
|
2025-02-06 11:37:41 +08:00
|
|
|
|
})
|
2025-07-15 11:24:54 +08:00
|
|
|
|
this.backAndToast(this.type === 'email' ? '邮箱绑定成功' : '手机号绑定成功')
|
2025-02-06 11:37:41 +08:00
|
|
|
|
} else {
|
|
|
|
|
|
uni.showToast({
|
|
|
|
|
|
title: message,
|
|
|
|
|
|
icon: 'none'
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
this.pending = false
|
2024-08-20 19:54:37 +08:00
|
|
|
|
} else {
|
|
|
|
|
|
uni.showToast({
|
2025-02-06 11:37:41 +08:00
|
|
|
|
title: '验证码为6位纯数字',
|
2024-08-20 19:54:37 +08:00
|
|
|
|
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)
|
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
|
|
|
|
.tips {
|
|
|
|
|
|
padding: 24rpx 32rpx 0 32rpx;
|
|
|
|
|
|
font-size: 28rpx;
|
|
|
|
|
|
color: #999999;
|
|
|
|
|
|
}
|
2024-09-03 09:42:53 +08:00
|
|
|
|
|
2025-07-15 11:24:54 +08:00
|
|
|
|
.view-country {
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
justify-content: space-between;
|
|
|
|
|
|
width: 616rpx;
|
|
|
|
|
|
height: 108rpx;
|
|
|
|
|
|
padding-right: 32rpx;
|
|
|
|
|
|
padding-left: 32rpx;
|
|
|
|
|
|
margin-top: 48rpx;
|
|
|
|
|
|
margin-left: 35rpx;
|
|
|
|
|
|
font-size: 28rpx;
|
|
|
|
|
|
line-height: 108rpx;
|
|
|
|
|
|
background: #ffffff;
|
|
|
|
|
|
border-radius: 16rpx;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.input-account {
|
2025-02-06 11:37:41 +08:00
|
|
|
|
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
|
|
|
|
.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
|
|
|
|
|
2025-02-06 11:37:41 +08:00
|
|
|
|
.view-top {
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
align-items: center;
|
|
|
|
|
|
}
|
2024-08-20 19:54:37 +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-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
|
|
|
|
</style>
|