diff --git a/miniprogram/pages/detailedReport/detailedReport.ts b/miniprogram/pages/detailedReport/detailedReport.ts index 40db345..4267d58 100644 --- a/miniprogram/pages/detailedReport/detailedReport.ts +++ b/miniprogram/pages/detailedReport/detailedReport.ts @@ -159,11 +159,28 @@ const splitWeight = (weight: number): { int: string; decimal: string } => { return { int, decimal: `.${dec}` } } -/** 根据 BMI 计算刻度圆圈位置(百分比) */ +/** + * 刻度轨道结构(rpx):屏宽 750 - basicIndicators 左右 padding 30*2 - 左右 border 4*2 = 682。 + * BLOCK_GAP 与 less 中 basicIndicatorsTrack 的 gap: 6rpx 保持同步。 + */ +const TRACK_WIDTH = 682 +const BLOCK_GAP = 6 +const BLOCK_WIDTH = (TRACK_WIDTH - BLOCK_GAP * 3) / 4 + +/** 根据 BMI 计算刻度圆圈圆心位置(百分比),对齐消瘦/正常/超重/肥胖四段分界 18.5/24/28,并计入色块间隙 */ const calcBmiLeft = (bmi?: number): number => { if (bmi == null || isNaN(bmi)) return 0 - const pct = (bmi - 14) / (40 - 14) - return Math.min(Math.max(pct, 0), 1) * 100 + let left: number + if (bmi < 18.5) { + left = (bmi / 18.5) * BLOCK_WIDTH + } else if (bmi < 24) { + left = BLOCK_WIDTH + BLOCK_GAP + ((bmi - 18.5) / (24 - 18.5)) * BLOCK_WIDTH + } else if (bmi < 28) { + left = BLOCK_WIDTH * 2 + BLOCK_GAP * 2 + ((bmi - 24) / (28 - 24)) * BLOCK_WIDTH + } else { + left = BLOCK_WIDTH * 3 + BLOCK_GAP * 3 + ((bmi - 28) / (40 - 28)) * BLOCK_WIDTH + } + return Math.min(Math.max(left / TRACK_WIDTH, 0), 1) * 100 } Page({