Files
JayuCloud/JC-ArtList-Frontend/src/views/ProfileView.vue
T

1437 lines
41 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<template>
<div class="mobile-container profile-page">
<header class="profile-hero">
<div class="profile-topbar">
<div class="profile-title-copy">
<span class="profile-kicker">{{ BRAND_CONFIG.appName }}</span>
<h1>个人中心</h1>
</div>
<button class="profile-icon-button" type="button" aria-label="打开设置" @click="handleSettingsClick">
<SettingOutlined />
</button>
</div>
<section class="welcome-card" aria-label="用户信息">
<div class="avatar-frame">
<a-badge :dot="hasNotification" :offset="[-4, 8]">
<a-avatar :size="78" :src="userInfo.avatar || DEFAULT_AVATAR" class="user-avatar" />
</a-badge>
</div>
<div class="welcome-copy">
<span class="welcome-label">Welcome back</span>
<h2 class="username">{{ userInfo.nickname || `${BRAND_CONFIG.appName}用户` }}</h2>
<p class="account">{{ userInfo.account || '登录后解锁预约礼遇' }}</p>
<p v-if="userInfo.signature" class="signature">{{ userInfo.signature }}</p>
</div>
<button class="edit-profile-btn" type="button" @click="handleEditProfile">编辑</button>
</section>
<div v-if="needSetPassword" class="password-tip">
<a-alert
type="warning"
message="建议尽快设置密码"
description="当前账号还未设置登录密码。"
show-icon
>
<template #action>
<a-button size="small" type="primary" @click="handleSetPassword">去设置</a-button>
</template>
</a-alert>
</div>
</header>
<main class="profile-content">
<button class="vip-card" type="button" @click="handleMenuClick('vip')">
<span class="vip-card__glow"></span>
<span class="vip-card__copy">
<span class="section-eyebrow">指尖会员</span>
<strong>会员柔光礼遇</strong>
<small>查看会员等级、余额和专属优惠</small>
</span>
<span class="vip-card__meta">
<span>{{ couponCount }}</span>
<small>可用券</small>
</span>
</button>
<button class="shop-card" type="button" @click="handleShopCardClick">
<span class="shop-icon-wrapper">
<ShopOutlined class="shop-icon" />
</span>
<span class="shop-content">
<span class="shop-label">当前登录门店</span>
<strong class="shop-name">{{ currentShopName }}</strong>
<small class="shop-tip">{{ shopSwitchTip }}</small>
</span>
<RightOutlined class="shop-arrow" />
</button>
<section class="profile-panel order-panel" aria-labelledby="order-panel-title">
<div class="section-head">
<div>
<span class="section-eyebrow">Orders</span>
<h2 id="order-panel-title">订单状态</h2>
</div>
<button class="section-link" type="button" @click="openOrders">
全部
<RightOutlined />
</button>
</div>
<div class="order-grid">
<button class="order-tile" type="button" @click="router.push('/orders?status=priceConfirming&source=profile')">
<span class="order-icon order-icon--primary">
<ShoppingOutlined />
</span>
<span class="order-label">待报价</span>
</button>
<button class="order-tile" type="button" @click="openPendingReviews">
<span class="order-icon order-icon--gold">
<BellOutlined />
</span>
<span class="order-label">待评价</span>
</button>
<button class="order-tile" type="button" @click="router.push('/wishlist')">
<span class="order-icon order-icon--rose">
<HeartOutlined />
</span>
<span class="order-label">收藏</span>
</button>
<button class="order-tile" type="button" @click="router.push('/coupons')">
<span class="order-icon order-icon--cream">
<CreditCardOutlined />
</span>
<span class="order-label">优惠券</span>
</button>
</div>
</section>
<section class="profile-panel menu-section" aria-labelledby="menu-section-title">
<div class="section-head">
<div>
<span class="section-eyebrow">Services</span>
<h2 id="menu-section-title">常用功能</h2>
</div>
</div>
<div class="menu-list">
<button
v-for="item in profileMenuItems"
:key="item.key"
class="menu-item"
type="button"
@click="handleMenuClick(item.key)"
>
<span class="menu-icon" :style="{ backgroundColor: item.bgColor, color: item.iconColor }">
<component :is="item.icon" />
</span>
<span class="menu-copy">
<strong>{{ item.title }}</strong>
<small v-if="item.desc">{{ item.desc }}</small>
</span>
<RightOutlined class="menu-arrow" />
</button>
</div>
</section>
<div class="logout-section">
<button class="logout-button" type="button" @click="handleLogout">
退出登录
</button>
</div>
</main>
<a-modal
v-model:open="editModalVisible"
title="编辑资料"
@ok="handleSaveProfile"
@cancel="handleCancelEdit"
:confirmLoading="saving"
:ok-button-props="{ disabled: avatarUploadPending || qrUploadPending }"
>
<DraftActions
:saved-at="draftSavedAt"
:disabled="avatarUploadPending || qrUploadPending"
@save="handleSaveDraft"
@clear="handleClearDraft"
/>
<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-progress
v-if="avatarUploadPending"
:percent="Math.round(avatarUploadProgress)"
size="small"
status="active"
class="avatar-upload-progress"
/>
<div v-if="avatarUploadPending" class="avatar-upload-status">头像上传中,上传完成前不可保存。</div>
<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-item label="联系电话">
<a-input v-model:value="editForm.contactPhone" placeholder="请输入联系电话" />
</a-form-item>
<a-form-item label="生日">
<a-input v-model:value="editForm.birthday" type="date" style="width: 100%" />
</a-form-item>
<a-form-item label="微信号" :required="isServiceUser">
<a-input v-model:value="editForm.wechatId" placeholder="请输入微信号" />
</a-form-item>
<a-form-item label="微信二维码">
<div class="qr-upload-section">
<a-upload
name="file"
:show-upload-list="false"
:before-upload="beforeUploadAvatar"
:custom-request="handleWechatQrUpload"
accept="image/*"
>
<img v-if="editForm.wechatQrCode" :src="editForm.wechatQrCode" alt="微信二维码" class="wechat-qr-preview" />
<a-button v-else :loading="qrUploadPending">上传二维码</a-button>
</a-upload>
<a-button v-if="editForm.wechatQrCode" type="text" danger size="small" @click="handleDeleteWechatQr">
删除二维码
</a-button>
<small v-if="isServiceUser">店长和美甲师需填写微信号,二维码可选。</small>
</div>
</a-form-item>
</a-form>
</a-modal>
<a-modal
v-model:open="shopSwitchVisible"
title="切换登录门店"
:confirm-loading="shopSwitchLoading"
@ok="handleConfirmSwitchShop"
>
<a-radio-group v-model:value="selectedShopId" class="shop-option-group">
<a-radio
v-for="shop in shopOptions"
:key="String(shop.id)"
:value="String(shop.id)"
class="shop-option"
>
<div class="shop-option-name">{{ shop.shopName }}</div>
</a-radio>
</a-radio-group>
<a-empty v-if="!shopOptions.length" description="当前账号没有可切换的门店" />
</a-modal>
</div>
</template>
<script setup lang="ts">
/**
* ProfileView page script.
* Call guide: the template binds the reactive state below, and the methods are triggered by button clicks, lifecycle hooks, or router events.
*/
import { computed, onMounted, reactive, ref } from 'vue'
import { useRouter } from 'vue-router'
import {
BellOutlined,
CalendarOutlined,
CreditCardOutlined,
HeartOutlined,
RightOutlined,
SettingOutlined,
ShopOutlined,
ShoppingOutlined
} from '@ant-design/icons-vue'
import { message, Modal } from 'ant-design-vue'
import type { UploadProps } from 'ant-design-vue'
import DraftActions from '@/components/DraftActions.vue'
import { authApi } from '@/api/auth'
import { couponApi } from '@/api/coupon'
import { fileApi } from '@/api/file'
/**
* Purpose: UserVO supports ProfileView.vue by holding or executing the user vo page or API role.
* Usage: import, call, read, or update this type from the owning page/module while preserving the surrounding loading and permission flow.
*/
import { userApi, type UserVO } from '@/api/user'
/**
* Purpose: ChunkUploadTask supports ProfileView.vue by holding or executing the chunk upload task page or API role.
* Usage: import, call, read, or update this type from the owning page/module while preserving the surrounding loading and permission flow.
*/
import { createChunkUploadTask, type ChunkUploadTask } from '@/utils/chunk-upload'
import { buildDraftStorageKey, clearDraftRecord, loadDraftRecord, saveDraftRecord } from '@/utils/form-draft'
import { DEFAULT_AVATAR } from '@/constants'
import { runWithGlobalLoading } from '@/utils/action-loading'
import { notifyShopThemeChanged } from '@/utils/shop-theme'
import { BRAND_CONFIG } from '@/config/brand'
/**
* Purpose: router supports ProfileView.vue by holding or executing the router page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const router = useRouter()
const USER_INFO_CACHE_KEY = 'userInfo'
const createEmptyUserInfo = (): UserVO => ({
id: 0,
nickname: '',
account: '',
avatar: '',
type: 0,
status: 0,
createTime: '',
updateTime: ''
})
const readCachedUserInfo = (): UserVO => {
if (typeof window === 'undefined') {
return createEmptyUserInfo()
}
try {
const raw = localStorage.getItem(USER_INFO_CACHE_KEY)
const cached = raw ? JSON.parse(raw) as Partial<UserVO> : null
return cached && typeof cached === 'object'
? { ...createEmptyUserInfo(), ...cached }
: createEmptyUserInfo()
} catch {
return createEmptyUserInfo()
}
}
const persistCachedUserInfo = (info: UserVO) => {
if (typeof window === 'undefined') {
return
}
localStorage.setItem(USER_INFO_CACHE_KEY, JSON.stringify(info))
}
/**
* Purpose: userInfo supports ProfileView.vue by holding or executing the user info page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const userInfo = ref<UserVO>(readCachedUserInfo())
/** editModalVisible is a reactive state variable used by the template and event handlers. */
const editModalVisible = ref(false)
/** saving is a reactive state variable used by the template and event handlers. */
const saving = ref(false)
/** needSetPassword is a reactive state variable used by the template and event handlers. */
const needSetPassword = ref(false)
/** hasNotification is a reactive state variable used by the template and event handlers. */
const hasNotification = ref(false)
/** unreadMessageCount is a reactive state variable used by the template and event handlers. */
const unreadMessageCount = ref(0)
/** couponCount is a reactive state variable used by the template and event handlers. */
const couponCount = ref(0)
/** artistCalendarAccessible controls whether the appointment calendar entry is shown. */
const artistCalendarAccessible = ref(false)
/** shopSwitchVisible is a reactive state variable used by the template and event handlers. */
const shopSwitchVisible = ref(false)
/** shopSwitchLoading is a reactive state variable used by the template and event handlers. */
const shopSwitchLoading = ref(false)
/**
* Purpose: selectedShopId supports ProfileView.vue by holding or executing the selected shop id page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const selectedShopId = ref<string>()
/** avatarUploadProgress is a reactive state variable used by the template and event handlers. */
const avatarUploadProgress = ref(0)
/** avatarUploadPending is a reactive state variable used by the template and event handlers. */
const avatarUploadPending = ref(false)
/** qrUploadPending tracks the WeChat QR upload state. */
const qrUploadPending = ref(false)
let avatarUploadTask: ChunkUploadTask<string> | null = null
/**
* Purpose: draftSavedAt supports ProfileView.vue by holding or executing the draft saved at page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const draftSavedAt = ref<number | null>(null)
/**
* Purpose: editForm supports ProfileView.vue by holding or executing the edit form page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const editForm = reactive({
nickname: '',
avatar: '',
signature: '',
contactPhone: '',
birthday: '',
wechatId: '',
wechatQrCode: ''
})
/** getDraftKey is a local helper used by this page script. */
const getDraftKey = () => buildDraftStorageKey('profile-edit')
/** buildDraftPayload is a local helper used by this page script. */
const buildDraftPayload = () => ({
nickname: editForm.nickname,
avatar: editForm.avatar,
signature: editForm.signature,
contactPhone: editForm.contactPhone,
birthday: editForm.birthday,
wechatId: editForm.wechatId,
wechatQrCode: editForm.wechatQrCode
})
/** restoreDraft is a local helper used by this page script. */
const restoreDraft = () => {
const draft = loadDraftRecord<ReturnType<typeof buildDraftPayload>>(getDraftKey())
if (!draft) {
draftSavedAt.value = null
return
}
Object.assign(editForm, draft.payload)
draftSavedAt.value = draft.savedAt
message.success('已恢复暂存内容')
}
/** handleSaveDraft is a local helper used by this page script. */
const handleSaveDraft = () => {
if (avatarUploadPending.value || qrUploadPending.value) {
message.warning('头像上传完成后才能暂存')
return
}
const draft = saveDraftRecord(getDraftKey(), buildDraftPayload())
draftSavedAt.value = draft.savedAt
message.success('已暂存到本地')
}
/** handleClearDraft is a local helper used by this page script. */
const handleClearDraft = (showMessage = true) => {
clearDraftRecord(getDraftKey())
draftSavedAt.value = null
if (showMessage) {
message.success('已清除暂存')
}
}
/** shopOptions is a reactive state variable used by the template and event handlers. */
const shopOptions = computed(() => {
const ids = userInfo.value.shopIds || []
const names = userInfo.value.shopNames || []
return ids.map((id, index) => ({
id,
shopName: names[index] || `门店 ${id}`
}))
})
/** currentShopName is a reactive state variable used by the template and event handlers. */
const currentShopName = computed(() => userInfo.value.shopName || userInfo.value.shopNames?.find(Boolean) || '当前门店')
/** shopSwitchTip is a reactive state variable used by the template and event handlers. */
const shopSwitchTip = computed(() => {
if (shopOptions.value.length > 1) {
return `可切换 ${shopOptions.value.length} 家门店`
}
if (shopOptions.value.length === 1) {
return '点击查看当前门店详情'
}
return '当前暂无可用门店'
})
/**
* Purpose: coreMenuItems supports ProfileView.vue by holding or executing the core menu items page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const coreMenuItems = [
{
key: 'orders',
title: '我的订单',
desc: '查看预约状态、取消订单',
icon: ShoppingOutlined,
bgColor: 'var(--theme-primary-soft)',
iconColor: 'var(--theme-primary)'
},
{
key: 'artist-calendar',
title: '预约日历',
desc: '查看未来 7 天属于自己的预约',
icon: CalendarOutlined,
bgColor: 'var(--theme-primary-soft)',
iconColor: 'var(--theme-accent)',
serviceOnly: true
},
{
key: 'wishlist',
title: '我的收藏',
desc: '快速回到喜欢的作品',
icon: HeartOutlined,
bgColor: 'var(--theme-primary-soft)',
iconColor: 'var(--theme-primary)'
},
{
key: 'coupons',
title: '我的优惠券',
desc: '查看可用优惠和 VIP 折扣',
icon: CreditCardOutlined,
bgColor: 'var(--theme-primary-soft)',
iconColor: 'var(--theme-accent)'
},
{
key: 'vip',
title: 'VIP 中心',
desc: '查看会员等级、余额和变动记录',
icon: CreditCardOutlined,
bgColor: 'var(--theme-primary-soft)',
iconColor: 'var(--theme-accent)'
},
{
key: 'notifications',
title: '消息通知',
desc: '查看店铺通知和系统消息',
icon: BellOutlined,
bgColor: 'var(--theme-primary-soft)',
iconColor: 'var(--theme-primary)'
},
{
key: 'settings',
title: '设置中心',
desc: '统一管理账号安全和更多入口',
icon: SettingOutlined,
bgColor: 'var(--theme-primary-soft)',
iconColor: 'var(--theme-accent)'
}
]
/** profileMenuItems is a reactive state variable used by the template and event handlers. */
const canViewArtistCalendar = computed(() => {
const userType = userInfo.value.type
return userType === 3 || (userType === 2 && artistCalendarAccessible.value)
})
/**
* Purpose: profileMenuItems supports ProfileView.vue by holding or executing the profile menu items page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const profileMenuItems = computed(() => {
return coreMenuItems.filter((item: any) => !item.serviceOnly || canViewArtistCalendar.value)
})
/** isServiceUser is a reactive state variable used by the template and event handlers. */
const isServiceUser = computed(() => {
const userType = userInfo.value.type
return userType === 2 || userType === 3
})
/** persistUserSession is a local helper used by this page script. */
const persistUserSession = (payload: any) => {
localStorage.setItem('accessToken', payload.accessToken)
localStorage.setItem('refreshToken', payload.refreshToken)
localStorage.setItem(USER_INFO_CACHE_KEY, JSON.stringify(payload.userInfo))
sessionStorage.setItem('accessToken', payload.accessToken)
notifyShopThemeChanged()
if (payload.needSetPassword) {
localStorage.setItem('needSetPassword', 'true')
} else {
localStorage.removeItem('needSetPassword')
}
}
/** fetchUserInfo is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
const fetchUserInfo = async () => {
try {
artistCalendarAccessible.value = false
const response = await userApi.getUserInfo()
userInfo.value = response
persistCachedUserInfo(response)
needSetPassword.value = localStorage.getItem('needSetPassword') === 'true'
selectedShopId.value = response.shopId ? String(response.shopId) : undefined
artistCalendarAccessible.value = response.type === 3
if (response.type === 2) {
const artistInfo = await userApi.getNailArtistInfo(response.id).catch(() => null)
artistCalendarAccessible.value = Number(artistInfo?.participateProduction) === 1
}
} catch (error) {
console.error('获取用户信息失败:', error)
message.error('获取用户信息失败')
}
}
/** loadCounts is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
const loadCounts = async () => {
try {
const [coupons, unreadMessages] = await Promise.all([
couponApi.listUserCoupons(),
userApi.getMyUnreadMessageCount()
])
couponCount.value = Array.isArray(coupons) ? coupons.length : 0
unreadMessageCount.value = Number(unreadMessages?.unreadCount || 0)
hasNotification.value = unreadMessageCount.value > 0
} catch (error) {
console.error('加载个人中心统计失败:', error)
}
}
/** openOrders is a local helper used by this page script. */
const openOrders = () => {
router.push(isServiceUser.value ? '/artist-orders' : '/orders')
}
/** openPendingReviews jumps directly to the first pending review on the order page. */
const openPendingReviews = () => {
router.push('/orders?status=pendingReview&review=pending&source=profile')
}
/** handleEditProfile is a local helper used by this page script. */
const handleEditProfile = () => {
avatarUploadTask?.cancel()
avatarUploadTask = null
avatarUploadPending.value = false
qrUploadPending.value = false
avatarUploadProgress.value = 0
editForm.nickname = userInfo.value.nickname || ''
editForm.avatar = userInfo.value.avatar || ''
editForm.signature = userInfo.value.signature || ''
editForm.contactPhone = userInfo.value.contactPhone || ''
editForm.birthday = userInfo.value.birthday || ''
editForm.wechatId = userInfo.value.wechatId || ''
editForm.wechatQrCode = userInfo.value.wechatQrCode || ''
restoreDraft()
editModalVisible.value = true
}
const beforeUploadAvatar: UploadProps['beforeUpload'] = file => {
const isImage = file.type.startsWith('image/')
if (!isImage) {
message.error('只能上传图片文件')
}
return isImage
}
/** handleAvatarUpload is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
const handleAvatarUpload = async (options: any) => {
const { file, onProgress, onSuccess, onError } = options
avatarUploadTask?.cancel()
avatarUploadProgress.value = 0
avatarUploadPending.value = true
const task = createChunkUploadTask({
file: file as File,
scene: 'profile-avatar',
concurrency: 3,
api: {
initUpload: fileApi.initAvatarChunkUpload,
uploadChunk: fileApi.uploadAvatarChunk,
completeUpload: fileApi.completeAvatarChunkUpload,
cancelUpload: fileApi.cancelAvatarChunkUpload
},
onProgress: (percent) => {
avatarUploadProgress.value = percent
onProgress?.({ percent })
}
})
avatarUploadTask = task
try {
const { response } = await task.promise
editForm.avatar = response as unknown as string
avatarUploadProgress.value = 100
onSuccess?.({ url: response })
message.success('头像上传成功')
} catch (error) {
const errorMessage = (error as Error)?.message || '头像上传失败'
if (errorMessage !== '上传已取消' && errorMessage !== 'canceled') {
console.error('头像上传失败:', error)
message.error(errorMessage)
onError?.(error)
}
} finally {
if (avatarUploadTask === task) {
avatarUploadTask = null
avatarUploadPending.value = false
}
}
}
/** handleDeleteAvatar is a local helper used by this page script. */
const handleDeleteAvatar = () => {
Modal.confirm({
title: '确认删除头像',
content: '删除后会恢复为默认头像。',
okText: '确认',
cancelText: '取消',
onOk: async () => {
editForm.avatar = ''
try {
await runWithGlobalLoading(() => userApi.updateUserInfo({ avatar: '' }))
userInfo.value.avatar = ''
persistCachedUserInfo(userInfo.value)
message.success('头像删除成功')
} catch (error) {
console.error('删除头像失败:', error)
message.error('删除头像失败')
}
}
})
}
/** handleWechatQrUpload uploads a user profile QR image without changing the avatar. */
const handleWechatQrUpload: UploadProps['customRequest'] = async (options) => {
const { file, onSuccess, onError, onProgress } = options
qrUploadPending.value = true
const task = createChunkUploadTask({
file: file as File,
scene: 'profile-wechat-qr',
concurrency: 3,
api: {
initUpload: fileApi.initProfileImageChunkUpload,
uploadChunk: fileApi.uploadProfileImageChunk,
completeUpload: fileApi.completeProfileImageChunkUpload,
cancelUpload: fileApi.cancelProfileImageChunkUpload
},
onProgress: (percent) => {
onProgress?.({ percent })
}
})
try {
const { response } = await task.promise
editForm.wechatQrCode = response as unknown as string
onSuccess?.({ url: response })
message.success('微信二维码上传成功')
} catch (error) {
const errorMessage = (error as Error)?.message || '微信二维码上传失败'
if (errorMessage !== '上传已取消' && errorMessage !== 'canceled') {
console.error('微信二维码上传失败:', error)
message.error(errorMessage)
onError?.(error as Error)
}
} finally {
qrUploadPending.value = false
}
}
/** handleDeleteWechatQr clears the QR image from the edit form. */
const handleDeleteWechatQr = () => {
editForm.wechatQrCode = ''
}
/** handleSaveProfile is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
const handleSaveProfile = async () => {
if (!editForm.nickname.trim()) {
message.error('请输入昵称')
return
}
if (avatarUploadPending.value || qrUploadPending.value) {
message.warning('头像上传完成前不可保存')
return
}
if (isServiceUser.value && !editForm.wechatId.trim()) {
message.error('店长和美甲师必须填写微信号')
return
}
saving.value = true
try {
await runWithGlobalLoading(async () => {
await userApi.updateUserInfo({
nickname: editForm.nickname,
avatar: editForm.avatar,
signature: editForm.signature,
contactPhone: editForm.contactPhone,
birthday: editForm.birthday || undefined,
wechatId: editForm.wechatId,
wechatQrCode: editForm.wechatQrCode
})
await fetchUserInfo()
})
message.success('资料更新成功')
handleClearDraft(false)
editModalVisible.value = false
} catch (error) {
console.error('保存资料失败:', error)
message.error('保存资料失败')
} finally {
saving.value = false
}
}
/** handleCancelEdit is a local helper used by this page script. */
const handleCancelEdit = () => {
avatarUploadTask?.cancel()
avatarUploadTask = null
avatarUploadPending.value = false
qrUploadPending.value = false
avatarUploadProgress.value = 0
editModalVisible.value = false
}
/** handleShopCardClick is a local helper used by this page script. */
const handleShopCardClick = () => {
if (shopOptions.value.length > 1) {
shopSwitchVisible.value = true
return
}
if (userInfo.value.shopId) {
router.push(`/shop/${userInfo.value.shopId}`)
return
}
message.info('当前暂无可用门店')
}
/** handleConfirmSwitchShop is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
const handleConfirmSwitchShop = async () => {
if (!selectedShopId.value) {
message.warning('请选择要切换的门店')
return
}
if (String(userInfo.value.shopId || '') === selectedShopId.value) {
shopSwitchVisible.value = false
return
}
shopSwitchLoading.value = true
try {
await runWithGlobalLoading(async () => {
const response = await authApi.switchShop({ shopId: selectedShopId.value })
persistUserSession(response as any)
await Promise.all([fetchUserInfo(), loadCounts()])
})
message.success('门店已切换')
shopSwitchVisible.value = false
} catch (error: any) {
console.error('切换门店失败:', error)
message.error(error?.message || '切换门店失败')
} finally {
shopSwitchLoading.value = false
}
}
/** handleMenuClick is a local helper used by this page script. */
const handleMenuClick = (key: string) => {
if (key === 'orders') {
openOrders()
} else if (key === 'artist-calendar') {
if (!canViewArtistCalendar.value) {
return
}
router.push('/artist-calendar')
} else if (key === 'wishlist') {
router.push('/wishlist')
} else if (key === 'coupons') {
router.push('/coupons')
} else if (key === 'vip') {
router.push('/vip-center')
} else if (key === 'notifications') {
router.push('/notifications')
} else if (key === 'settings') {
router.push('/settings')
}
}
/** handleLogout is a local helper used by this page script. */
const handleLogout = () => {
Modal.confirm({
title: '确认退出登录',
content: '退出后需要重新登录才能继续下单和查看订单。',
okText: '确认',
cancelText: '取消',
onOk: async () => {
await runWithGlobalLoading(async () => {
try {
await authApi.logout()
} catch (error) {
console.error('退出登录接口调用失败:', error)
} finally {
localStorage.removeItem('accessToken')
localStorage.removeItem('refreshToken')
localStorage.removeItem(USER_INFO_CACHE_KEY)
localStorage.removeItem('needSetPassword')
sessionStorage.removeItem('accessToken')
notifyShopThemeChanged()
message.success('已退出登录')
router.push('/')
}
})
}
})
}
/** handleSettingsClick is a local helper used by this page script. */
const handleSettingsClick = () => {
router.push('/settings')
}
/** handleSetPassword is a local helper used by this page script. */
const handleSetPassword = () => {
router.push('/settings/password')
}
onMounted(async () => {
await fetchUserInfo()
await loadCounts()
})
</script>
<style scoped>
.profile-page {
position: relative;
min-height: 100vh;
padding: 18px 16px calc(112px + env(safe-area-inset-bottom, 0px));
overflow-x: hidden;
color: var(--text-primary);
background:
radial-gradient(ellipse at 50% 0%, color-mix(in srgb, var(--theme-primary) 42%, transparent), transparent 42%),
linear-gradient(180deg, color-mix(in srgb, var(--theme-card-bg) 84%, var(--theme-primary-soft)), var(--theme-page-bg) 46%, color-mix(in srgb, var(--theme-secondary-soft) 26%, var(--theme-page-bg))),
var(--theme-background-image),
var(--theme-page-bg);
background-size: auto, cover, cover, auto;
background-position: center top;
}
.profile-hero,
.profile-content {
position: relative;
z-index: 1;
}
.profile-hero {
display: grid;
gap: 16px;
}
.profile-topbar {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
min-height: 46px;
}
.profile-title-copy {
min-width: 0;
}
.profile-kicker,
.section-eyebrow,
.welcome-label {
display: block;
letter-spacing: 0;
}
.profile-kicker,
.section-eyebrow {
color: var(--theme-primary-action);
font-size: 11px;
font-weight: 800;
}
.profile-topbar h1 {
margin: 2px 0 0;
color: var(--text-primary);
font-size: 18px;
font-weight: 780;
line-height: 1.18;
}
.profile-icon-button,
.edit-profile-btn,
.section-link,
.vip-card,
.shop-card,
.order-tile,
.menu-item,
.logout-button {
appearance: none;
font: inherit;
border: 0;
cursor: pointer;
-webkit-tap-highlight-color: transparent;
}
.profile-icon-button {
display: inline-flex;
align-items: center;
justify-content: center;
flex: 0 0 auto;
width: 42px;
height: 42px;
border-radius: 999px;
color: var(--theme-accent);
background: color-mix(in srgb, var(--theme-card-bg) 78%, transparent);
box-shadow: 0 14px 30px color-mix(in srgb, var(--theme-neutral) 10%, transparent);
backdrop-filter: blur(16px);
}
.welcome-card,
.profile-panel,
.shop-card,
.vip-card {
border: 1px solid color-mix(in srgb, var(--theme-card-bg) 74%, var(--theme-border));
background: color-mix(in srgb, var(--theme-card-bg) 86%, transparent);
box-shadow: 0 20px 44px color-mix(in srgb, var(--theme-neutral) 11%, transparent);
backdrop-filter: blur(18px);
}
.welcome-card {
display: grid;
grid-template-columns: auto minmax(0, 1fr) auto;
align-items: center;
gap: 14px;
min-height: 128px;
padding: 20px 16px;
border-radius: 28px;
}
.avatar-frame {
display: flex;
align-items: center;
justify-content: center;
width: 88px;
height: 88px;
border-radius: 28px;
background:
linear-gradient(145deg, color-mix(in srgb, var(--theme-card-bg) 82%, transparent), color-mix(in srgb, var(--theme-primary) 18%, var(--theme-card-bg))),
var(--theme-card-bg);
}
.user-avatar {
border: 3px solid var(--theme-card-bg);
box-shadow: 0 12px 24px color-mix(in srgb, var(--theme-neutral) 12%, transparent);
}
.welcome-copy {
min-width: 0;
}
.welcome-label {
color: var(--theme-secondary);
font-size: 11px;
font-weight: 800;
}
.username {
margin: 4px 0 4px;
overflow: hidden;
color: var(--text-primary);
font-size: 20px;
font-weight: 800;
line-height: 1.18;
text-overflow: ellipsis;
white-space: nowrap;
}
.account,
.signature {
margin: 0;
color: var(--text-secondary);
font-size: 12px;
line-height: 1.5;
}
.account,
.shop-name,
.shop-tip,
.menu-copy strong,
.menu-copy small {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.signature {
display: -webkit-box;
margin-top: 4px;
overflow: hidden;
-webkit-box-orient: vertical;
-webkit-line-clamp: 2;
}
.edit-profile-btn {
align-self: start;
min-width: 50px;
min-height: 34px;
padding: 0 14px;
border-radius: 999px;
color: var(--theme-primary-action);
background: color-mix(in srgb, var(--theme-primary) 18%, var(--theme-card-bg));
font-size: 13px;
font-weight: 760;
}
.password-tip {
overflow: hidden;
border-radius: 18px;
}
.password-tip :deep(.ant-alert) {
border-color: var(--theme-border);
background: color-mix(in srgb, var(--theme-secondary-soft) 38%, var(--theme-card-bg));
}
.profile-content {
display: grid;
gap: 14px;
margin-top: 14px;
}
.vip-card {
position: relative;
display: grid;
grid-template-columns: minmax(0, 1fr) auto;
align-items: center;
gap: 16px;
min-height: 116px;
padding: 18px;
overflow: hidden;
border-radius: 26px;
text-align: left;
}
.vip-card::before {
position: absolute;
inset: 0;
content: "";
background:
linear-gradient(135deg, color-mix(in srgb, var(--theme-primary) 20%, transparent), transparent 46%),
linear-gradient(315deg, color-mix(in srgb, var(--theme-secondary) 24%, transparent), transparent 52%);
pointer-events: none;
}
.vip-card__glow {
position: absolute;
inset: auto 18px 16px auto;
width: 96px;
height: 1px;
background: var(--theme-secondary);
}
.vip-card__copy,
.vip-card__meta {
position: relative;
z-index: 1;
}
.vip-card__copy {
display: grid;
min-width: 0;
gap: 5px;
}
.vip-card__copy strong {
color: var(--text-primary);
font-size: 20px;
font-weight: 820;
line-height: 1.22;
}
.vip-card__copy small,
.vip-card__meta small {
color: var(--text-secondary);
font-size: 12px;
line-height: 1.45;
}
.vip-card__meta {
display: grid;
place-items: center;
width: 72px;
height: 72px;
border: 1px solid color-mix(in srgb, var(--theme-secondary) 42%, transparent);
border-radius: 24px;
color: var(--theme-accent);
background: color-mix(in srgb, var(--theme-card-bg) 68%, transparent);
}
.vip-card__meta span {
font-size: 22px;
font-weight: 820;
line-height: 1;
}
.shop-card {
display: grid;
grid-template-columns: auto minmax(0, 1fr) auto;
align-items: center;
gap: 14px;
min-height: 92px;
padding: 16px;
border-radius: 24px;
text-align: left;
}
.shop-icon-wrapper {
display: inline-flex;
align-items: center;
justify-content: center;
width: 52px;
height: 52px;
border-radius: 18px;
color: var(--theme-card-bg);
background: var(--theme-gradient);
}
.shop-icon {
font-size: 22px;
}
.shop-content {
display: grid;
min-width: 0;
gap: 3px;
}
.shop-label {
color: var(--theme-primary-action);
font-size: 11px;
font-weight: 780;
}
.shop-name {
color: var(--text-primary);
font-size: 16px;
font-weight: 800;
line-height: 1.28;
}
.shop-tip {
color: var(--text-secondary);
font-size: 12px;
line-height: 1.35;
}
.shop-arrow,
.menu-arrow,
.section-link {
color: var(--text-secondary);
}
.profile-panel {
padding: 18px;
border-radius: 26px;
}
.section-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 14px;
}
.section-head h2 {
margin: 3px 0 0;
color: var(--text-primary);
font-size: 18px;
font-weight: 820;
line-height: 1.25;
}
.section-link {
display: inline-flex;
align-items: center;
gap: 4px;
min-height: 34px;
padding: 0 10px;
border-radius: 999px;
background: color-mix(in srgb, var(--theme-primary-soft) 72%, transparent);
font-size: 12px;
font-weight: 760;
}
.order-grid {
display: grid;
grid-template-columns: repeat(4, minmax(0, 1fr));
gap: 8px;
}
.order-tile {
display: grid;
place-items: center;
min-width: 0;
min-height: 76px;
padding: 12px 4px;
border-radius: 20px;
color: var(--text-primary);
background: color-mix(in srgb, var(--theme-card-bg) 72%, var(--theme-primary-soft));
}
.order-icon {
display: inline-flex;
align-items: center;
justify-content: center;
width: 36px;
height: 36px;
border-radius: 14px;
font-size: 18px;
}
.order-icon--primary {
color: var(--theme-card-bg);
background: var(--theme-primary-action);
}
.order-icon--gold {
color: var(--theme-accent);
background: color-mix(in srgb, var(--theme-secondary) 34%, var(--theme-card-bg));
}
.order-icon--rose {
color: var(--theme-primary-action);
background: color-mix(in srgb, var(--theme-primary) 28%, var(--theme-card-bg));
}
.order-icon--cream {
color: var(--theme-accent);
background: color-mix(in srgb, var(--theme-secondary-soft) 74%, var(--theme-card-bg));
}
.order-label {
margin-top: 8px;
color: var(--text-secondary);
font-size: 12px;
font-weight: 760;
line-height: 1.2;
text-align: center;
}
.menu-section {
padding: 18px 0 4px;
}
.menu-section .section-head {
padding: 0 18px;
}
.menu-list {
display: grid;
}
.menu-item {
display: grid;
grid-template-columns: auto minmax(0, 1fr) auto;
align-items: center;
gap: 12px;
min-height: 72px;
padding: 12px 18px;
color: var(--text-primary);
background: transparent;
text-align: left;
}
.menu-item + .menu-item {
border-top: 1px solid var(--theme-border);
}
.menu-icon {
display: inline-flex;
align-items: center;
justify-content: center;
width: 44px;
height: 44px;
border-radius: 16px;
font-size: 19px;
}
.menu-copy {
display: grid;
min-width: 0;
gap: 4px;
}
.menu-copy strong {
color: var(--text-primary);
font-size: 14px;
font-weight: 780;
line-height: 1.25;
}
.menu-copy small {
color: var(--text-secondary);
font-size: 12px;
line-height: 1.35;
}
.logout-section {
padding: 4px 0 0;
}
.logout-button {
width: 100%;
min-height: 50px;
border: 1px solid color-mix(in srgb, var(--theme-primary) 32%, var(--theme-border));
border-radius: 999px;
color: var(--theme-primary-action);
background: color-mix(in srgb, var(--theme-card-bg) 76%, transparent);
font-size: 15px;
font-weight: 780;
box-shadow: 0 12px 28px color-mix(in srgb, var(--theme-neutral) 7%, transparent);
}
.avatar-upload-section {
display: flex;
flex-direction: column;
align-items: center;
gap: 8px;
}
.upload-hint {
font-size: 12px;
color: var(--theme-primary);
}
.avatar-upload-progress {
width: 220px;
margin-top: 4px;
}
.avatar-upload-status {
font-size: 12px;
color: var(--theme-accent);
}
.qr-upload-section {
display: grid;
justify-items: start;
gap: 8px;
}
.wechat-qr-preview {
width: 96px;
height: 96px;
border: 1px solid var(--theme-border);
border-radius: 8px;
object-fit: cover;
}
.qr-upload-section small {
color: var(--text-secondary);
line-height: 1.5;
}
.shop-option-group {
display: flex;
flex-direction: column;
gap: 12px;
}
.shop-option {
margin: 0;
padding: 12px 14px;
border: 1px solid var(--theme-border);
border-radius: 14px;
}
.shop-option-name {
font-weight: 600;
}
</style>