import { useState, useEffect } from 'react' import { View, Text, ScrollView } from '@tarojs/components' import Taro from '@tarojs/taro' import { TabBarLayout } from '@/layouts/tab-bar-layout' import { useAuth , type User as UserProfile} from '@/utils/auth' import { cn } from '@/utils/cn' import { Button } from '@/components/ui/button' import { Image } from '@/components/ui/image' import { Navbar } from '@/components/ui/navbar' import { AvatarUpload } from '@/components/ui/avatar-upload' import { uploadFromChoose, type UploadResult } from '@/utils/minio' import './index.css' const ProfilePage: React.FC = () => { const { user: userProfile, logout, isLoading: loading, updateUser } = useAuth() const [updatingAvatar, setUpdatingAvatar] = useState(false) const handleLogout = async () => { try { Taro.showModal({ title: '退出登录', content: '确定要退出登录吗?', success: async (res) => { if (res.confirm) { Taro.showLoading({ title: '退出中...' }) await logout() Taro.hideLoading() Taro.showToast({ title: '已退出登录', icon: 'success', duration: 1500 }) setTimeout(() => { Taro.reLaunch({ url: '/pages/index/index' }) }, 1500) } } }) } catch (error) { Taro.hideLoading() Taro.showToast({ title: '退出失败,请重试', icon: 'none' }) } } const handleAvatarUpload = async (result: UploadResult) => { try { setUpdatingAvatar(true) Taro.showLoading({ title: '更新头像...' }) // 这里应该调用更新用户头像的API // 假设有一个更新用户信息的API console.log('头像上传成功:', result) // 更新本地用户数据 if (userProfile) { const updatedUser = { ...userProfile, avatarFile: { ...userProfile.avatarFile, fullUrl: result.fileUrl } } updateUser(updatedUser) } Taro.hideLoading() Taro.showToast({ title: '头像更新成功', icon: 'success' }) } catch (error) { console.error('更新头像失败:', error) Taro.hideLoading() Taro.showToast({ title: '更新头像失败', icon: 'none' }) } finally { setUpdatingAvatar(false) } } const handleAvatarUploadError = (error: Error) => { console.error('头像上传失败:', error) Taro.showToast({ title: '上传失败,请重试', icon: 'none' }) } const handleEditProfile = () => { Taro.showToast({ title: '功能开发中...', icon: 'none' }) } const handleSettings = () => { Taro.showToast({ title: '功能开发中...', icon: 'none' }) } const menuItems = [ { icon: 'i-heroicons-user-circle-20-solid', title: '编辑资料', onClick: handleEditProfile, color: 'text-blue-500' }, { icon: 'i-heroicons-cog-6-tooth-20-solid', title: '设置', onClick: handleSettings, color: 'text-gray-500' }, { icon: 'i-heroicons-shield-check-20-solid', title: '隐私政策', onClick: () => Taro.showToast({ title: '功能开发中...', icon: 'none' }), color: 'text-green-500' }, { icon: 'i-heroicons-question-mark-circle-20-solid', title: '帮助与反馈', onClick: () => Taro.showToast({ title: '功能开发中...', icon: 'none' }), color: 'text-purple-500' } ] if (loading) { return ( ) } if (!userProfile) { return ( 请先登录 ) } return ( {/* 用户信息卡片 */} {userProfile.username} {userProfile.email && ( {userProfile.email} )} 注册于 {new Date(userProfile.createdAt).toLocaleDateString('zh-CN')} {/* 统计信息 */} 0 收藏 0 点赞 0 关注 {/* 功能菜单 */} {menuItems.map((item, index) => ( {item.title} ))} {/* 账号信息 */} 账号信息 用户ID {userProfile.id} {userProfile.updatedAt && ( 最近登录 {new Date(userProfile.updatedAt).toLocaleString('zh-CN')} )} {/* 退出登录按钮 */} {/* 版本信息 */} v1.0.0 - 小程序版 ) } export default ProfilePage