Files
JayuCloud/Frontend/src/views/ProfileView.vue
T

653 lines
14 KiB
Vue
Raw Normal View History

<template>
<div class="mobile-container">
2026-02-24 16:07:09 +08:00
<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]">
2026-02-24 16:07:09 +08:00
<a-avatar :size="90" :src="userInfo.avatar || DEFAULT_AVATAR" class="user-avatar" />
</a-badge>
<div class="user-details">
2026-02-24 16:07:09 +08:00
<h2 class="username">{{ userInfo.nickname || '用户' }}</h2>
<p class="email">{{ userInfo.account }}</p>
<p class="signature" v-if="userInfo.signature">{{ userInfo.signature }}</p>
</div>
</div>
2026-02-24 16:07:09 +08:00
<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">
2026-02-24 16:07:09 +08:00
<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 }">
2026-02-24 16:07:09 +08:00
<a-list-item class="menu-item" @click="handleMenuClick(item.key)">
<template #actions>
<RightOutlined />
</template>
<a-list-item-meta>
<template #avatar>
<div class="menu-icon" :style="{ backgroundColor: item.bgColor }">
<component :is="item.icon" />
</div>
</template>
<template #title>
<span>{{ item.title }}</span>
</template>
<template #description v-if="item.desc">
<span>{{ item.desc }}</span>
</template>
</a-list-item-meta>
</a-list-item>
</template>
</a-list>
</a-card>
</div>
<div class="logout-section">
<a-button danger block @click="handleLogout">
退出登录
</a-button>
</div>
2026-02-24 16:07:09 +08:00
<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">
2026-02-24 16:07:09 +08:00
import { ref, onMounted } from 'vue'
import { useRouter } from 'vue-router'
2026-02-24 16:07:09 +08:00
import {
SettingOutlined,
RightOutlined,
ShoppingOutlined,
HeartOutlined,
EnvironmentOutlined,
CreditCardOutlined,
BellOutlined,
2026-02-24 16:07:09 +08:00
QuestionCircleOutlined,
ShopOutlined
} from '@ant-design/icons-vue'
2026-02-24 16:07:09 +08:00
import { message, Modal, UploadProps } from 'ant-design-vue'
2026-02-24 14:12:27 +08:00
import { authApi } from '@/api/auth'
2026-02-24 16:07:09 +08:00
import { userApi, type UserVO } from '@/api/user'
import { fileApi } from '@/api/file'
import { DEFAULT_AVATAR } from '@/constants'
const router = useRouter()
2026-02-24 16:07:09 +08:00
const userInfo = ref<UserVO>({
id: 0,
nickname: '',
account: '',
createTime: '',
updateTime: ''
})
const hasNotification = ref(true)
2026-02-24 16:07:09 +08:00
const editModalVisible = ref(false)
const saving = ref(false)
const uploading = ref(false)
const editForm = ref({
nickname: '',
avatar: '',
signature: ''
})
const menuItems = ref([
2026-02-24 16:07:09 +08:00
{
key: 'orders',
title: '我的订单',
icon: ShoppingOutlined,
bgColor: '#e6f7ff'
},
2026-02-24 16:07:09 +08:00
{
key: 'wishlist',
title: '我的收藏',
icon: HeartOutlined,
bgColor: '#fff1f0'
},
2026-02-24 16:07:09 +08:00
{
key: 'address',
title: '收货地址',
icon: EnvironmentOutlined,
bgColor: '#f6ffed'
},
2026-02-24 16:07:09 +08:00
{
key: 'payment',
title: '支付方式',
icon: CreditCardOutlined,
bgColor: '#fff7e6'
},
2026-02-24 16:07:09 +08:00
{
key: 'notifications',
title: '消息通知',
desc: '3条未读',
icon: BellOutlined,
bgColor: '#f9f0ff'
},
2026-02-24 16:07:09 +08:00
{
key: 'help',
title: '帮助与支持',
icon: QuestionCircleOutlined,
bgColor: '#e6f7ff'
}
])
2026-02-24 16:07:09 +08:00
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 = () => {
2026-02-24 16:07:09 +08:00
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') {
router.push('/wishlist')
} else if (key === 'orders') {
message.info('订单功能开发中...')
} else if (key === 'address') {
message.info('地址管理功能开发中...')
} else if (key === 'payment') {
message.info('支付方式功能开发中...')
} else if (key === 'notifications') {
message.info('消息通知功能开发中...')
} else if (key === 'help') {
message.info('帮助中心功能开发中...')
}
}
const handleLogout = () => {
2026-02-24 14:12:27 +08:00
Modal.confirm({
title: '确认退出登录',
content: '确定要退出登录吗?',
okText: '确定',
cancelText: '取消',
onOk: async () => {
try {
await authApi.logout()
} catch (error) {
console.error('登出接口调用失败:', error)
} finally {
localStorage.removeItem('accessToken')
localStorage.removeItem('refreshToken')
sessionStorage.removeItem('accessToken')
message.success('已退出登录')
router.push('/auth')
}
}
})
}
const handleSettingsClick = () => {
console.log('设置图标被点击')
router.push('/settings')
}
2026-02-24 16:07:09 +08:00
onMounted(() => {
fetchUserInfo()
})
</script>
<style scoped>
.mobile-container {
padding-top: 60px;
min-height: 100vh;
background: #f5f5f5;
2026-02-24 16:07:09 +08:00
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 {
position: fixed;
top: 0;
left: 0;
right: 0;
z-index: 100;
display: flex;
justify-content: space-between;
align-items: center;
padding: 10px 15px;
2026-02-24 16:07:09 +08:00
background: transparent;
color: white;
}
.header h1 {
font-size: 18px;
font-weight: bold;
margin: 0;
}
.settings-btn {
width: 40px;
height: 40px;
display: flex;
align-items: center;
justify-content: center;
2026-02-24 16:07:09 +08:00
color: white;
}
.profile-info {
padding: 15px;
2026-02-24 16:07:09 +08:00
position: relative;
z-index: 1;
}
.profile-card {
2026-02-24 16:07:09 +08:00
border-radius: 20px;
overflow: hidden;
2026-02-24 16:07:09 +08:00
box-shadow: 0 8px 30px rgba(0, 0, 0, 0.08);
}
.profile-card :deep(.ant-card-body) {
2026-02-24 16:07:09 +08:00
padding: 28px 24px 24px;
}
.avatar-section {
display: flex;
align-items: center;
2026-02-24 16:07:09 +08:00
gap: 18px;
margin-bottom: 24px;
}
.user-avatar {
border: 4px solid white;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}
.user-details {
flex: 1;
}
.username {
2026-02-24 16:07:09 +08:00
font-size: 24px;
font-weight: 700;
margin: 0 0 6px 0;
color: #1a1a2e;
}
.email {
2026-02-24 16:07:09 +08:00
color: #8b8b9a;
font-size: 14px;
2026-02-24 16:07:09 +08:00
margin: 0 0 6px 0;
}
.signature {
color: #6b6b7a;
font-size: 13px;
margin: 0;
2026-02-24 16:07:09 +08:00
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;
2026-02-24 16:07:09 +08:00
position: relative;
z-index: 1;
}
2026-02-24 16:07:09 +08:00
.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) {
2026-02-24 16:07:09 +08:00
font-size: 13px;
color: #8b8b9a;
font-weight: 500;
}
.stats-section :deep(.ant-statistic-content) {
2026-02-24 16:07:09 +08:00
font-size: 22px;
font-weight: 700;
color: #1a1a2e;
}
.menu-section {
padding: 0 15px 15px;
2026-02-24 16:07:09 +08:00
position: relative;
z-index: 1;
}
.menu-card {
2026-02-24 16:07:09 +08:00
border-radius: 20px;
overflow: hidden;
2026-02-24 16:07:09 +08:00
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.05);
}
.menu-card :deep(.ant-card-body) {
padding: 0;
}
.menu-item {
2026-02-24 16:07:09 +08:00
padding: 18px 16px;
cursor: pointer;
2026-02-24 16:07:09 +08:00
transition: all 0.3s ease;
border-bottom: 1px solid #f5f5f7;
}
.menu-item:hover {
2026-02-24 16:07:09 +08:00
background: #f8f9ff;
}
.menu-item:last-child {
border-bottom: none;
}
.menu-item :deep(.ant-list-item-action) {
margin-left: 8px;
2026-02-24 16:07:09 +08:00
color: #c4c4d0;
}
.menu-icon {
2026-02-24 16:07:09 +08:00
width: 44px;
height: 44px;
border-radius: 12px;
display: flex;
align-items: center;
justify-content: center;
2026-02-24 16:07:09 +08:00
font-size: 20px;
color: white;
}
.menu-item :deep(.ant-list-item-meta-title) {
font-size: 15px;
2026-02-24 16:07:09 +08:00
font-weight: 600;
color: #1a1a2e;
}
.menu-item :deep(.ant-list-item-meta-description) {
font-size: 12px;
2026-02-24 16:07:09 +08:00
color: #8b8b9a;
margin-top: 4px;
}
.logout-section {
2026-02-24 16:07:09 +08:00
padding: 0 15px 25px;
position: relative;
z-index: 1;
}
.logout-section :deep(.ant-btn-dangerous) {
2026-02-24 16:07:09 +08:00
height: 50px;
border-radius: 25px;
font-weight: 600;
font-size: 16px;
2026-02-24 16:07:09 +08:00
background: linear-gradient(135deg, #ff6b6b 0%, #ee5a6f 100%);
border: none;
box-shadow: 0 4px 15px rgba(238, 90, 111, 0.3);
}
2026-02-24 16:07:09 +08:00
</style>