Browse Source

旋律线 优化 数据错误的情况

黄琪勇 10 months ago
parent
commit
64b6f2a884
1 changed files with 4 additions and 3 deletions
  1. 4 3
      src/page-instrument/view-detail/smoothAnimation/index.ts

+ 4 - 3
src/page-instrument/view-detail/smoothAnimation/index.ts

@@ -184,13 +184,14 @@ export function moveSmoothAnimation(progress: number, activeIndex: number, isMov
    // 百分比转为当前的index 距离个数
    const progressCalcIndex = Math.round(progress * _numberOfSegments)
    // // 当前的index
-   let nowIndex = nextPointsIndex - _numberOfSegments + progressCalcIndex
+   const nowIndex = nextPointsIndex - _numberOfSegments + progressCalcIndex
    const nowPointsPos = smoothAnimationState.pointsPos[nowIndex]
-   smoothAnimationState.canvasCtx?.clearRect(0, 0, smoothAnimationState.canvasDomWith, smoothAnimationState.canvasDomHeight)
-   if (!nowPointsPos?.x) {
+   // 当x的值为null和undefinedde的时候 错误 不走下面的方法
+   if (!(nowPointsPos?.x != null)) {
       console.error(nowPointsPos?.x, "nowPointsPos", nowIndex, activeIndex)
       return
    }
+   smoothAnimationState.canvasCtx?.clearRect(0, 0, smoothAnimationState.canvasDomWith, smoothAnimationState.canvasDomHeight)
    // 移动
    smoothAnimationMove(
       {