import { View, Text, Button, Image } from '@tarojs/components'
import { useDidShow } from '@tarojs/taro'
import { useState } from 'react'
import Taro from '@tarojs/taro'
import './index.css'
import { useAuth } from '@/utils/auth'
export default function Index() {
const { user, isLoading, logout } = useAuth()
const [logoutLoading, setLogoutLoading] = useState(false)
useDidShow(() => {
// 用户状态由useAuth自动管理,无需手动检查
console.log('页面显示,当前用户状态:', user ? '已登录' : '未登录')
})
const handleLogin = () => {
Taro.navigateTo({ url: '/pages/login/index' })
}
const handleLogout = async () => {
setLogoutLoading(true)
try {
await logout()
// 退出成功后,useAuth会自动更新user状态
Taro.showToast({
title: '退出成功',
icon: 'success'
})
} catch (error) {
console.error('Logout error:', error)
} finally {
setLogoutLoading(false)
}
}
const handleProfile = () => {
Taro.navigateTo({ url: '/pages/profile/index' })
}
const goToRegister = () => {
Taro.navigateTo({ url: '/pages/register/index' })
}
// 显示加载状态
if (isLoading) {
return (
加载中...
)
}
return (
{user ? (
欢迎回来
{user.username}
用户ID
{user.id}
{user.email && (
邮箱
{user.email}
)}
注册时间
{new Date(user.createdAt).toLocaleDateString()}
1
今日访问
7
本周活跃
30
本月使用
) : (
欢迎使用小程序444
请先登录以使用完整功能
功能特色
安全认证
多重加密保护账户安全
👤
用户管理
完整的用户信息管理
📱
响应式设计
完美适配各种设备
⚡
实时同步
数据实时更新同步
)}
)
}