功能:完善门店能力与用户安全配置

This commit is contained in:
xiaowang
2026-05-18 10:04:57 +08:00
parent 4563dd2538
commit 3797938616
356 changed files with 24983 additions and 1858 deletions
+98 -7
View File
@@ -59,7 +59,7 @@
<a-card :bordered="false" class="stats-card">
<a-row :gutter="16">
<a-col :span="8">
<div class="stat-item" @click="router.push('/orders')">
<div class="stat-item" @click="openOrders">
<div class="stat-icon orders">
<ShoppingOutlined />
</div>
@@ -88,7 +88,7 @@
<div class="menu-section">
<a-card :bordered="false" class="menu-card">
<a-list :data-source="coreMenuItems" :split="false">
<a-list :data-source="profileMenuItems" :split="false">
<template #renderItem="{ item }">
<a-list-item class="menu-item" @click="handleMenuClick(item.key)">
<template #actions>
@@ -190,9 +190,15 @@
</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,
@@ -227,17 +233,30 @@ const userInfo = ref<UserVO>({
updateTime: ''
})
/** 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)
/** orderCount is a reactive state variable used by the template and event handlers. */
const orderCount = ref(0)
/** couponCount is a reactive state variable used by the template and event handlers. */
const couponCount = ref(0)
/** wishlistCount is a reactive state variable used by the template and event handlers. */
const wishlistCount = ref(0)
/** 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)
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)
let avatarUploadTask: ChunkUploadTask<string> | null = null
const draftSavedAt = ref<number | null>(null)
@@ -248,14 +267,17 @@ const editForm = reactive({
signature: ''
})
/** 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
})
/** restoreDraft is a local helper used by this page script. */
const restoreDraft = () => {
const draft = loadDraftRecord<ReturnType<typeof buildDraftPayload>>(getDraftKey())
if (!draft) {
@@ -267,6 +289,7 @@ const restoreDraft = () => {
message.success('已恢复暂存内容')
}
/** handleSaveDraft is a local helper used by this page script. */
const handleSaveDraft = () => {
if (avatarUploadPending.value) {
message.warning('头像上传完成后才能暂存')
@@ -277,6 +300,7 @@ const handleSaveDraft = () => {
message.success('已暂存到本地')
}
/** handleClearDraft is a local helper used by this page script. */
const handleClearDraft = (showMessage = true) => {
clearDraftRecord(getDraftKey())
draftSavedAt.value = null
@@ -285,6 +309,7 @@ const handleClearDraft = (showMessage = true) => {
}
}
/** 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 || []
@@ -294,7 +319,9 @@ const shopOptions = computed(() => {
}))
})
/** currentShopName is a reactive state variable used by the template and event handlers. */
const currentShopName = computed(() => userInfo.value.shopName || '当前暂无可用门店')
/** 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} 家门店`
@@ -313,6 +340,14 @@ const coreMenuItems = [
icon: ShoppingOutlined,
bgColor: '#e6f7ff'
},
{
key: 'artist-calendar',
title: '预约日历',
desc: '查看未来 7 天属于自己的预约',
icon: CalendarOutlined,
bgColor: '#fff7ed',
serviceOnly: true
},
{
key: 'wishlist',
title: '我的收藏',
@@ -327,6 +362,20 @@ const coreMenuItems = [
icon: CreditCardOutlined,
bgColor: '#fff7e6'
},
{
key: 'vip',
title: 'VIP 中心',
desc: '查看会员等级、余额和变动记录',
icon: CreditCardOutlined,
bgColor: '#f6f1e8'
},
{
key: 'notifications',
title: '消息通知',
desc: '查看店铺通知和系统消息',
icon: BellOutlined,
bgColor: '#eaf6ff'
},
{
key: 'settings',
title: '设置中心',
@@ -336,6 +385,19 @@ const coreMenuItems = [
}
]
/** profileMenuItems is a reactive state variable used by the template and event handlers. */
const profileMenuItems = computed(() => {
const userType = userInfo.value.type
return coreMenuItems.filter((item: any) => !item.serviceOnly || userType === 2 || userType === 3)
})
/** 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)
@@ -348,6 +410,7 @@ const persistUserSession = (payload: any) => {
}
}
/** fetchUserInfo is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
const fetchUserInfo = async () => {
try {
const response = await userApi.getUserInfo()
@@ -360,21 +423,32 @@ const fetchUserInfo = async () => {
}
}
/** loadCounts is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
const loadCounts = async () => {
try {
const [orders, coupons, wishlist] = await Promise.all([
orderApi.getOrderList(),
const orderListRequest = isServiceUser.value ? orderApi.getArtistOrders() : orderApi.getOrderList()
const [orders, coupons, wishlist, unreadMessages] = await Promise.all([
orderListRequest,
couponApi.listUserCoupons(),
wishlistApi.getWishlist()
wishlistApi.getWishlist(),
userApi.getMyUnreadMessageCount()
])
orderCount.value = Array.isArray(orders) ? orders.length : 0
couponCount.value = Array.isArray(coupons) ? coupons.length : 0
wishlistCount.value = Array.isArray(wishlist) ? wishlist.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')
}
/** handleEditProfile is a local helper used by this page script. */
const handleEditProfile = () => {
avatarUploadTask?.cancel()
avatarUploadTask = null
@@ -400,6 +474,7 @@ const beforeUploadAvatar: UploadProps['beforeUpload'] = file => {
return isImage && isLt20M
}
/** 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
@@ -445,6 +520,7 @@ const handleAvatarUpload = async (options: any) => {
}
}
/** handleDeleteAvatar is a local helper used by this page script. */
const handleDeleteAvatar = () => {
Modal.confirm({
title: '确认删除头像',
@@ -465,6 +541,7 @@ const handleDeleteAvatar = () => {
})
}
/** 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('请输入昵称')
@@ -497,6 +574,7 @@ const handleSaveProfile = async () => {
}
}
/** handleCancelEdit is a local helper used by this page script. */
const handleCancelEdit = () => {
avatarUploadTask?.cancel()
avatarUploadTask = null
@@ -505,6 +583,7 @@ const handleCancelEdit = () => {
editModalVisible.value = false
}
/** handleShopCardClick is a local helper used by this page script. */
const handleShopCardClick = () => {
if (shopOptions.value.length > 1) {
shopSwitchVisible.value = true
@@ -517,6 +596,7 @@ const handleShopCardClick = () => {
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('请选择要切换的门店')
@@ -544,18 +624,26 @@ const handleConfirmSwitchShop = async () => {
}
}
/** handleMenuClick is a local helper used by this page script. */
const handleMenuClick = (key: string) => {
if (key === 'orders') {
router.push('/orders')
openOrders()
} else if (key === 'artist-calendar') {
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: '确认退出登录',
@@ -582,16 +670,19 @@ const handleLogout = () => {
})
}
/** 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 Promise.all([fetchUserInfo(), loadCounts()])
await fetchUserInfo()
await loadCounts()
})
</script>