个人资料修改

This commit is contained in:
xiaowang
2026-02-24 16:07:09 +08:00
parent cd805632ad
commit faee2d4e0c
12 changed files with 495 additions and 116 deletions
+391 -101
View File
@@ -1,56 +1,78 @@
<template>
<div class="mobile-container">
<!-- 头部区域 -->
<div class="header-bg"></div>
<header class="header">
<h1>个人中心</h1>
<a-button class="settings-btn" type="text" @click="handleSettingsClick">
<SettingOutlined :style="{ fontSize: '20px' }" />
</a-button>
</header>
<!-- 用户信息卡片 -->
<div class="profile-info">
<a-card :bordered="false" class="profile-card">
<div class="avatar-section">
<a-badge :dot="hasNotification" :offset="[-5, 5]">
<a-avatar :size="80" src="https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png" />
<a-avatar :size="90" :src="userInfo.avatar || DEFAULT_AVATAR" class="user-avatar" />
</a-badge>
<div class="user-details">
<h2 class="username">昵称</h2>
<p class="email">user@example.com</p>
<h2 class="username">{{ userInfo.nickname || '用户' }}</h2>
<p class="email">{{ userInfo.account }}</p>
<p class="signature" v-if="userInfo.signature">{{ userInfo.signature }}</p>
</div>
</div>
<a-button type="primary" block @click="handleEditProfile">
<div class="shop-section" v-if="userInfo.shopName">
<div class="shop-card">
<div class="shop-icon-wrapper">
<ShopOutlined class="shop-icon" />
</div>
<div class="shop-content">
<p class="shop-label">所属店铺</p>
<h3 class="shop-name">{{ userInfo.shopName }}</h3>
</div>
<div class="shop-arrow">
<RightOutlined />
</div>
</div>
</div>
<a-button type="primary" block @click="handleEditProfile" class="edit-btn">
编辑资料
</a-button>
</a-card>
</div>
<!-- 统计数据 -->
<div class="stats-section">
<a-row :gutter="16">
<a-col :span="8">
<a-statistic title="订单" :value="12" />
</a-col>
<a-col :span="8">
<a-statistic title="收藏" :value="5" />
</a-col>
<a-col :span="8">
<a-statistic title="优惠券" :value="3" />
</a-col>
</a-row>
<a-card :bordered="false" class="stats-card">
<a-row :gutter="16">
<a-col :span="8">
<div class="stat-item">
<div class="stat-icon" style="background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);">
<ShoppingOutlined />
</div>
<a-statistic title="订单" :value="12" />
</div>
</a-col>
<a-col :span="8">
<div class="stat-item">
<div class="stat-icon" style="background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);">
<HeartOutlined />
</div>
<a-statistic title="收藏" :value="5" />
</div>
</a-col>
<a-col :span="8">
<div class="stat-item">
<div class="stat-icon" style="background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);">
<CreditCardOutlined />
</div>
<a-statistic title="优惠券" :value="3" />
</div>
</a-col>
</a-row>
</a-card>
</div>
<!-- 菜单列表 -->
<div class="menu-section">
<a-card :bordered="false" class="menu-card">
<a-list :data-source="menuItems" :split="false">
<template #renderItem="{ item }">
<a-list-item
class="menu-item"
@click="handleMenuClick(item.key)"
>
<a-list-item class="menu-item" @click="handleMenuClick(item.key)">
<template #actions>
<RightOutlined />
</template>
@@ -72,85 +94,212 @@
</a-list>
</a-card>
</div>
<!-- 退出登录按钮 -->
<div class="logout-section">
<a-button danger block @click="handleLogout">
退出登录
</a-button>
</div>
<a-modal
v-model:visible="editModalVisible"
title="编辑资料"
@ok="handleSaveProfile"
@cancel="handleCancelEdit"
:confirmLoading="saving"
>
<a-form layout="vertical">
<a-form-item label="头像">
<div class="avatar-upload-section">
<a-upload
name="file"
:show-upload-list="false"
:before-upload="beforeUploadAvatar"
:custom-request="handleAvatarUpload"
accept="image/*"
>
<a-avatar :size="80" :src="editForm.avatar || DEFAULT_AVATAR" />
<div class="upload-hint">点击更换头像</div>
</a-upload>
<a-button v-if="editForm.avatar" type="text" danger size="small" @click="handleDeleteAvatar">
删除头像
</a-button>
</div>
</a-form-item>
<a-form-item label="昵称">
<a-input v-model:value="editForm.nickname" placeholder="请输入昵称" />
</a-form-item>
<a-form-item label="个性签名">
<a-textarea v-model:value="editForm.signature" placeholder="请输入个性签名" :rows="3" />
</a-form-item>
</a-form>
</a-modal>
</div>
</template>
<script setup lang="ts">
import { ref } from 'vue'
import { ref, onMounted } from 'vue'
import { useRouter } from 'vue-router'
import {
SettingOutlined,
import {
SettingOutlined,
RightOutlined,
ShoppingOutlined,
HeartOutlined,
EnvironmentOutlined,
CreditCardOutlined,
BellOutlined,
QuestionCircleOutlined
QuestionCircleOutlined,
ShopOutlined
} from '@ant-design/icons-vue'
import { message, Modal } from 'ant-design-vue'
import { message, Modal, UploadProps } from 'ant-design-vue'
import { authApi } from '@/api/auth'
import { userApi, type UserVO } from '@/api/user'
import { fileApi } from '@/api/file'
import { DEFAULT_AVATAR } from '@/constants'
const router = useRouter()
// 是否有未读通知
const userInfo = ref<UserVO>({
id: 0,
nickname: '',
account: '',
createTime: '',
updateTime: ''
})
const hasNotification = ref(true)
const editModalVisible = ref(false)
const saving = ref(false)
const uploading = ref(false)
const editForm = ref({
nickname: '',
avatar: '',
signature: ''
})
// 菜单项数据
const menuItems = ref([
{
key: 'orders',
title: '我的订单',
{
key: 'orders',
title: '我的订单',
icon: ShoppingOutlined,
bgColor: '#e6f7ff'
},
{
key: 'wishlist',
title: '我的收藏',
{
key: 'wishlist',
title: '我的收藏',
icon: HeartOutlined,
bgColor: '#fff1f0'
},
{
key: 'address',
title: '收货地址',
{
key: 'address',
title: '收货地址',
icon: EnvironmentOutlined,
bgColor: '#f6ffed'
},
{
key: 'payment',
title: '支付方式',
{
key: 'payment',
title: '支付方式',
icon: CreditCardOutlined,
bgColor: '#fff7e6'
},
{
key: 'notifications',
title: '消息通知',
{
key: 'notifications',
title: '消息通知',
desc: '3条未读',
icon: BellOutlined,
bgColor: '#f9f0ff'
},
{
key: 'help',
title: '帮助与支持',
{
key: 'help',
title: '帮助与支持',
icon: QuestionCircleOutlined,
bgColor: '#e6f7ff'
}
])
// 处理编辑资料点击
const fetchUserInfo = async () => {
try {
console.log('开始获取用户信息...')
const res = await userApi.getUserInfo()
console.log('获取到的用户信息:', res)
userInfo.value = res
console.log('设置后的 userInfo:', userInfo.value)
} catch (error) {
console.error('获取用户信息失败:', error)
message.error('获取用户信息失败')
}
}
const handleEditProfile = () => {
console.log('编辑个人资料被点击')
message.info('编辑功能开发中...')
editForm.value = {
nickname: userInfo.value.nickname || '',
avatar: userInfo.value.avatar || '',
signature: userInfo.value.signature || ''
}
editModalVisible.value = true
}
const beforeUploadAvatar: UploadProps['beforeUpload'] = (file) => {
const isImage = file.type.startsWith('image/')
const isLt2M = file.size / 1024 / 1024 < 2
if (!isImage) {
message.error('只能上传图片文件!')
}
if (!isLt2M) {
message.error('图片大小不能超过 2MB!')
}
return isImage && isLt2M
}
const handleAvatarUpload = async (options: any) => {
const { file } = options
uploading.value = true
try {
const res = await fileApi.uploadAvatar(file)
editForm.value.avatar = res
message.success('头像上传成功')
} catch (error) {
console.error('头像上传失败:', error)
message.error('头像上传失败')
} finally {
uploading.value = false
}
}
const handleDeleteAvatar = () => {
Modal.confirm({
title: '确认删除',
content: '确定要删除头像吗?',
onOk: () => {
editForm.value.avatar = ''
}
})
}
const handleSaveProfile = async () => {
if (!editForm.value.nickname) {
message.error('请输入昵称')
return
}
saving.value = true
try {
await userApi.updateUserInfo(editForm.value)
message.success('资料更新成功')
editModalVisible.value = false
await fetchUserInfo()
} catch (error) {
console.error('保存资料失败:', error)
message.error('保存资料失败')
} finally {
saving.value = false
}
}
const handleCancelEdit = () => {
editModalVisible.value = false
}
// 处理菜单项点击
const handleMenuClick = (key: string) => {
console.log('菜单项被点击:', key)
if (key === 'wishlist') {
@@ -168,7 +317,6 @@ const handleMenuClick = (key: string) => {
}
}
// 处理退出登录
const handleLogout = () => {
Modal.confirm({
title: '确认退出登录',
@@ -181,24 +329,24 @@ const handleLogout = () => {
} catch (error) {
console.error('登出接口调用失败:', error)
} finally {
// 清除本地存储的token
localStorage.removeItem('accessToken')
localStorage.removeItem('refreshToken')
sessionStorage.removeItem('accessToken')
message.success('已退出登录')
// 跳转到登录页面
router.push('/auth')
}
}
})
}
// 处理设置图标点击
const handleSettingsClick = () => {
console.log('设置图标被点击')
router.push('/settings')
}
onMounted(() => {
fetchUserInfo()
})
</script>
<style scoped>
@@ -206,6 +354,17 @@ const handleSettingsClick = () => {
padding-top: 60px;
min-height: 100vh;
background: #f5f5f5;
position: relative;
}
.header-bg {
position: fixed;
top: 0;
left: 0;
right: 0;
height: 180px;
background: linear-gradient(135deg, #667eea 0%, #764ba2 50%, #f093fb 100%);
z-index: 0;
}
.header {
@@ -218,9 +377,8 @@ const handleSettingsClick = () => {
justify-content: space-between;
align-items: center;
padding: 10px 15px;
border-bottom: 1px solid #f0f0f0;
background: white;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
background: transparent;
color: white;
}
.header h1 {
@@ -235,26 +393,35 @@ const handleSettingsClick = () => {
display: flex;
align-items: center;
justify-content: center;
color: white;
}
.profile-info {
padding: 15px;
position: relative;
z-index: 1;
}
.profile-card {
border-radius: 16px;
border-radius: 20px;
overflow: hidden;
box-shadow: 0 8px 30px rgba(0, 0, 0, 0.08);
}
.profile-card :deep(.ant-card-body) {
padding: 24px;
padding: 28px 24px 24px;
}
.avatar-section {
display: flex;
align-items: center;
gap: 16px;
margin-bottom: 20px;
gap: 18px;
margin-bottom: 24px;
}
.user-avatar {
border: 4px solid white;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}
.user-details {
@@ -262,46 +429,162 @@ const handleSettingsClick = () => {
}
.username {
font-size: 20px;
font-weight: bold;
margin: 0 0 4px 0;
font-size: 24px;
font-weight: 700;
margin: 0 0 6px 0;
color: #1a1a2e;
}
.email {
color: #999;
color: #8b8b9a;
font-size: 14px;
margin: 0 0 6px 0;
}
.signature {
color: #6b6b7a;
font-size: 13px;
margin: 0;
line-height: 1.6;
}
.shop-section {
margin-bottom: 24px;
}
.shop-card {
display: flex;
align-items: center;
gap: 14px;
padding: 18px;
background: linear-gradient(135deg, #f5f7ff 0%, #e8ecff 100%);
border-radius: 16px;
cursor: pointer;
transition: all 0.3s ease;
}
.shop-card:hover {
transform: translateY(-2px);
box-shadow: 0 6px 20px rgba(102, 126, 234, 0.15);
}
.shop-icon-wrapper {
width: 52px;
height: 52px;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
border-radius: 14px;
display: flex;
align-items: center;
justify-content: center;
flex-shrink: 0;
}
.shop-icon {
font-size: 24px;
color: white;
}
.shop-content {
flex: 1;
}
.shop-label {
font-size: 12px;
color: #8b8b9a;
margin: 0 0 4px 0;
}
.shop-name {
font-size: 18px;
font-weight: 600;
color: #1a1a2e;
margin: 0;
}
.shop-arrow {
color: #c4c4d0;
font-size: 16px;
}
.edit-btn {
height: 48px;
border-radius: 12px;
font-size: 15px;
font-weight: 600;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
border: none;
box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}
.avatar-upload-section {
display: flex;
flex-direction: column;
align-items: center;
gap: 8px;
}
.upload-hint {
font-size: 12px;
color: #667eea;
margin-top: 4px;
}
.stats-section {
padding: 0 15px 15px;
display: flex;
justify-content: center;
position: relative;
z-index: 1;
}
.stats-section :deep(.ant-row) {
width: 100%;
max-width: 400px;
.stats-card {
border-radius: 20px;
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.05);
}
.stats-card :deep(.ant-card-body) {
padding: 20px 16px;
}
.stat-item {
display: flex;
flex-direction: column;
align-items: center;
gap: 10px;
}
.stat-icon {
width: 52px;
height: 52px;
border-radius: 14px;
display: flex;
align-items: center;
justify-content: center;
font-size: 24px;
color: white;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}
.stats-section :deep(.ant-statistic-title) {
font-size: 12px;
color: #999;
font-size: 13px;
color: #8b8b9a;
font-weight: 500;
}
.stats-section :deep(.ant-statistic-content) {
font-size: 20px;
font-weight: bold;
color: #1890ff;
font-size: 22px;
font-weight: 700;
color: #1a1a2e;
}
.menu-section {
padding: 0 15px 15px;
position: relative;
z-index: 1;
}
.menu-card {
border-radius: 16px;
border-radius: 20px;
overflow: hidden;
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.05);
}
.menu-card :deep(.ant-card-body) {
@@ -309,14 +592,14 @@ const handleSettingsClick = () => {
}
.menu-item {
padding: 16px;
padding: 18px 16px;
cursor: pointer;
transition: background 0.3s;
border-bottom: 1px solid #f0f0f0;
transition: all 0.3s ease;
border-bottom: 1px solid #f5f5f7;
}
.menu-item:hover {
background: #fafafa;
background: #f8f9ff;
}
.menu-item:last-child {
@@ -325,38 +608,45 @@ const handleSettingsClick = () => {
.menu-item :deep(.ant-list-item-action) {
margin-left: 8px;
color: #ccc;
color: #c4c4d0;
}
.menu-icon {
width: 40px;
height: 40px;
border-radius: 10px;
width: 44px;
height: 44px;
border-radius: 12px;
display: flex;
align-items: center;
justify-content: center;
font-size: 18px;
font-size: 20px;
color: white;
}
.menu-item :deep(.ant-list-item-meta-title) {
font-size: 15px;
font-weight: 500;
color: #333;
font-weight: 600;
color: #1a1a2e;
}
.menu-item :deep(.ant-list-item-meta-description) {
font-size: 12px;
color: #999;
color: #8b8b9a;
margin-top: 4px;
}
.logout-section {
padding: 0 15px 20px;
padding: 0 15px 25px;
position: relative;
z-index: 1;
}
.logout-section :deep(.ant-btn-dangerous) {
height: 48px;
border-radius: 24px;
height: 50px;
border-radius: 25px;
font-weight: 600;
font-size: 16px;
background: linear-gradient(135deg, #ff6b6b 0%, #ee5a6f 100%);
border: none;
box-shadow: 0 4px 15px rgba(238, 90, 111, 0.3);
}
</style>
</style>