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

1443 lines
41 KiB
Vue
Raw Normal View History

<template>
2026-05-29 13:30:56 +08:00
<div class="mobile-container profile-page">
<header class="profile-hero">
<div class="profile-topbar">
<div class="profile-title-copy">
2026-06-24 22:13:00 +08:00
<span class="profile-kicker">{{ BRAND_CONFIG.appName }}</span>
2026-05-29 13:30:56 +08:00
<h1>个人中心</h1>
</div>
<button class="profile-icon-button" type="button" aria-label="打开设置" @click="handleSettingsClick">
<SettingOutlined />
</button>
</div>
2026-05-29 13:30:56 +08:00
<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>
2026-06-24 22:13:00 +08:00
<h2 class="username">{{ userInfo.nickname || `${BRAND_CONFIG.appName}用户` }}</h2>
2026-05-29 13:30:56 +08:00
<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>
2026-05-29 13:30:56 +08:00
<main class="profile-content">
<button class="vip-card" type="button" @click="handleMenuClick('vip')">
<span class="vip-card__glow"></span>
<span class="vip-card__copy">
2026-05-30 18:31:35 +08:00
<span class="section-eyebrow">指尖会员</span>
2026-05-29 13:30:56 +08:00
<strong>会员柔光礼遇</strong>
<small>查看会员等级、余额和专属优惠</small>
</span>
<span class="vip-card__meta">
<span>{{ couponCount }}</span>
<small>可用券</small>
</span>
</button>
2026-05-29 13:30:56 +08:00
<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>
2026-05-29 13:30:56 +08:00
<button class="section-link" type="button" @click="openOrders">
全部
<RightOutlined />
2026-05-29 13:30:56 +08:00
</button>
</div>
<div class="order-grid">
2026-06-04 16:39:06 +08:00
<button class="order-tile" type="button" @click="router.push('/orders?status=priceConfirming&source=profile')">
2026-05-29 13:30:56 +08:00
<span class="order-icon order-icon--primary">
<ShoppingOutlined />
</span>
2026-06-04 16:39:06 +08:00
<span class="order-label">待报价</span>
2026-05-29 13:30:56 +08:00
</button>
<button class="order-tile" type="button" @click="openPendingReviews">
<span class="order-icon order-icon--gold">
<BellOutlined />
</span>
2026-06-04 16:39:06 +08:00
<span class="order-label">待评价</span>
2026-05-29 13:30:56 +08:00
</button>
<button class="order-tile" type="button" @click="router.push('/wishlist')">
<span class="order-icon order-icon--rose">
<HeartOutlined />
</span>
2026-06-04 16:39:06 +08:00
<span class="order-label">收藏</span>
2026-05-29 13:30:56 +08:00
</button>
<button class="order-tile" type="button" @click="router.push('/coupons')">
<span class="order-icon order-icon--cream">
<CreditCardOutlined />
</span>
2026-06-04 16:39:06 +08:00
<span class="order-label">优惠券</span>
2026-05-29 13:30:56 +08:00
</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>
2026-02-24 16:07:09 +08:00
</div>
</div>
2026-05-29 13:30:56 +08:00
<div class="menu-list">
<button
v-for="item in profileMenuItems"
:key="item.key"
class="menu-item"
type="button"
@click="handleMenuClick(item.key)"
>
2026-05-29 13:30:56 +08:00
<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>
2026-05-29 13:30:56 +08:00
</section>
2026-05-29 13:30:56 +08:00
<div class="logout-section">
<button class="logout-button" type="button" @click="handleLogout">
退出登录
</button>
2026-05-29 13:30:56 +08:00
</div>
</main>
2026-02-24 16:07:09 +08:00
<a-modal
v-model:open="editModalVisible"
2026-02-24 16:07:09 +08:00
title="编辑资料"
@ok="handleSaveProfile"
@cancel="handleCancelEdit"
:confirmLoading="saving"
2026-05-29 13:30:56 +08:00
:ok-button-props="{ disabled: avatarUploadPending || qrUploadPending }"
2026-02-24 16:07:09 +08:00
>
2026-03-26 12:04:02 +08:00
<DraftActions
:saved-at="draftSavedAt"
2026-05-29 13:30:56 +08:00
:disabled="avatarUploadPending || qrUploadPending"
2026-03-26 12:04:02 +08:00
@save="handleSaveDraft"
@clear="handleClearDraft"
/>
2026-02-24 16:07:09 +08:00
<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>
2026-03-26 11:41:38 +08:00
<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>
2026-02-24 16:07:09 +08:00
<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>
2026-05-29 13:30:56 +08:00
<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>
2026-02-24 16:07:09 +08:00
</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'
2026-02-24 16:07:09 +08:00
import {
BellOutlined,
CalendarOutlined,
CreditCardOutlined,
HeartOutlined,
RightOutlined,
SettingOutlined,
ShopOutlined,
ShoppingOutlined
} from '@ant-design/icons-vue'
2026-02-25 09:13:45 +08:00
import { message, Modal } from 'ant-design-vue'
import type { UploadProps } from 'ant-design-vue'
2026-03-26 12:04:02 +08:00
import DraftActions from '@/components/DraftActions.vue'
2026-02-24 14:12:27 +08:00
import { authApi } from '@/api/auth'
import { couponApi } from '@/api/coupon'
2026-02-24 16:07:09 +08:00
import { fileApi } from '@/api/file'
2026-05-23 18:44:57 +08:00
/**
* 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'
2026-05-23 18:44:57 +08:00
/**
* 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.
*/
2026-03-26 11:41:38 +08:00
import { createChunkUploadTask, type ChunkUploadTask } from '@/utils/chunk-upload'
2026-03-26 12:04:02 +08:00
import { buildDraftStorageKey, clearDraftRecord, loadDraftRecord, saveDraftRecord } from '@/utils/form-draft'
2026-02-24 16:07:09 +08:00
import { DEFAULT_AVATAR } from '@/constants'
import { runWithGlobalLoading } from '@/utils/action-loading'
import { notifyShopThemeChanged } from '@/utils/shop-theme'
2026-06-24 22:13:00 +08:00
import { BRAND_CONFIG } from '@/config/brand'
2026-05-23 18:44:57 +08:00
/**
* 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()
2026-05-31 18:36:52 +08:00
const USER_INFO_CACHE_KEY = 'userInfo'
2026-05-31 18:36:52 +08:00
const createEmptyUserInfo = (): UserVO => ({
2026-02-24 16:07:09 +08:00
id: 0,
nickname: '',
account: '',
2026-03-02 10:13:20 +08:00
avatar: '',
type: 0,
status: 0,
2026-02-24 16:07:09 +08:00
createTime: '',
updateTime: ''
})
2026-05-31 18:36:52 +08:00
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. */
2026-02-24 16:07:09 +08:00
const editModalVisible = ref(false)
/** saving is a reactive state variable used by the template and event handlers. */
2026-02-24 16:07:09 +08:00
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. */
2026-02-28 14:32:28 +08:00
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)
2026-05-23 18:44:57 +08:00
/**
* 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. */
2026-03-26 11:41:38 +08:00
const avatarUploadProgress = ref(0)
/** avatarUploadPending is a reactive state variable used by the template and event handlers. */
2026-03-26 11:41:38 +08:00
const avatarUploadPending = ref(false)
2026-05-29 13:30:56 +08:00
/** qrUploadPending tracks the WeChat QR upload state. */
const qrUploadPending = ref(false)
2026-03-26 11:41:38 +08:00
let avatarUploadTask: ChunkUploadTask<string> | null = null
2026-05-23 18:44:57 +08:00
/**
* 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.
*/
2026-03-26 12:04:02 +08:00
const draftSavedAt = ref<number | null>(null)
2026-05-23 18:44:57 +08:00
/**
* 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({
2026-02-24 16:07:09 +08:00
nickname: '',
avatar: '',
2026-05-29 13:30:56 +08:00
signature: '',
contactPhone: '',
birthday: '',
wechatId: '',
wechatQrCode: ''
2026-02-24 16:07:09 +08:00
})
/** 打开编辑弹窗时的联系电话原值,用于判断用户是否真实修改过(未修改则不提交该字段)。 */
const originalContactPhone = ref('')
/** getDraftKey is a local helper used by this page script. */
2026-03-26 12:04:02 +08:00
const getDraftKey = () => buildDraftStorageKey('profile-edit')
/** buildDraftPayload is a local helper used by this page script. */
2026-03-26 12:04:02 +08:00
const buildDraftPayload = () => ({
nickname: editForm.nickname,
avatar: editForm.avatar,
2026-05-29 13:30:56 +08:00
signature: editForm.signature,
contactPhone: editForm.contactPhone,
birthday: editForm.birthday,
wechatId: editForm.wechatId,
wechatQrCode: editForm.wechatQrCode
2026-03-26 12:04:02 +08:00
})
/** restoreDraft is a local helper used by this page script. */
2026-03-26 12:04:02 +08:00
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. */
2026-03-26 12:04:02 +08:00
const handleSaveDraft = () => {
2026-05-29 13:30:56 +08:00
if (avatarUploadPending.value || qrUploadPending.value) {
2026-03-26 12:04:02 +08:00
message.warning('头像上传完成后才能暂存')
return
}
const draft = saveDraftRecord(getDraftKey(), buildDraftPayload())
draftSavedAt.value = draft.savedAt
message.success('已暂存到本地')
}
/** handleClearDraft is a local helper used by this page script. */
2026-03-26 12:04:02 +08:00
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. */
2026-05-31 18:36:52 +08:00
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 '当前暂无可用门店'
})
2026-05-23 18:44:57 +08:00
/**
* 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)
})
2026-05-23 18:44:57 +08:00
/**
* 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)
2026-05-31 18:36:52 +08:00
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. */
2026-02-24 16:07:09 +08:00
const fetchUserInfo = async () => {
try {
artistCalendarAccessible.value = false
const response = await userApi.getUserInfo()
2026-03-02 10:13:20 +08:00
userInfo.value = response
2026-05-31 18:36:52 +08:00
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
}
2026-02-24 16:07:09 +08:00
} catch (error) {
console.error('获取用户信息失败:', error)
2026-02-24 16:07:09 +08:00
message.error('获取用户信息失败')
}
}
/** loadCounts is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
const loadCounts = async () => {
try {
2026-06-04 16:39:06 +08:00
const [coupons, unreadMessages] = await Promise.all([
couponApi.listUserCoupons(),
2026-06-04 16:39:06 +08:00
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)
2026-02-24 16:07:09 +08:00
}
}
/** 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 = () => {
2026-06-04 16:39:06 +08:00
router.push('/orders?status=pendingReview&review=pending&source=profile')
}
/** handleEditProfile is a local helper used by this page script. */
const handleEditProfile = () => {
2026-03-26 11:41:38 +08:00
avatarUploadTask?.cancel()
avatarUploadTask = null
avatarUploadPending.value = false
2026-05-29 13:30:56 +08:00
qrUploadPending.value = false
2026-03-26 11:41:38 +08:00
avatarUploadProgress.value = 0
editForm.nickname = userInfo.value.nickname || ''
editForm.avatar = userInfo.value.avatar || ''
editForm.signature = userInfo.value.signature || ''
2026-05-29 13:30:56 +08:00
editForm.contactPhone = userInfo.value.contactPhone || ''
originalContactPhone.value = editForm.contactPhone
2026-05-29 13:30:56 +08:00
editForm.birthday = userInfo.value.birthday || ''
editForm.wechatId = userInfo.value.wechatId || ''
editForm.wechatQrCode = userInfo.value.wechatQrCode || ''
2026-03-26 12:04:02 +08:00
restoreDraft()
2026-02-24 16:07:09 +08:00
editModalVisible.value = true
}
const beforeUploadAvatar: UploadProps['beforeUpload'] = file => {
2026-02-24 16:07:09 +08:00
const isImage = file.type.startsWith('image/')
if (!isImage) {
message.error('只能上传图片文件')
2026-02-24 16:07:09 +08:00
}
return isImage
2026-02-24 16:07:09 +08:00
}
/** handleAvatarUpload is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
2026-02-24 16:07:09 +08:00
const handleAvatarUpload = async (options: any) => {
2026-03-26 11:41:38 +08:00
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,
2026-03-26 11:41:38 +08:00
api: {
initUpload: fileApi.initAvatarChunkUpload,
uploadChunk: fileApi.uploadAvatarChunk,
completeUpload: fileApi.completeAvatarChunkUpload,
cancelUpload: fileApi.cancelAvatarChunkUpload
},
onProgress: (percent) => {
avatarUploadProgress.value = percent
onProgress?.({ percent })
}
})
avatarUploadTask = task
2026-02-24 16:07:09 +08:00
try {
2026-03-26 11:41:38 +08:00
const { response } = await task.promise
editForm.avatar = response as unknown as string
avatarUploadProgress.value = 100
onSuccess?.({ url: response })
2026-02-24 16:07:09 +08:00
message.success('头像上传成功')
} catch (error) {
2026-03-26 11:41:38 +08:00
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
}
2026-02-24 16:07:09 +08:00
}
}
/** handleDeleteAvatar is a local helper used by this page script. */
2026-02-24 16:07:09 +08:00
const handleDeleteAvatar = () => {
Modal.confirm({
title: '确认删除头像',
content: '删除后会恢复为默认头像。',
okText: '确认',
cancelText: '取消',
2026-02-25 09:13:45 +08:00
onOk: async () => {
editForm.avatar = ''
2026-02-25 09:13:45 +08:00
try {
await runWithGlobalLoading(() => userApi.updateUserInfo({ avatar: '' }))
userInfo.value.avatar = ''
2026-05-31 18:36:52 +08:00
persistCachedUserInfo(userInfo.value)
2026-02-25 09:13:45 +08:00
message.success('头像删除成功')
} catch (error) {
console.error('删除头像失败:', error)
message.error('删除头像失败')
}
2026-02-24 16:07:09 +08:00
}
})
}
2026-05-29 13:30:56 +08:00
/** handleWechatQrUpload uploads a user profile QR image without changing the avatar. */
const handleWechatQrUpload: UploadProps['customRequest'] = async (options) => {
const { file, onSuccess, onError, onProgress } = options
2026-05-29 13:30:56 +08:00
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 })
}
})
2026-05-29 13:30:56 +08:00
try {
const { response } = await task.promise
2026-05-29 13:30:56 +08:00
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)
}
2026-05-29 13:30:56 +08:00
} 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. */
2026-02-24 16:07:09 +08:00
const handleSaveProfile = async () => {
if (!editForm.nickname.trim()) {
2026-02-24 16:07:09 +08:00
message.error('请输入昵称')
return
}
2026-05-29 13:30:56 +08:00
if (avatarUploadPending.value || qrUploadPending.value) {
2026-03-26 11:41:38 +08:00
message.warning('头像上传完成前不可保存')
return
}
2026-05-29 13:30:56 +08:00
if (isServiceUser.value && !editForm.wechatId.trim()) {
message.error('店长和美甲师必须填写微信号')
return
}
2026-02-24 16:07:09 +08:00
saving.value = true
try {
await runWithGlobalLoading(async () => {
const payload = {
nickname: editForm.nickname,
avatar: editForm.avatar,
2026-05-29 13:30:56 +08:00
signature: editForm.signature,
birthday: editForm.birthday || undefined,
wechatId: editForm.wechatId,
wechatQrCode: editForm.wechatQrCode,
// 只有联系电话真实变更时才提交,避免把接口回填值(可能已脱敏)原样写回
...(editForm.contactPhone !== originalContactPhone.value ? { contactPhone: editForm.contactPhone } : {})
}
await userApi.updateUserInfo(payload)
await fetchUserInfo()
})
2026-02-24 16:07:09 +08:00
message.success('资料更新成功')
2026-03-26 12:04:02 +08:00
handleClearDraft(false)
2026-02-24 16:07:09 +08:00
editModalVisible.value = false
} catch (error) {
console.error('保存资料失败:', error)
message.error('保存资料失败')
} finally {
saving.value = false
}
}
/** handleCancelEdit is a local helper used by this page script. */
2026-02-24 16:07:09 +08:00
const handleCancelEdit = () => {
2026-03-26 11:41:38 +08:00
avatarUploadTask?.cancel()
avatarUploadTask = null
avatarUploadPending.value = false
2026-05-29 13:30:56 +08:00
qrUploadPending.value = false
2026-03-26 11:41:38 +08:00
avatarUploadProgress.value = 0
2026-02-24 16:07:09 +08:00
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') {
2026-02-28 15:45:16 +08:00
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 = () => {
2026-02-24 14:12:27 +08:00
Modal.confirm({
title: '确认退出登录',
content: '退出后需要重新登录才能继续下单和查看订单。',
okText: '确认',
2026-02-24 14:12:27 +08:00
cancelText: '取消',
onOk: async () => {
await runWithGlobalLoading(async () => {
try {
await authApi.logout()
} catch (error) {
console.error('退出登录接口调用失败:', error)
} finally {
localStorage.removeItem('accessToken')
localStorage.removeItem('refreshToken')
2026-05-31 18:36:52 +08:00
localStorage.removeItem(USER_INFO_CACHE_KEY)
localStorage.removeItem('needSetPassword')
sessionStorage.removeItem('accessToken')
notifyShopThemeChanged()
message.success('已退出登录')
router.push('/')
}
})
2026-02-24 14:12:27 +08:00
}
})
}
/** handleSettingsClick is a local helper used by this page script. */
const handleSettingsClick = () => {
router.push('/settings')
}
2026-02-24 16:07:09 +08:00
/** handleSetPassword is a local helper used by this page script. */
const handleSetPassword = () => {
router.push('/settings/password')
}
onMounted(async () => {
await fetchUserInfo()
await loadCounts()
2026-02-24 16:07:09 +08:00
})
</script>
<style scoped>
2026-05-29 13:30:56 +08:00
.profile-page {
position: relative;
min-height: 100vh;
2026-05-29 13:30:56 +08:00
padding: 18px 16px calc(112px + env(safe-area-inset-bottom, 0px));
overflow-x: hidden;
color: var(--text-primary);
background:
2026-05-29 13:30:56 +08:00
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);
2026-05-29 13:30:56 +08:00
background-size: auto, cover, cover, auto;
background-position: center top;
2026-02-24 16:07:09 +08:00
}
2026-05-29 13:30:56 +08:00
.profile-hero,
.profile-content {
2026-02-24 16:07:09 +08:00
position: relative;
z-index: 1;
}
2026-05-29 13:30:56 +08:00
.profile-hero {
display: grid;
gap: 16px;
}
2026-05-29 13:30:56 +08:00
.profile-topbar {
display: flex;
align-items: center;
2026-05-29 13:30:56 +08:00
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);
2026-05-31 18:36:52 +08:00
font-size: 18px;
2026-05-29 13:30:56 +08:00
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);
2026-02-24 16:07:09 +08:00
}
.user-avatar {
2026-05-29 13:30:56 +08:00
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 {
2026-05-29 13:30:56 +08:00
margin: 4px 0 4px;
overflow: hidden;
color: var(--text-primary);
2026-05-31 18:36:52 +08:00
font-size: 20px;
2026-05-29 13:30:56 +08:00
font-weight: 800;
line-height: 1.18;
text-overflow: ellipsis;
white-space: nowrap;
}
.account,
2026-02-24 16:07:09 +08:00
.signature {
margin: 0;
2026-05-29 13:30:56 +08:00
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;
2026-02-24 16:07:09 +08:00
}
.shop-card {
2026-05-29 13:30:56 +08:00
display: grid;
grid-template-columns: auto minmax(0, 1fr) auto;
2026-02-24 16:07:09 +08:00
align-items: center;
gap: 14px;
2026-05-29 13:30:56 +08:00
min-height: 92px;
padding: 16px;
border-radius: 24px;
text-align: left;
2026-02-24 16:07:09 +08:00
}
.shop-icon-wrapper {
2026-05-29 13:30:56 +08:00
display: inline-flex;
2026-02-24 16:07:09 +08:00
align-items: center;
justify-content: center;
2026-05-29 13:30:56 +08:00
width: 52px;
height: 52px;
border-radius: 18px;
color: var(--theme-card-bg);
background: var(--theme-gradient);
2026-02-24 16:07:09 +08:00
}
.shop-icon {
2026-05-29 13:30:56 +08:00
font-size: 22px;
2026-02-24 16:07:09 +08:00
}
.shop-content {
2026-05-29 13:30:56 +08:00
display: grid;
min-width: 0;
gap: 3px;
2026-02-24 16:07:09 +08:00
}
.shop-label {
2026-05-29 13:30:56 +08:00
color: var(--theme-primary-action);
font-size: 11px;
font-weight: 780;
2026-02-24 16:07:09 +08:00
}
.shop-name {
2026-05-29 13:30:56 +08:00
color: var(--text-primary);
font-size: 16px;
font-weight: 800;
line-height: 1.28;
}
.shop-tip {
2026-05-29 13:30:56 +08:00
color: var(--text-secondary);
font-size: 12px;
line-height: 1.35;
2026-02-24 16:07:09 +08:00
}
2026-05-29 13:30:56 +08:00
.shop-arrow,
.menu-arrow,
.section-link {
color: var(--text-secondary);
}
2026-05-29 13:30:56 +08:00
.profile-panel {
padding: 18px;
border-radius: 26px;
}
2026-05-29 13:30:56 +08:00
.section-head {
display: flex;
align-items: center;
2026-05-29 13:30:56 +08:00
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;
2026-06-04 16:39:06 +08:00
min-height: 76px;
padding: 12px 4px;
2026-05-29 13:30:56 +08:00
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;
2026-05-29 13:30:56 +08:00
width: 36px;
height: 36px;
border-radius: 14px;
font-size: 18px;
}
2026-05-29 13:30:56 +08:00
.order-icon--primary {
color: var(--theme-card-bg);
background: var(--theme-primary-action);
}
2026-05-29 13:30:56 +08:00
.order-icon--gold {
color: var(--theme-accent);
background: color-mix(in srgb, var(--theme-secondary) 34%, var(--theme-card-bg));
}
2026-05-29 13:30:56 +08:00
.order-icon--rose {
color: var(--theme-primary-action);
background: color-mix(in srgb, var(--theme-primary) 28%, var(--theme-card-bg));
}
2026-05-29 13:30:56 +08:00
.order-icon--cream {
color: var(--theme-accent);
background: color-mix(in srgb, var(--theme-secondary-soft) 74%, var(--theme-card-bg));
}
2026-06-04 16:39:06 +08:00
.order-label {
margin-top: 8px;
2026-05-29 13:30:56 +08:00
color: var(--text-secondary);
2026-06-04 16:39:06 +08:00
font-size: 12px;
font-weight: 760;
2026-05-29 13:30:56 +08:00
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 {
2026-05-29 13:30:56 +08:00
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;
}
2026-05-29 13:30:56 +08:00
.menu-item + .menu-item {
border-top: 1px solid var(--theme-border);
}
.menu-icon {
2026-05-29 13:30:56 +08:00
display: inline-flex;
align-items: center;
justify-content: center;
2026-05-29 13:30:56 +08:00
width: 44px;
height: 44px;
border-radius: 16px;
font-size: 19px;
}
2026-05-29 13:30:56 +08:00
.menu-copy {
display: grid;
min-width: 0;
gap: 4px;
}
.menu-copy strong {
color: var(--text-primary);
font-size: 14px;
2026-05-29 13:30:56 +08:00
font-weight: 780;
line-height: 1.25;
}
2026-05-29 13:30:56 +08:00
.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);
2026-02-24 16:07:09 +08:00
}
.avatar-upload-section {
display: flex;
flex-direction: column;
align-items: center;
gap: 8px;
}
.upload-hint {
font-size: 12px;
color: var(--theme-primary);
}
2026-03-26 11:41:38 +08:00
.avatar-upload-progress {
width: 220px;
margin-top: 4px;
}
.avatar-upload-status {
font-size: 12px;
color: var(--theme-accent);
2026-03-26 11:41:38 +08:00
}
2026-05-29 13:30:56 +08:00
.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 {
2026-02-24 16:07:09 +08:00
display: flex;
flex-direction: column;
gap: 12px;
}
.shop-option {
margin: 0;
padding: 12px 14px;
2026-05-29 13:30:56 +08:00
border: 1px solid var(--theme-border);
border-radius: 14px;
}
.shop-option-name {
font-weight: 600;
}
</style>