import React from 'react'; import { Routes, Route, useParams, useNavigate } from 'react-router-dom'; import { observer } from 'mobx-react-lite'; import styled from 'styled-components'; import { useAuthStore } from './stores/AuthStore'; import { useUserStore } from './stores/UserStore'; import { useRegionStore } from './stores/RegionStore'; import Layout from './components/common/Layout'; import Loading from './components/common/Loading'; import ChinaMap from './components/common/ChinaMap'; import CitiesPage from './components/region/CitiesPage'; import CityDetailPage from './components/region/CityDetailPage'; import ArticleDetailPage from './components/article/ArticleDetailPage'; import ServiceDetailPage from './components/service/ServiceDetailPage'; import LoginPage from './components/auth/LoginPage'; import RegisterPage from './components/auth/RegisterPage'; const Container = styled.div` max-width: 1200px; margin: 0 auto; padding: 20px; `; const Header = styled.header` margin-bottom: 30px; padding-bottom: 20px; border-bottom: 2px solid #eee; `; const Title = styled.h1` margin: 0; font-size: 28px; `; function App() { const authStore = useAuthStore(); // Fetch current user on app load React.useEffect(() => { if (authStore.isAuthenticated) { authStore.fetchCurrentUser(); } }, [authStore]); return ( } /> } /> } /> } /> } /> } /> } /> } /> } /> ); } const ArticleDetailPageWrapper = observer(() => { const { articleId } = useParams(); return ; }); const ServiceDetailPageWrapper = observer(() => { const { serviceId } = useParams(); return ; }); const HomePage = observer(() => { const navigate = useNavigate(); const regionStore = useRegionStore(); const [loading, setLoading] = React.useState(false); const handleProvinceClick = async (geo) => { const provinceName = geo.properties.name; const provinceCode = geo.properties.code; setLoading(true); try { // 先获取所有省份列表,找到对应的 region ID await regionStore.fetchProvinces(); const province = regionStore.regions.find( r => r.name === provinceName || r.code === provinceCode ); if (province) { navigate(`/cities/${province.id}`); } else { // 如果没有找到,跳转到城市列表页并带上省份名称 navigate(`/cities?province=${encodeURIComponent(provinceName)}`); } } catch (error) { console.error('Failed to navigate to province:', error); } finally { setLoading(false); } }; return (
欢迎来到城市手册

探索每个城市的故事与特色

{loading ? ( ) : ( )}

📚 最新文章

即将推出...

); }); const UserProfilePage = observer(() => { const authStore = useAuthStore(); const userStore = useUserStore(); React.useEffect(() => { if (authStore.isAuthenticated) { userStore.fetchCurrentUser(); } }, [authStore, userStore]); if (!authStore.isAuthenticated) { return (

请先登录

); } if (userStore.loading) { return ; } return (
个人中心
{userStore.user && (

用户信息

用户名: {userStore.user.username}

邮箱: {userStore.user.email}

角色: {userStore.user.role_display}

统计

文章数: {userStore.user.articles_count}

服务数: {userStore.user.services_count}

评论数: {userStore.user.comments_count}

点赞数: {userStore.user.likes_count}

收藏数: {userStore.user.favorites_count}

)}
); }); const NotFoundPage = () => (
404

页面未找到

); export default App;