|
1 | 1 | /** |
2 | | - * HumanOS - App 主组件 |
3 | | - * 重构:确保首次访问和再次访问都能正确显示首页 |
| 2 | + * HumanOS - 最小化版本 |
| 3 | + * 先确保首页正常显示,再逐步添加引导动画 |
4 | 4 | */ |
5 | 5 |
|
6 | | -import { useState, useEffect, useCallback } from 'react' |
7 | | -import { Routes, Route, useLocation } from 'react-router-dom' |
8 | | -import { AnimatePresence, motion } from 'framer-motion' |
| 6 | +import { useState, useEffect } from 'react' |
| 7 | +import { Routes, Route } from 'react-router-dom' |
9 | 8 | import Layout from '@components/Layout' |
10 | 9 | import Home from '@pages/Home' |
11 | 10 | import Assessment from '@pages/Assessment' |
12 | 11 | import Results from '@pages/Results' |
13 | 12 | import Dashboard from '@pages/Dashboard' |
14 | 13 | import About from '@pages/About' |
15 | 14 | import NotFound from '@pages/NotFound' |
16 | | -import Intro from '@pages/Intro' |
17 | | -import SplashScreen from '@components/animations/SplashScreen' |
18 | | -import { pageVariants } from '@utils/animation-config' |
19 | 15 |
|
20 | | -function App() { |
21 | | - const location = useLocation() |
22 | | - // appState: 'loading' = 加载中, 'intro' = 首次引导页, 'splash' = 启动动画, 'ready' = 主页就绪 |
23 | | - const [appState, setAppState] = useState<'loading' | 'intro' | 'splash' | 'ready'>('loading') |
24 | | - const [isFirstVisit, setIsFirstVisit] = useState<boolean | null>(null) |
| 16 | +// 简单的启动屏组件 |
| 17 | +function SimpleSplash({ onComplete }: { onComplete: () => void }) { |
| 18 | + const [progress, setProgress] = useState(0) |
25 | 19 |
|
26 | | - // 初始化:检查是否首次访问 |
| 20 | + useEffect(() => { |
| 21 | + // 2秒后自动进入首页 |
| 22 | + const timer = setTimeout(() => { |
| 23 | + onComplete() |
| 24 | + }, 2000) |
| 25 | + return () => clearTimeout(timer) |
| 26 | + }, [onComplete]) |
| 27 | + |
| 28 | + return ( |
| 29 | + <div className="fixed inset-0 bg-slate-950 flex flex-col items-center justify-center z-[100]"> |
| 30 | + <div className="text-center"> |
| 31 | + {/* Logo 动画 */} |
| 32 | + <div className="w-20 h-20 mx-auto mb-8 rounded-2xl bg-gradient-to-br from-violet-500 via-pink-500 to-orange-500 animate-pulse" /> |
| 33 | + |
| 34 | + {/* 文字 */} |
| 35 | + <h1 className="text-3xl font-bold text-gradient mb-4">HumanOS</h1> |
| 36 | + <p className="text-white/50 text-sm">正在加载...</p> |
| 37 | + </div> |
| 38 | + </div> |
| 39 | + ) |
| 40 | +} |
| 41 | + |
| 42 | +export default function App() { |
| 43 | + const [isLoading, setIsLoading] = useState(true) |
| 44 | + const [showSplash, setShowSplash] = useState(true) |
| 45 | + |
| 46 | + // 检查是否首次访问 |
27 | 47 | useEffect(() => { |
28 | 48 | const hasVisited = localStorage.getItem('human-os-visited') |
29 | 49 | if (hasVisited) { |
30 | | - // 曾经访问过,直接进入 Splash 动画 |
31 | | - setIsFirstVisit(false) |
32 | | - setAppState('splash') |
| 50 | + // 曾访问过,直接进入 |
| 51 | + setShowSplash(false) |
33 | 52 | } else { |
34 | | - // 首次访问,显示引导页 |
35 | | - setIsFirstVisit(true) |
36 | | - setAppState('intro') |
| 53 | + // 首次访问,标记已访问 |
| 54 | + localStorage.setItem('human-os-visited', 'true') |
37 | 55 | } |
38 | 56 | }, []) |
39 | 57 |
|
40 | | - // 处理引导页完成 |
41 | | - const handleIntroComplete = useCallback(() => { |
42 | | - // 标记为已访问 |
43 | | - localStorage.setItem('human-os-visited', 'true') |
44 | | - setIsFirstVisit(false) |
45 | | - // 进入启动动画 |
46 | | - setAppState('splash') |
47 | | - }, []) |
48 | | - |
49 | | - // 处理启动动画完成 |
50 | | - const handleSplashComplete = useCallback(() => { |
51 | | - setAppState('ready') |
52 | | - }, []) |
| 58 | + // 处理启动屏完成 |
| 59 | + const handleSplashComplete = () => { |
| 60 | + setShowSplash(false) |
| 61 | + } |
53 | 62 |
|
54 | | - // 加载中状态 |
55 | | - if (appState === 'loading' || isFirstVisit === null) { |
| 63 | + // 加载中 |
| 64 | + if (isLoading) { |
56 | 65 | return ( |
57 | 66 | <div className="fixed inset-0 bg-slate-950 flex items-center justify-center"> |
58 | | - <motion.div |
59 | | - className="w-12 h-12 rounded-xl bg-gradient-to-br from-violet-500 to-pink-500" |
60 | | - animate={{ |
61 | | - scale: [1, 1.2, 1], |
62 | | - rotate: [0, 180, 360], |
63 | | - }} |
64 | | - transition={{ |
65 | | - duration: 2, |
66 | | - repeat: Infinity, |
67 | | - ease: 'easeInOut', |
68 | | - }} |
69 | | - /> |
| 67 | + <div className="w-10 h-10 rounded-xl bg-gradient-to-br from-violet-500 to-pink-500 animate-pulse" /> |
70 | 68 | </div> |
71 | 69 | ) |
72 | 70 | } |
73 | 71 |
|
74 | | - // 首次访问:显示引导页 |
75 | | - if (appState === 'intro') { |
76 | | - return ( |
77 | | - <Intro onEnter={handleIntroComplete} /> |
78 | | - ) |
| 72 | + // 启动屏阶段 |
| 73 | + if (showSplash) { |
| 74 | + return <SimpleSplash onComplete={handleSplashComplete} /> |
79 | 75 | } |
80 | 76 |
|
81 | | - // 启动动画阶段 |
82 | | - if (appState === 'splash') { |
83 | | - return ( |
84 | | - <SplashScreen |
85 | | - onComplete={handleSplashComplete} |
86 | | - minDuration={3000} |
87 | | - /> |
88 | | - ) |
89 | | - } |
90 | | - |
91 | | - // 主页就绪:显示完整应用 |
| 77 | + // 正常显示应用 |
92 | 78 | return ( |
93 | 79 | <Layout> |
94 | | - <AnimatePresence mode="wait"> |
95 | | - <motion.div |
96 | | - key={location.pathname} |
97 | | - variants={pageVariants} |
98 | | - initial="initial" |
99 | | - animate="enter" |
100 | | - exit="exit" |
101 | | - className="min-h-screen" |
102 | | - > |
103 | | - <Routes location={location}> |
104 | | - <Route path="/" element={<Home />} /> |
105 | | - <Route path="/home" element={<Home />} /> |
106 | | - <Route path="/assessment/:id" element={<Assessment />} /> |
107 | | - <Route path="/results/:id" element={<Results />} /> |
108 | | - <Route path="/dashboard" element={<Dashboard />} /> |
109 | | - <Route path="/about" element={<About />} /> |
110 | | - <Route path="*" element={<NotFound />} /> |
111 | | - </Routes> |
112 | | - </motion.div> |
113 | | - </AnimatePresence> |
| 80 | + <Routes> |
| 81 | + <Route path="/" element={<Home />} /> |
| 82 | + <Route path="/home" element={<Home />} /> |
| 83 | + <Route path="/assessment/:id" element={<Assessment />} /> |
| 84 | + <Route path="/results/:id" element={<Results />} /> |
| 85 | + <Route path="/dashboard" element={<Dashboard />} /> |
| 86 | + <Route path="/about" element={<About />} /> |
| 87 | + <Route path="*" element={<NotFound />} /> |
| 88 | + </Routes> |
114 | 89 | </Layout> |
115 | 90 | ) |
116 | 91 | } |
117 | | - |
118 | | -export default App |
0 commit comments