Skip to content

Commit e855dd5

Browse files
committed
refactor: 最小化版本 - 移除引导页,直接显示首页
1 parent 5e64a3d commit e855dd5

1 file changed

Lines changed: 58 additions & 85 deletions

File tree

src/App.tsx

Lines changed: 58 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -1,118 +1,91 @@
11
/**
2-
* HumanOS - App 主组件
3-
* 重构:确保首次访问和再次访问都能正确显示首页
2+
* HumanOS - 最小化版本
3+
* 先确保首页正常显示,再逐步添加引导动画
44
*/
55

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'
98
import Layout from '@components/Layout'
109
import Home from '@pages/Home'
1110
import Assessment from '@pages/Assessment'
1211
import Results from '@pages/Results'
1312
import Dashboard from '@pages/Dashboard'
1413
import About from '@pages/About'
1514
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'
1915

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)
2519

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+
// 检查是否首次访问
2747
useEffect(() => {
2848
const hasVisited = localStorage.getItem('human-os-visited')
2949
if (hasVisited) {
30-
// 曾经访问过,直接进入 Splash 动画
31-
setIsFirstVisit(false)
32-
setAppState('splash')
50+
// 曾访问过,直接进入
51+
setShowSplash(false)
3352
} else {
34-
// 首次访问,显示引导页
35-
setIsFirstVisit(true)
36-
setAppState('intro')
53+
// 首次访问,标记已访问
54+
localStorage.setItem('human-os-visited', 'true')
3755
}
3856
}, [])
3957

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+
}
5362

54-
// 加载中状态
55-
if (appState === 'loading' || isFirstVisit === null) {
63+
// 加载中
64+
if (isLoading) {
5665
return (
5766
<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" />
7068
</div>
7169
)
7270
}
7371

74-
// 首次访问:显示引导页
75-
if (appState === 'intro') {
76-
return (
77-
<Intro onEnter={handleIntroComplete} />
78-
)
72+
// 启动屏阶段
73+
if (showSplash) {
74+
return <SimpleSplash onComplete={handleSplashComplete} />
7975
}
8076

81-
// 启动动画阶段
82-
if (appState === 'splash') {
83-
return (
84-
<SplashScreen
85-
onComplete={handleSplashComplete}
86-
minDuration={3000}
87-
/>
88-
)
89-
}
90-
91-
// 主页就绪:显示完整应用
77+
// 正常显示应用
9278
return (
9379
<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>
11489
</Layout>
11590
)
11691
}
117-
118-
export default App

0 commit comments

Comments
 (0)