feat: 重命名邮箱相关页面为账户相关,新增手机号绑定和解绑功能

This commit is contained in:
fanpeng 2025-07-15 11:24:54 +08:00
parent bae82f76e7
commit 5360916d93
6 changed files with 165 additions and 43 deletions

View File

@ -38,6 +38,15 @@ export function unbindEmailTokenRequest(data) {
}) })
} }
// 获取解绑手机号token
export function unbindPhoneTokenRequest(data) {
return request({
url: '/user/unbindPhoneToken',
method: 'POST',
data
})
}
// 修改绑定邮箱 // 修改绑定邮箱
export function updateEmailRequest(data) { export function updateEmailRequest(data) {
return request({ return request({
@ -47,6 +56,15 @@ export function updateEmailRequest(data) {
}) })
} }
// 修改绑定手机号
export function updatePhoneRequest(data) {
return request({
url: '/user/bindPhone',
method: 'POST',
data
})
}
// 获取邮箱验证码 // 获取邮箱验证码
export function getEmailCodeRequest(data) { export function getEmailCodeRequest(data) {
return request({ return request({

View File

@ -107,13 +107,13 @@
} }
}, },
{ {
"path": "updateEmail", "path": "updateAccount",
"style": { "style": {
"navigationBarTitleText": "修改邮箱" "navigationBarTitleText": "修改邮箱"
} }
}, },
{ {
"path": "verifyEmail", "path": "verifyAccount",
"style": { "style": {
"navigationBarTitleText": "验证邮箱" "navigationBarTitleText": "验证邮箱"
} }

View File

@ -1,10 +1,30 @@
<template> <template>
<view> <view>
<view class="tips">在APP上找回密码和登录新设备时可通过绑定的邮箱验证</view> <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>
<input <input
class="input-email" :type="type === 'email' ? 'text' : 'number'"
class="input-account"
:value="email" :value="email"
placeholder="请输入邮箱" :placeholder="type === 'email' ? '请输入邮箱' : '请输入手机号'"
placeholder-class="input-placeholder" placeholder-class="input-placeholder"
:focus="true" :focus="true"
@input="updateInputEmail" @input="updateInputEmail"
@ -27,10 +47,10 @@
<script> <script>
import { mapActions, mapState } from 'pinia' import { mapActions, mapState } from 'pinia'
import { test } from 'uview-plus'
import { useUserStore } from '@/stores/user' import { useUserStore } from '@/stores/user'
import { getEmailCodeRequest, updateEmailRequest } from '@/api/user' import { getEmailCodeRequest, updateEmailRequest, updatePhoneRequest } from '@/api/user'
import { useBasicStore } from '@/stores/basic' import { useBasicStore } from '@/stores/basic'
import { PHONE_REG, EMAIL_REG } from '@/constant/reg'
export default { export default {
data() { data() {
@ -39,24 +59,55 @@
verificationCode: '', verificationCode: '',
token: '', token: '',
email: '', email: '',
pending: false pending: false,
type: '',
country: {
name: '中国',
code: '86'
}
} }
}, },
computed: { computed: {
...mapState(useUserStore, ['userInfo']) ...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
}
}, },
onLoad(option) { onLoad(option) {
this.type = option.type
uni.setNavigationBarTitle({
title: this.type === 'email' ? '验证邮箱' : '验证手机号'
})
if (option.token) { if (option.token) {
this.token = option.token this.token = option.token
} else { } else {
uni.setNavigationBarTitle({ uni.setNavigationBarTitle({
title: '绑定邮箱' title: this.type === 'email' ? '绑定邮箱' : '绑定手机号'
}) })
} }
}, },
methods: { methods: {
...mapActions(useUserStore, ['updateUserInfo']), ...mapActions(useUserStore, ['updateUserInfo']),
...mapActions(useBasicStore, ['routeJump', 'backAndToast', 'getNetworkType']), ...mapActions(useBasicStore, ['routeJump', 'backAndToast', 'getNetworkType']),
toJump(path) {
this.routeJump({
name: path,
events: {
country: data => {
this.country = data
}
}
})
},
updateInputEmail(data) { updateInputEmail(data) {
this.email = data.detail.value this.email = data.detail.value
}, },
@ -67,9 +118,9 @@
if (this.text !== '获取验证码') { if (this.text !== '获取验证码') {
return return
} }
if (!test.email(this.email)) { if (!this.isAccountValid) {
uni.showToast({ uni.showToast({
title: '请输入正确的邮箱', title: this.type === 'email' ? '请输入正确的邮箱' : '请输入正确的手机号',
icon: 'none' icon: 'none'
}) })
return return
@ -78,29 +129,30 @@
if (!netWork) { if (!netWork) {
return return
} }
const { code } = await getEmailCodeRequest({ const { code, message } = await getEmailCodeRequest({
account: this.email, account: this.email,
channel: '2', channel: this.type === 'email' ? '2' : '1',
codeType: 6 codeType: this.type === 'email' ? 6 : 3,
countryCode: this.type === 'mobile' ? this.country.code : undefined
}) })
if (code === 0) { if (code === 0) {
this.updateTime() this.updateTime()
} else { } else {
uni.showToast({ uni.showToast({
title: '验证码获取失败', title: message,
icon: 'none' icon: 'none'
}) })
} }
}, },
async toUpdateEmail() { async toUpdateEmail() {
if (!test.email(this.email)) { if (!this.isAccountValid) {
uni.showToast({ uni.showToast({
title: '请输入正确的邮箱', title: this.type === 'email' ? '请输入正确的邮箱' : '请输入正确的手机号',
icon: 'none' icon: 'none'
}) })
return return
} }
if (this.verificationCode.length === 6 && test.digits(this.verificationCode)) { if (/^\d{6}$/.test(this.verificationCode)) {
const netWork = await this.getNetworkType() const netWork = await this.getNetworkType()
if (!netWork) { if (!netWork) {
return return
@ -110,19 +162,25 @@
} }
this.pending = true this.pending = true
const params = { const params = {
verificationCode: this.verificationCode, verificationCode: this.verificationCode
email: this.email }
if (this.type === 'email') {
params.email = this.email
} else {
params.account = this.email
params.countryCode = this.country.code
} }
if (this.token !== '') { if (this.token !== '') {
params.unbindToken = this.token params.unbindToken = this.token
} }
const { code, message } = await updateEmailRequest(params) const request = this.type === 'email' ? updateEmailRequest : updatePhoneRequest
const { code, message } = await request(params)
if (code === 0) { if (code === 0) {
this.updateUserInfo({ this.updateUserInfo({
...this.userInfo, ...this.userInfo,
email: this.email [this.type]: this.email
}) })
this.backAndToast('邮箱绑定成功') this.backAndToast(this.type === 'email' ? '邮箱绑定成功' : '手机号绑定成功')
} else { } else {
uni.showToast({ uni.showToast({
title: message, title: message,
@ -167,7 +225,22 @@
color: #999999; color: #999999;
} }
.input-email { .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 {
width: 616rpx; width: 616rpx;
height: 108rpx; height: 108rpx;
padding-right: 32rpx; padding-right: 32rpx;

View File

@ -44,6 +44,7 @@
</view> </view>
</view> </view>
<view class="view-line"></view> <view class="view-line"></view>
<!-- #ifdef MP-WEIXIN -->
<label for="phone"> <label for="phone">
<view class="view-button"> <view class="view-button">
<view>手机号</view> <view>手机号</view>
@ -58,8 +59,23 @@
</view> </view>
</view> </view>
</label> </label>
<!-- #endif -->
<!-- #ifdef APP-PLUS -->
<view class="view-button" @click="toUpdateAccount('mobile')">
<view>手机号</view>
<view class="view-button" style="padding: 0">
<view v-if="userInfo.mobile !== ''" class="info">{{ userInfo.mobile }}</view>
<view v-else class="red-dot"></view>
<image
class="icon-arrow"
src="https://oss-lock.xhjcn.ltd/mp/icon_arrow.png"
mode="aspectFill"
></image>
</view>
</view>
<!-- #endif -->
<view class="view-line"></view> <view class="view-line"></view>
<view class="view-button" @click="toUpdateEmail"> <view class="view-button" @click="toUpdateAccount('email')">
<view>邮箱</view> <view>邮箱</view>
<view class="view-button" style="padding: 0"> <view class="view-button" style="padding: 0">
<view v-if="userInfo.email !== ''" class="info">{{ userInfo.email }}</view> <view v-if="userInfo.email !== ''" class="info">{{ userInfo.email }}</view>
@ -262,14 +278,20 @@
name: 'updateName' name: 'updateName'
}) })
}, },
toUpdateEmail() { toUpdateAccount(type) {
if (this.userInfo.email === '') { if (this.userInfo[type] === '') {
this.routeJump({ this.routeJump({
name: 'updateEmail' name: 'updateAccount',
params: {
type
}
}) })
} else { } else {
this.routeJump({ this.routeJump({
name: 'verifyEmail' name: 'verifyAccount',
params: {
type
}
}) })
} }
}, },

View File

@ -21,19 +21,26 @@
import { mapActions, mapState } from 'pinia' import { mapActions, mapState } from 'pinia'
import { test } from 'uview-plus' import { test } from 'uview-plus'
import { useUserStore } from '@/stores/user' import { useUserStore } from '@/stores/user'
import { getEmailCodeRequest, unbindEmailTokenRequest } from '@/api/user' import { getEmailCodeRequest, unbindEmailTokenRequest, unbindPhoneTokenRequest } from '@/api/user'
import { useBasicStore } from '@/stores/basic' import { useBasicStore } from '@/stores/basic'
export default { export default {
data() { data() {
return { return {
text: '获取验证码', text: '获取验证码',
verificationCode: '' verificationCode: '',
type: ''
} }
}, },
computed: { computed: {
...mapState(useUserStore, ['userInfo']) ...mapState(useUserStore, ['userInfo'])
}, },
onLoad(options) {
this.type = options.type
uni.setNavigationBarTitle({
title: this.type === 'email' ? '验证邮箱' : '验证手机号'
})
},
methods: { methods: {
...mapActions(useUserStore, ['updateUserInfo']), ...mapActions(useUserStore, ['updateUserInfo']),
...mapActions(useBasicStore, ['routeJump', 'getNetworkType']), ...mapActions(useBasicStore, ['routeJump', 'getNetworkType']),
@ -45,15 +52,15 @@
if (!netWork) { if (!netWork) {
return return
} }
const { code } = await getEmailCodeRequest({ const { code, message } = await getEmailCodeRequest({
channel: '2', channel: this.type === 'email' ? '2' : '1',
codeType: 7 codeType: this.type === 'email' ? 7 : 4
}) })
if (code === 0) { if (code === 0) {
this.updateTime() this.updateTime()
} else { } else {
uni.showToast({ uni.showToast({
title: '验证码获取失败', title: message,
icon: 'none' icon: 'none'
}) })
} }
@ -64,15 +71,17 @@
if (!netWork) { if (!netWork) {
return return
} }
const { code, data, message } = await unbindEmailTokenRequest({ const request = this.type === 'email' ? unbindEmailTokenRequest : unbindPhoneTokenRequest
const { code, data, message } = await request({
verificationCode: this.verificationCode verificationCode: this.verificationCode
}) })
if (code === 0) { if (code === 0) {
this.routeJump({ this.routeJump({
type: 'redirectTo', type: 'redirectTo',
name: 'updateEmail', name: 'updateAccount',
params: { params: {
token: data.token token: data.token,
type: this.type
} }
}) })
} else { } else {

View File

@ -28,13 +28,13 @@ const pages = [
tabBar: false tabBar: false
}, },
{ {
name: 'updateEmail', name: 'updateAccount',
path: '/pages/user/updateEmail', path: '/pages/user/updateAccount',
tabBar: false tabBar: false
}, },
{ {
name: 'verifyEmail', name: 'verifyAccount',
path: '/pages/user/verifyEmail', path: '/pages/user/verifyAccount',
tabBar: false tabBar: false
}, },
{ {