import { View, Text } from '@tarojs/components'; import Taro, { useDidShow } from '@tarojs/taro'; import { useAuthStore } from '../../stores/auth'; import { usePointsStore } from '../../stores/points'; import { useUIStore } from '../../stores/ui'; import { navigateToLogin } from '../../utils/navigate'; import './index.scss'; interface MenuItem { label: string; icon: string; bg: string; color: string; path: string; isSwitchTab?: boolean; } interface MenuGroup { title: string; items: MenuItem[]; } const LOGGED_IN_GROUPS: MenuGroup[] = [ { title: '健康管理', items: [ { label: '健康记录', icon: '健', bg: 'pri-l', color: 'pri', path: '/pages/pkg-profile/health-records/index' }, { label: '我的报告', icon: '报', bg: 'acc-l', color: 'acc', path: '/pages/pkg-profile/reports/index' }, { label: 'AI 分析', icon: '智', bg: 'pri-l', color: 'pri', path: '/pages/ai-report/list/index' }, { label: '诊断记录', icon: '诊', bg: 'acc-l', color: 'acc', path: '/pages/pkg-profile/diagnoses/index' }, { label: '用药记录', icon: '药', bg: 'pri-l', color: 'pri', path: '/pages/pkg-profile/medication/index' }, ], }, { title: '就诊服务', items: [ { label: '我的预约', icon: '约', bg: 'pri-l', color: 'pri', path: '/pages/appointment/index' }, { label: '我的随访', icon: '随', bg: 'acc-l', color: 'acc', path: '/pages/pkg-profile/followups/index' }, { label: '在线咨询', icon: '问', bg: 'pri-l', color: 'pri', path: '/pages/consultation/index' }, ], }, { title: '透析管理', items: [ { label: '透析记录', icon: '透', bg: 'pri-l', color: 'pri', path: '/pages/pkg-profile/dialysis-records/index' }, { label: '透析处方', icon: '方', bg: 'acc-l', color: 'acc', path: '/pages/pkg-profile/dialysis-prescriptions/index' }, { label: '知情同意', icon: '知', bg: 'pri-l', color: 'pri', path: '/pages/pkg-profile/consents/index' }, ], }, { title: '生活服务', items: [ { label: '积分商城', icon: '礼', bg: 'pri-l', color: 'pri', path: '/pages/mall/index', isSwitchTab: true }, { label: '线下活动', icon: '活', bg: 'acc-l', color: 'acc', path: '/pages/events/index' }, ], }, { title: '账号', items: [ { label: '就诊人管理', icon: '家', bg: 'pri-l', color: 'pri', path: '/pages/pkg-profile/family/index' }, { label: '长辈模式', icon: '老', bg: 'acc-l', color: 'acc', path: '/pages/pkg-profile/elder-mode/index' }, { label: '设备同步', icon: '设', bg: 'surface-alt', color: 'tx3', path: '/pages/device-sync/index' }, { label: '设置', icon: '齿', bg: 'surface-alt', color: 'tx3', path: '/pages/pkg-profile/settings/index' }, ], }, ]; const GUEST_GROUPS: MenuGroup[] = [ { title: '设置', items: [ { label: '长辈模式', icon: '老', bg: 'acc-l', color: 'acc', path: '/pages/pkg-profile/elder-mode/index' }, { label: '设置', icon: '齿', bg: 'surface-alt', color: 'tx3', path: '/pages/pkg-profile/settings/index' }, ], }, ]; export default function Profile() { const { user, logout } = useAuthStore(); const { account: pointsAccount, checkinStatus: checkinInfo, refresh: refreshPoints } = usePointsStore(); const mode = useUIStore((s) => s.mode); const modeClass = mode === 'elder' ? 'elder-mode' : ''; const isGuest = !user; const groups = isGuest ? GUEST_GROUPS : LOGGED_IN_GROUPS; useDidShow(() => { if (!isGuest) refreshPoints(); }); const handleMenuClick = (item: MenuItem) => { if (item.isSwitchTab) { Taro.switchTab({ url: item.path }); } else { Taro.navigateTo({ url: item.path }); } }; const handleLogout = () => { Taro.showModal({ title: '退出登录', content: '确定要退出登录吗?', }).then((res) => { if (res.confirm) { logout(); } }); }; const displayName = user?.display_name || user?.username || (user?.phone ? `${user.phone.slice(-4)}` : '') || '用户'; const displayInitial = (user?.display_name || user?.username || '用').charAt(0); return ( {/* 用户信息卡片 */} {isGuest ? ( ? 未登录 点击登录,开启健康管理之旅 ) : ( <> {displayInitial} {displayName} {user?.phone ? `${user.phone.slice(0, 3)}****${user.phone.slice(-4)}` : ''} {/* 积分 + 打卡 */} {(pointsAccount?.balance ?? 0).toLocaleString()} 健康积分 {checkinInfo?.consecutive_days ?? 0} 连续打卡 )} {/* 分组菜单 */} {groups.map((group) => ( {group.title} {group.items.map((item, idx) => ( handleMenuClick(item)} > {item.icon} {item.label} {idx < group.items.length - 1 && } ))} ))} {/* 退出登录 / 登录 */} {isGuest ? ( 登录账号 ) : ( 退出登录 )} ); }