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) {
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) {
return request({

View File

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

View File

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

View File

@ -44,6 +44,7 @@
</view>
</view>
<view class="view-line"></view>
<!-- #ifdef MP-WEIXIN -->
<label for="phone">
<view class="view-button">
<view>手机号</view>
@ -58,8 +59,23 @@
</view>
</view>
</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-button" @click="toUpdateEmail">
<view class="view-button" @click="toUpdateAccount('email')">
<view>邮箱</view>
<view class="view-button" style="padding: 0">
<view v-if="userInfo.email !== ''" class="info">{{ userInfo.email }}</view>
@ -262,14 +278,20 @@
name: 'updateName'
})
},
toUpdateEmail() {
if (this.userInfo.email === '') {
toUpdateAccount(type) {
if (this.userInfo[type] === '') {
this.routeJump({
name: 'updateEmail'
name: 'updateAccount',
params: {
type
}
})
} else {
this.routeJump({
name: 'verifyEmail'
name: 'verifyAccount',
params: {
type
}
})
}
},

View File

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

View File

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