import { View, Text, Button, Image } from '@tarojs/components' import { useLoad, useDidShow } from '@tarojs/taro' import { useState } from 'react' import Taro from '@tarojs/taro' import { authManager, User } from '../../utils/auth' import './index.css' export default function Index() { const [user, setUser] = useState(null) const [loading, setLoading] = useState(false) useLoad(() => { console.log('Index Page loaded.') checkLoginStatus() }) useDidShow(() => { checkLoginStatus() }) const checkLoginStatus = async () => { if (authManager.isLoggedIn()) { const userInfo = authManager.getUserInfo() setUser(userInfo) } else { setUser(null) } } const handleLogin = () => { Taro.navigateTo({ url: '/pages/login/index' }) } const handleLogout = async () => { setLoading(true) try { await authManager.logout() setUser(null) Taro.showToast({ title: '退出成功', icon: 'success' }) } catch (error) { console.error('Logout error:', error) } finally { setLoading(false) } } const handleProfile = () => { Taro.navigateTo({ url: '/pages/profile/index' }) } const goToRegister = () => { Taro.navigateTo({ url: '/pages/register/index' }) } return ( {user ? ( 欢迎回来 {user.username} 用户ID {user.id} {user.email && ( 邮箱 {user.email} )} 注册时间 {new Date(user.createdAt).toLocaleDateString()} 1 今日访问 7 本周活跃 30 本月使用 ) : ( 欢迎使用小程序 请先登录以使用完整功能 功能特色 🔒 安全认证 多重加密保护账户安全 👤 用户管理 完整的用户信息管理 📱 响应式设计 完美适配各种设备 实时同步 数据实时更新同步 )} ) }