import { useMemo, useCallback } from 'react' import Taro from '@tarojs/taro' import { View, Text, Image, ScrollView } from '@tarojs/components' import { Cell, CellGroup, Icon } from '@antmjs/vantui' import useAuthStore from '@/stores/auth/useAuthStore' import { GENDER_MAP } from '@/types/user' import type { Gender } from '@/types/user' import './index.less' /** 状态栏高度 */ function getStatusBarHeight(): number { try { return Taro.getSystemInfoSync().statusBarHeight || 20 } catch { return 20 } } /** 默认用户信息(未登录时展示占位) */ const DEFAULT_USER = { avatar: 'https://picsum.photos/seed/avatar/200/200', name: '未登录', className: '点击登录体验更多功能', gender: '男' as const, stats: { likes: '-', comments: '-', favorites: '-' }, } /** 订单入口 */ const ORDER_TABS = [ { key: 'all', label: '全部', icon: 'orders-o' }, { key: 'pending', label: '待付款', icon: 'balance-pay' }, { key: 'progress', label: '进行中', icon: 'logistics' }, { key: 'confirm', label: '待确认', icon: 'checked' }, { key: 'review', label: '待评价', icon: 'star-o' }, ] /** 功能列表 */ const FEATURE_LIST = [ { key: 'goods', label: '商品订单', icon: 'orders-o' }, { key: 'address', label: '地址管理', icon: 'location-o' }, { key: 'about', label: '关于我们', icon: 'info-o' }, { key: 'feedback', label: '意见反馈', icon: 'chat-o' }, ] as const export default function Profile() { const statusBarH = useMemo(getStatusBarHeight, []) const user = useAuthStore(s => s.user) const logout = useAuthStore(s => s.logout) const isLoggedIn = useAuthStore(s => !!s.token && !!s.user) /** 跳转登录页 */ const handleGoToLogin = useCallback(() => { Taro.navigateTo({ url: '/pages/login/index' }) }, []) const handleSettings = () => { Taro.showToast({ title: '设置页面即将上线', icon: 'none' }) } const handleEditProfile = () => { if (isLoggedIn) { Taro.navigateTo({ url: '/pages/profile-edit/index' }) } else { handleGoToLogin() } } const handleOrderTab = (key: string) => { if (!isLoggedIn) { handleGoToLogin() return } Taro.showToast({ title: `${ORDER_TABS.find(t => t.key === key)?.label || ''}订单即将上线`, icon: 'none' }) } const handleFeature = (item: typeof FEATURE_LIST[number]) => { if (!isLoggedIn) { handleGoToLogin() return } Taro.showToast({ title: `${item.label}即将上线`, icon: 'none' }) } const handleAllOrders = () => { if (!isLoggedIn) { handleGoToLogin() return } Taro.showToast({ title: '全部订单即将上线', icon: 'none' }) } /** 退出登录 */ const handleLogout = useCallback(() => { Taro.showModal({ title: '提示', content: '确定要退出登录吗?', success: (res) => { if (res.confirm) { logout() Taro.showToast({ title: '已退出登录', icon: 'success' }) } }, }) }, [logout]) // 根据登录状态决定展示的用户信息 const displayUser = isLoggedIn && user ? { avatar: user.avatar, name: user.nickname, className: '在校学生', // 后续可扩展班级字段 gender: GENDER_MAP[user.gender] || '未知', stats: { likes: '-', comments: '-', favorites: '-' }, // 暂用占位,后续从 API 获取 } : DEFAULT_USER return ( {/* ========== 背景图区域 ========== */} {/* 设置按钮 */} {/* 头像 + 用户信息 */} {isLoggedIn ? ( <> {displayUser.name} {displayUser.gender === '男' ? '♂' : displayUser.gender === '女' ? '♀' : ''} {displayUser.className} ) : ( <> 点击登录账号 登录后体验更多功能 )} {/* 点赞/评论/收藏 */} {displayUser.stats.likes} 点赞 {displayUser.stats.comments} 评论 {displayUser.stats.favorites} 收藏 {/* ========== 可滚动内容 ========== */} {/* ========== 订单卡片 ========== */} 我的订单 全部 {ORDER_TABS.map((tab) => ( handleOrderTab(tab.key)} > {tab.label} ))} {/* ========== 功能列表 ========== */} {FEATURE_LIST.map((item, index) => ( handleFeature(item)} /> ))} {/* ========== 退出登录(仅登录后显示) ========== */} {isLoggedIn && ( )} {/* ========== 底部信息 ========== */} 湘ICP备2024000000号-1 校园通 v1.0.0 ) }