Skip to content

Commit 3cebe84

Browse files
committed
feat: 添加主应用组件和静态资源
1 parent 249789f commit 3cebe84

File tree

4 files changed

+160
-0
lines changed

4 files changed

+160
-0
lines changed

src/App.css

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
.app {
2+
display: flex;
3+
flex-direction: column;
4+
height: 100vh;
5+
width: 100vw;
6+
overflow: hidden;
7+
}
8+
9+
.main-content {
10+
flex: 1;
11+
display: flex;
12+
gap: var(--spacing-md);
13+
padding: var(--spacing-md) var(--spacing-lg);
14+
min-height: 0;
15+
overflow: hidden;
16+
}
17+
18+
.left-panel {
19+
width: 400px;
20+
flex-shrink: 0;
21+
display: flex;
22+
flex-direction: column;
23+
}
24+
25+
.right-panel {
26+
flex: 1;
27+
display: flex;
28+
flex-direction: column;
29+
min-width: 0;
30+
}
31+
32+
/* 响应式布局 */
33+
@media (max-width: 1200px) {
34+
.main-content {
35+
flex-direction: column;
36+
}
37+
38+
.left-panel {
39+
width: 100%;
40+
height: 300px;
41+
}
42+
43+
.right-panel {
44+
flex: 1;
45+
}
46+
}

src/App.tsx

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
import { useState, useEffect, useCallback } from 'react';
2+
import {
3+
Header,
4+
DataInput,
5+
CodePanel,
6+
Canvas,
7+
ControlPanel,
8+
AlgorithmIdeaModal,
9+
WeChatFloat,
10+
} from './components';
11+
import { useAlgorithmPlayer } from './hooks';
12+
import type { AlgorithmType } from './types';
13+
import { DATA_EXAMPLES } from './utils/validation';
14+
import './styles/global.css';
15+
import './App.css';
16+
17+
function App() {
18+
const [data, setData] = useState<number[]>(DATA_EXAMPLES[0].data);
19+
const [algorithmType, setAlgorithmType] = useState<AlgorithmType>('dp');
20+
const [showAlgorithmIdea, setShowAlgorithmIdea] = useState(false);
21+
22+
const {
23+
steps,
24+
currentStep,
25+
currentStepData,
26+
isPlaying,
27+
speed,
28+
play,
29+
pause,
30+
nextStep,
31+
prevStep,
32+
reset,
33+
seek,
34+
setSpeed,
35+
generateSteps,
36+
} = useAlgorithmPlayer();
37+
38+
// 初始化生成步骤
39+
useEffect(() => {
40+
generateSteps(data, algorithmType);
41+
}, [data, algorithmType, generateSteps]);
42+
43+
// 处理数据变化
44+
const handleDataChange = useCallback((newData: number[]) => {
45+
setData(newData);
46+
}, []);
47+
48+
// 处理算法类型变化
49+
const handleAlgorithmTypeChange = useCallback((type: AlgorithmType) => {
50+
setAlgorithmType(type);
51+
}, []);
52+
53+
return (
54+
<div className="app">
55+
<Header onShowAlgorithmIdea={() => setShowAlgorithmIdea(true)} />
56+
57+
<DataInput
58+
onDataChange={handleDataChange}
59+
currentData={data}
60+
algorithmType={algorithmType}
61+
onAlgorithmTypeChange={handleAlgorithmTypeChange}
62+
/>
63+
64+
<main className="main-content">
65+
<div className="left-panel">
66+
<CodePanel
67+
currentStep={currentStepData}
68+
algorithmType={algorithmType}
69+
/>
70+
</div>
71+
72+
<div className="right-panel">
73+
<Canvas
74+
currentStep={currentStepData}
75+
algorithmType={algorithmType}
76+
data={data}
77+
/>
78+
</div>
79+
</main>
80+
81+
<ControlPanel
82+
currentStep={currentStep}
83+
totalSteps={steps.length}
84+
isPlaying={isPlaying}
85+
onPlay={play}
86+
onPause={pause}
87+
onPrevStep={prevStep}
88+
onNextStep={nextStep}
89+
onReset={reset}
90+
onSeek={seek}
91+
speed={speed}
92+
onSpeedChange={setSpeed}
93+
/>
94+
95+
<AlgorithmIdeaModal
96+
isOpen={showAlgorithmIdea}
97+
onClose={() => setShowAlgorithmIdea(false)}
98+
/>
99+
100+
<WeChatFloat />
101+
</div>
102+
);
103+
}
104+
105+
export default App;

src/assets/images/wechat-group.png

328 KB
Loading

src/main.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { StrictMode } from 'react'
2+
import { createRoot } from 'react-dom/client'
3+
import App from './App.tsx'
4+
5+
createRoot(document.getElementById('root')!).render(
6+
<StrictMode>
7+
<App />
8+
</StrictMode>,
9+
)

0 commit comments

Comments
 (0)