feat: 新增删除账号功能,更新相关页面和API

This commit is contained in:
fanpeng 2025-07-15 14:39:32 +08:00
parent 5360916d93
commit 2fbc3583e8
7 changed files with 232 additions and 6 deletions

View File

@ -31,7 +31,7 @@
return 'XHJ'
}
// #endif
return 'PRE'
return 'XHJ'
}
},
computed: {

View File

@ -155,6 +155,15 @@ export function getWebUrlRequest(data) {
})
}
// 删除账号
export function deleteAccountRequest(data) {
return request({
url: '/user/delete',
method: 'POST',
data
})
}
// 退出登录
export function logoutRequest(data) {
return request({

View File

@ -150,6 +150,13 @@
"style": {
"navigationBarTitleText": "安全验证"
}
},
{
"path": "deleteAccount",
"style": {
"navigationBarTitleText": "删除账号",
"disableScroll": true
}
}
]
},

View File

@ -77,6 +77,7 @@
<!-- #endif -->
<!-- #ifdef APP-PLUS -->
<view class="switch-account !bg-red-500" @click="logout">退出</view>
<view class="delete-account" @click="deleteAccount">删除账号</view>
<!-- #endif -->
</view>
<view v-else>
@ -175,6 +176,19 @@
'getUserInfo',
'checkSession'
]),
deleteAccount() {
uni.showModal({
title: '提示',
content: '删除账号后,你的所有信息及相关记录都会从平台彻底删除,且不可恢复,是否删除?',
success: res => {
if (res.confirm) {
this.routeJump({
name: 'deleteAccount'
})
}
}
})
},
selectEnv(env) {
setStorage('envVersion', env.key)
removeStorage('token')
@ -364,7 +378,7 @@
.switch-account {
position: absolute;
bottom: 60rpx;
bottom: 120rpx;
width: 600rpx;
height: 80rpx;
margin-left: 75rpx;
@ -377,9 +391,17 @@
border-radius: 46rpx;
}
.delete-account {
position: absolute;
right: 75rpx;
bottom: 60rpx;
font-size: 28rpx;
color: #666;
}
.env {
position: absolute;
bottom: 180rpx;
bottom: 240rpx;
width: 600rpx;
margin-left: 75rpx;
line-height: 80rpx;

View File

@ -0,0 +1,183 @@
<template>
<view>
<view class="tips">为了你的账号安全删除账号前请先使用验证码验证</view>
<view class="view-top">
<input
type="number"
class="input"
:value="verificationCode"
maxlength="6"
placeholder="请输入验证码"
placeholder-class="input-placeholder"
@input="updateInput"
/>
<view class="button-verify" @click="getEmailCode">{{ text }}</view>
</view>
<view class="button" @click="verify">验证</view>
</view>
</template>
<script>
import { mapActions, mapState } from 'pinia'
import { test } from 'uview-plus'
import { useUserStore } from '@/stores/user'
import { getEmailCodeRequest, deleteAccountRequest } from '@/api/user'
import { useBasicStore } from '@/stores/basic'
import { removeStorage } from '@/utils/storage'
export default {
data() {
return {
text: '获取验证码',
verificationCode: '',
pending: false
}
},
computed: {
...mapState(useUserStore, ['userInfo'])
},
methods: {
...mapActions(useBasicStore, ['routeJump', 'getNetworkType']),
async getEmailCode() {
if (this.text !== '获取验证码') {
return
}
const netWork = await this.getNetworkType()
if (!netWork) {
return
}
const { code, message } = await getEmailCodeRequest({
channel: this.userInfo.mobile !== '' ? '1' : '2',
codeType: 5
})
if (code === 0) {
this.updateTime()
} else {
uni.showToast({
title: message,
icon: 'none'
})
}
},
async verify() {
if (this.verificationCode.length === 6 && test.digits(this.verificationCode)) {
const netWork = await this.getNetworkType()
if (!netWork) {
return
}
this.pending = true
const { code, message } = await deleteAccountRequest({
channel: this.userInfo.mobile !== '' ? 1 : 2,
verificationCode: this.verificationCode
})
this.pending = false
if (code === 0) {
removeStorage('token')
removeStorage('openid')
removeStorage('userInfo')
removeStorage('lockList')
this.routeJump({
name: 'login',
type: 'reLaunch'
})
uni.showToast({
title: '删除成功',
icon: 'none'
})
} else {
uni.showToast({
title: message,
icon: 'none'
})
}
} else {
uni.showToast({
title: '验证码为6位纯数字',
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)
},
updateInput(data) {
this.verificationCode = data.detail.value
}
}
}
</script>
<style lang="scss">
page {
background-color: $uni-bg-color-grey;
}
</style>
<style scoped lang="scss">
.tips {
padding: 24rpx 32rpx 0 32rpx;
font-size: 28rpx;
color: #999999;
}
.button-verify {
width: 265rpx;
height: 108rpx;
margin-top: 48rpx;
margin-left: 35rpx;
font-size: 32rpx;
line-height: 108rpx;
color: #ffffff;
text-align: center;
background: #63b8af;
border-radius: 16rpx;
}
.view-top {
display: flex;
align-items: center;
}
.input {
width: 316rpx;
height: 108rpx;
padding-right: 32rpx;
padding-left: 32rpx;
margin-top: 48rpx;
margin-left: 35rpx;
background: #ffffff;
border-radius: 16rpx;
}
.input-placeholder {
height: 108rpx;
font-size: 36rpx;
font-weight: bold;
line-height: 108rpx;
}
.button {
width: 680rpx;
height: 96rpx;
margin-top: 32rpx;
margin-left: 35rpx;
font-size: 32rpx;
line-height: 96rpx;
color: #ffffff;
text-align: center;
background: #63b8af;
border-radius: 16rpx;
}
</style>

View File

@ -94,10 +94,10 @@
abbreviation: 'CN',
group: 'Z'
})
const username = ref('18174429647')
const password = ref('..022059')
const username = ref('')
const password = ref('')
const select = ref(true)
const select = ref(false)
const pending = ref(false)

View File

@ -431,6 +431,11 @@ const pages = [
name: 'safeVerify',
path: '/pages/user/safeVerify',
tabBar: false
},
{
name: 'deleteAccount',
path: '/pages/user/deleteAccount',
tabBar: false
}
]