修复一些问题,个人账号功能完善,注册功能完善,收藏,购物车功能完善,初版基本完成,投入测试

This commit is contained in:
xiaowang
2026-03-03 17:50:10 +08:00
parent b301e37468
commit b0470b8f86
23 changed files with 804 additions and 129 deletions
+115 -36
View File
@@ -11,36 +11,8 @@
<!-- 账号设置内容 -->
<div class="account-settings">
<!-- 状态提示 -->
<div v-if="!hasPassword || !hasPhone" class="status-tips">
<a-alert
v-if="!hasPassword"
type="warning"
message="请设置密码"
description="为了账户安全,建议您设置一个安全的密码"
show-icon
:closable="false"
>
<template #action>
<a-button size="small" type="primary" @click="handleSetPassword">去设置</a-button>
</template>
</a-alert>
<a-alert
v-if="!hasPhone"
type="warning"
message="请绑定手机号"
description="绑定手机号可以提高账户安全性"
show-icon
:closable="false"
>
<template #action>
<a-button size="small" type="primary" @click="handleBindPhone">去绑定</a-button>
</template>
</a-alert>
</div>
<!-- 账号设置选项 -->
<a-card :bordered="false" class="settings-card" v-if="hasPassword && hasPhone">
<a-card :bordered="false" class="settings-card">
<a-list :data-source="accountSettings" :split="false">
<template #renderItem="{ item }">
<a-list-item class="setting-item" @click="handleSettingClick(item.key)">
@@ -190,7 +162,7 @@
import { ref, reactive, onMounted } from 'vue'
import { useRouter } from 'vue-router'
import { LeftOutlined, RightOutlined, LockOutlined, PhoneOutlined } from '@ant-design/icons-vue'
import { message } from 'ant-design-vue'
import { message, Modal } from 'ant-design-vue'
import { userApi } from '@/api/user'
import type { UserVO } from '@/api/user'
@@ -253,9 +225,64 @@ const accountSettings = ref([
title: '修改密码',
icon: LockOutlined,
bgColor: '#f6ffed'
},
{
key: 'deactivateAccount',
title: '注销账号',
icon: LockOutlined,
bgColor: '#fff1f0'
}
])
// 根据用户状态动态更新账号设置选项
const updateAccountSettings = () => {
const settings = []
// 手机号相关
if (!hasPhone.value) {
settings.push({
key: 'bindPhone',
title: '绑定手机号',
icon: PhoneOutlined,
bgColor: '#e6f7ff'
})
} else {
settings.push({
key: 'changePhone',
title: '修改手机号',
icon: PhoneOutlined,
bgColor: '#e6f7ff'
})
}
// 密码相关
if (!hasPassword.value) {
settings.push({
key: 'setPassword',
title: '设置密码',
icon: LockOutlined,
bgColor: '#fff7e6'
})
} else {
settings.push({
key: 'changePassword',
title: '修改密码',
icon: LockOutlined,
bgColor: '#f6ffed'
})
}
// 注销账号
settings.push({
key: 'deactivateAccount',
title: '注销账号',
icon: LockOutlined,
bgColor: '#fff1f0'
})
accountSettings.value = settings
}
// 获取用户信息
const fetchUserInfo = async () => {
try {
@@ -265,6 +292,8 @@ const fetchUserInfo = async () => {
hasPhone.value = !!userInfo.value.phone
// 检查是否设置密码(通过localStorage中的标识)
hasPassword.value = localStorage.getItem('needSetPassword') !== 'true'
// 更新账号设置选项
updateAccountSettings()
} catch (error) {
console.error('获取用户信息失败:', error)
message.error('获取用户信息失败')
@@ -279,12 +308,21 @@ const handleBackClick = () => {
// 处理设置项点击
const handleSettingClick = (key: string) => {
switch (key) {
case 'bindPhone':
bindPhoneModalVisible.value = true
break
case 'changePhone':
changePhoneModalVisible.value = true
break
case 'setPassword':
handleSetPassword()
break
case 'changePassword':
changePasswordModalVisible.value = true
break
case 'deactivateAccount':
handleDeactivateAccount()
break
default:
break
}
@@ -295,12 +333,7 @@ const handleSetPassword = () => {
router.push('/settings/password')
}
// 处理绑定手机号
const handleBindPhone = () => {
bindPhoneModalVisible.value = true
}
// 发送验证码
// 发送绑定手机号验证码
const handleSendVerificationCode = async () => {
if (!bindPhoneForm.phone) {
message.error('请输入手机号')
@@ -461,6 +494,52 @@ const handleChangePasswordCancel = () => {
changePasswordForm.confirmPassword = ''
}
// 处理注销账号
const handleDeactivateAccount = async () => {
Modal.confirm({
title: '确认注销账号',
content: '注销账号后,您的所有数据将被删除且无法恢复。确定要注销账号吗?',
okText: '确认注销',
okType: 'danger',
cancelText: '取消',
onOk: async () => {
try {
// 在删除前先重命名账号和手机号,添加删除时间戳
const timestamp = new Date().getTime()
const newAccount = `${userInfo.value.account}_deleted_${timestamp}`
const newPhone = `${userInfo.value.phone}_deleted_${timestamp}`
try {
await userApi.updateUserInfo({ account: newAccount, phone: newPhone })
} catch (renameError) {
console.error('重命名账号和手机号失败:', renameError)
// 重命名失败也继续删除流程
}
await userApi.deactivateAccount()
message.success('账号注销成功')
} catch (error) {
console.error('注销账号失败:', error)
message.error('注销账号失败')
} finally {
// 无论成功或失败,都清除本地存储的用户信息
localStorage.removeItem('accessToken')
localStorage.removeItem('refreshToken')
localStorage.removeItem('userInfo')
localStorage.removeItem('adminAccessToken')
localStorage.removeItem('adminRefreshToken')
localStorage.removeItem('adminUserInfo')
localStorage.removeItem('needSetPassword')
localStorage.removeItem('userPermissions')
sessionStorage.removeItem('accessToken')
sessionStorage.removeItem('adminAccessToken')
// 跳转到登录页
router.push('/')
}
}
})
}
// 生命周期
onMounted(() => {
fetchUserInfo()