Skip to content

Commit f1c2d99

Browse files
committed
fix: 修复lint错误和类型问题
1 parent 2a439ef commit f1c2d99

22 files changed

+131
-62
lines changed

src/algorithms/dpAlgorithm.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,16 @@ export interface DPAnimationState {
66
currentStep: number;
77
}
88

9-
// 为每个步骤添加多层次的解释
10-
interface StepExplanation {
9+
// 为每个步骤添加多层次的解释(用于类型定义)
10+
interface _StepExplanation {
1111
simple: string;
1212
detailed: string;
1313
expert: string;
1414
}
1515

16+
// 导出类型以供其他模块使用
17+
export type StepExplanation = _StepExplanation;
18+
1619
/**
1720
* 使用动态规划算法生成爬楼梯问题的解和动画时间线
1821
* @param n 楼梯的阶数

src/components/CanvasComponent.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ const CanvasComponent: React.FC<CanvasComponentProps> = ({ state, width, height
8282

8383
// 添加步骤描述背景和文本 - 新增内容
8484
const stepDesc = state.timeline[state.currentStep]?.description || "";
85-
const stepBackground = stepDescGroup.append('rect')
85+
stepDescGroup.append('rect')
8686
.attr('x', 0)
8787
.attr('y', 10)
8888
.attr('width', dimensions.width)
@@ -238,7 +238,7 @@ const CanvasComponent: React.FC<CanvasComponentProps> = ({ state, width, height
238238

239239
// 渲染公式 - 增强显示
240240
if (state.formula) {
241-
const formulaBackground = formulaGroup.append('rect')
241+
formulaGroup.append('rect')
242242
.attr('x', innerWidth - 220)
243243
.attr('y', -20)
244244
.attr('width', 200)
@@ -274,7 +274,7 @@ const CanvasComponent: React.FC<CanvasComponentProps> = ({ state, width, height
274274

275275
// 渲染矩阵(仅当使用矩阵算法时)
276276
if (state.currentAlgorithm === 'matrix' && state.matrix.length > 0) {
277-
renderMatrix(g, state.matrix, innerWidth, innerHeight);
277+
renderMatrix(g, state.matrix, innerWidth);
278278
}
279279

280280
}, [state.staircase, state.currentAlgorithm, state.formula, state.matrix, dimensions, state.currentStep, state.timeline, state.totalSteps]);
@@ -317,8 +317,7 @@ const CanvasComponent: React.FC<CanvasComponentProps> = ({ state, width, height
317317
const renderMatrix = (
318318
g: d3.Selection<SVGGElement, unknown, null, undefined>,
319319
matrix: number[][],
320-
width: number,
321-
height: number
320+
width: number
322321
) => {
323322
const matrixGroup = g.append('g')
324323
.attr('class', 'matrix')

src/components/ControlPanel.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010

1111
interface ControlPanelProps {
1212
state: AnimationState;
13-
dispatch: (action: any) => void; // Redux dispatch 函数
13+
dispatch: React.Dispatch<ReturnType<typeof playPause | typeof resetAnimation | typeof setAlgorithm | typeof setCurrentStep | typeof setPlaybackSpeed>>;
1414
}
1515

1616
const ControlPanel: React.FC<ControlPanelProps> = ({ state, dispatch }) => {

src/components/FormulaVisualizer.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,16 @@ interface FormulaVisualizerProps {
369369
// 通项公式可视化组件
370370
const FormulaVisualizer: React.FC<FormulaVisualizerProps> = ({ n, state, currentTimeline }) => {
371371
const [detailLevel, setDetailLevel] = useState<'simple' | 'detailed' | 'expert'>('simple');
372-
const [chartData, setChartData] = useState<any>(null);
372+
const [chartData, setChartData] = useState<{
373+
labels: string[];
374+
datasets: {
375+
label: string;
376+
data: number[];
377+
borderColor: string;
378+
backgroundColor: string;
379+
tension: number;
380+
}[];
381+
} | null>(null);
373382

374383
// 黄金比例常数
375384
const PHI = (1 + Math.sqrt(5)) / 2; // 约等于1.618...

src/components/StairsComponent.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,8 @@ const PathArrow = styled.div<{ type: 'one' | 'two' }>`
246246
}
247247
`;
248248

249-
// 单独定义Float动画组件
250-
const floatAnimation = (index: number, totalSteps: number) => {
249+
// 单独定义Float动画组件(保留以备将来使用)
250+
const _floatAnimation = (index: number, totalSteps: number) => {
251251
const baseY = -index * (totalSteps <= 5 ? 60 : totalSteps <= 10 ? 50 : 40);
252252
const baseZ = index * 2;
253253

@@ -259,6 +259,9 @@ const floatAnimation = (index: number, totalSteps: number) => {
259259
`;
260260
};
261261

262+
// 导出以供其他模块使用
263+
export { _floatAnimation as floatAnimation };
264+
262265
interface StairsComponentProps {
263266
n: number;
264267
currentStep: number;

src/components/StepExplanation.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ const StepExplanation: React.FC<StepExplanationProps> = ({
6464
code,
6565
formula
6666
}) => {
67+
// 保留totalSteps以备将来使用
68+
void totalSteps;
6769
return (
6870
<ExplanationContainer>
6971
<StepTitle>

src/components/dp/AnimatedClimber.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ const AnimatedClimber: React.FC<AnimatedClimberProps> = ({
4545
const [animationProgress, setAnimationProgress] = useState(0); // 动画进度 0-1
4646
const [animationStartTime, setAnimationStartTime] = useState(0); // 动画开始时间
4747
const [climberPathPoints, setClimberPathPoints] = useState<{x: number, y: number}[]>([]); // 小人移动路径点
48+
// 保留setClimberPathPoints以备将来使用
49+
void setClimberPathPoints;
4850

4951
const canvasRef = useRef<HTMLCanvasElement>(null);
5052
const forceRender = useRef<number>(0); // 强制渲染引用

src/components/dp/PathDiagramComponent.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ import {
1616
import { useClimberPosition } from './hooks/useClimberPosition';
1717

1818
const PathDiagramComponent: React.FC<PathDiagramProps> = ({ n, state, currentTimeline }) => {
19-
if (!state.values || state.values.length === 0) return null;
20-
21-
// 使用钩子获取小人位置和状态
19+
// 使用钩子获取小人位置和状态 - 必须在条件返回之前调用
2220
const { climberPosition, climberEmoji, actionText, currentCalcIndex } = useClimberPosition(state, currentTimeline);
23-
console.log('PathDiagram渲染, 当前计算阶梯:', currentCalcIndex);
2421

2522
// 创建要显示的楼梯步骤
2623
const stepsToShow = useMemo(() => {
24+
// 如果没有值数据,返回空数组
25+
if (!state.values || state.values.length === 0) return [];
26+
2727
const steps = [];
2828
const maxStepsToShow = Math.min(n, 6); // 限制显示的最大阶梯数
2929

@@ -100,6 +100,9 @@ const PathDiagramComponent: React.FC<PathDiagramProps> = ({ n, state, currentTim
100100
return steps;
101101
}, [n, state.values, state.stepStatuses, currentCalcIndex, climberPosition, actionText]);
102102

103+
// 如果没有值数据,返回null
104+
if (!state.values || state.values.length === 0) return null;
105+
103106
return (
104107
<PathDiagram>
105108
<GuideTitle>

src/components/dp/SimpleDPVisualizer.tsx

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { useEffect, useState, useRef } from 'react';
2-
import { setAnimationState } from '../../state/animationSlice';
2+
import { setAnimationState, AnimationState, AnimationTimeline } from '../../state/animationSlice';
33
import { generateDPSolution } from '../../algorithms/dpAlgorithm';
44
import AnimatedClimber from './AnimatedClimber';
55
import styled from 'styled-components';
@@ -15,11 +15,20 @@ import {
1515
ExplanationPanel
1616
} from './styles/layout';
1717

18+
interface DPSolutionData {
19+
result: number;
20+
timeline: AnimationTimeline[];
21+
stepsData?: {
22+
stepStatuses: ('uncalculated' | 'calculating' | 'calculated')[];
23+
values: number[];
24+
};
25+
}
26+
1827
interface SimpleDPVisualizerProps {
1928
n: number;
20-
state: any;
21-
onGenerateSolution: (data: any) => void;
22-
dispatch: (action: any) => void;
29+
state: AnimationState;
30+
onGenerateSolution: (data: DPSolutionData) => void;
31+
dispatch: React.Dispatch<ReturnType<typeof setAnimationState> | { type: string; payload?: unknown }>;
2332
}
2433

2534
const SimpleDPVisualizer: React.FC<SimpleDPVisualizerProps> = ({

src/components/dp/characters/ShadiaoCharacter.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -365,20 +365,20 @@ export class ShadiaoCharacter {
365365
// 绘制星星
366366
private drawStar(ctx: CanvasRenderingContext2D, cx: number, cy: number, size: number, spikes: number): void {
367367
let rot = Math.PI / 2 * 3;
368-
let step = Math.PI / spikes;
368+
const stepAngle = Math.PI / spikes;
369369
ctx.beginPath();
370370
ctx.moveTo(cx, cy - size);
371371

372372
for (let i = 0; i < spikes; i++) {
373373
let x = cx + Math.cos(rot) * size;
374374
let y = cy + Math.sin(rot) * size;
375375
ctx.lineTo(x, y);
376-
rot += step;
376+
rot += stepAngle;
377377

378378
x = cx + Math.cos(rot) * size * 0.4;
379379
y = cy + Math.sin(rot) * size * 0.4;
380380
ctx.lineTo(x, y);
381-
rot += step;
381+
rot += stepAngle;
382382
}
383383

384384
ctx.lineTo(cx, cy - size);
@@ -468,22 +468,24 @@ export class ShadiaoCharacter {
468468

469469
// 根据状态调整四肢
470470
switch (mode) {
471-
case 'climbing':
471+
case 'climbing': {
472472
// 爬楼梯时手脚乱动
473473
const progress = this.animationProgress;
474474
leftArmAngle = -Math.PI/3 - Math.sin(progress * Math.PI) * Math.PI/4;
475475
rightArmAngle = Math.PI/3 + Math.sin(progress * Math.PI) * Math.PI/4;
476476
leftLegAngle = -Math.PI/6 - Math.cos(progress * Math.PI) * Math.PI/6;
477477
rightLegAngle = Math.PI/6 + Math.cos(progress * Math.PI) * Math.PI/6;
478478
break;
479-
case 'celebrating':
479+
}
480+
case 'celebrating': {
480481
// 庆祝时手臂挥舞
481482
const time = Date.now() / 150;
482483
leftArmAngle = -Math.PI/2 + Math.sin(time) * Math.PI/4;
483484
rightArmAngle = Math.PI/2 - Math.sin(time + Math.PI) * Math.PI/4;
484485
leftLegAngle = -Math.PI/12 + Math.sin(time) * Math.PI/8;
485486
rightLegAngle = Math.PI/12 - Math.sin(time) * Math.PI/8;
486487
break;
488+
}
487489
case 'thinking':
488490
// 思考时一只手摸下巴
489491
leftArmAngle = -Math.PI/2;

0 commit comments

Comments
 (0)