import React, { useState, useEffect } from 'react'; import { checkinService } from '../services/api'; import CheckinForm from '../components/CheckinForm'; import CheckinList from '../components/CheckinList'; import MapView from '../components/MapView'; const HomePage = ({ user }) => { const [checkins, setCheckins] = useState([]); const [stats, setStats] = useState(null); const [loading, setLoading] = useState(true); const [view, setView] = useState('list'); // 'list' or 'map' useEffect(() => { loadCheckins(); loadStats(); }, []); const loadCheckins = async () => { try { const response = await checkinService.getAll({ limit: 100 }); setCheckins(response.data.checkins); } catch (error) { console.error('加载打卡记录失败:', error); } finally { setLoading(false); } }; const loadStats = async () => { try { const response = await checkinService.getStats(); setStats(response.data.stats); } catch (error) { console.error('加载统计信息失败:', error); } }; const handleCheckinSuccess = (newCheckin) => { setCheckins([newCheckin, ...checkins]); loadStats(); }; return (
{/* 头部 */}

📍 Footprint

你好, {user.username}

{stats && (

总打卡: {stats.total_checkins}

打卡天数: {stats.total_days}

)}
{/* 主内容 */}
{/* 左侧:打卡表单 */}
{/* 右侧:打卡记录或地图 */}
{/* 视图切换 */}

我的足迹

{/* 内容区域 */} {loading ? (

加载中...

) : view === 'list' ? ( ) : ( )}
); }; export default HomePage;