diff --git a/miniprogram/pages/detailedReport/detailedReport.ts b/miniprogram/pages/detailedReport/detailedReport.ts index 3f6cb96..d946fba 100644 --- a/miniprogram/pages/detailedReport/detailedReport.ts +++ b/miniprogram/pages/detailedReport/detailedReport.ts @@ -124,6 +124,15 @@ const BMI_TYPE_COLOR: Record = { 肥胖: '#F24439', } +/** 基础指标:label 前端写死 */ +const BASIC_INDICATORS: { key: string; label: string }[] = [ + { key: 'ppWeightKg', label: '体重' }, + { key: 'ppBMI', label: 'BMI' }, + { key: 'ppFat', label: '体脂率' }, + { key: 'ppBodyScore', label: '健康评分' }, + { key: 'ppBodyHealth', label: '健康评价' }, +] + /** 将 bodyDataList 转为 key -> 指标 的映射 */ const toMap = (list: LefuBodyDatum[] = []): Record => { const map: Record = {} @@ -259,21 +268,22 @@ Page({ changeText, } - // 基础指标(2 行 x 3 列,第 6 格留空保持布局) - const basicKeys = ['ppWeightKg', 'ppBMI', 'ppFat', 'ppBodyScore', 'ppBodyHealth'] - const basicCells: BasicCell[] = basicKeys.map((k) => { - const d = map[k] - if (!d) return { ...EMPTY_BASIC_CELL } - const isScore = k === 'ppBodyScore' - const isHealth = k === 'ppBodyHealth' - const isBmi = k === 'ppBMI' + // 基础指标(2 行 x 3 列,第 6 格留空保持布局;label 前端写死,缺失值显示 -) + const basicCells: BasicCell[] = BASIC_INDICATORS.map(({ key, label }) => { + const d = map[key] + const isScore = key === 'ppBodyScore' + const isHealth = key === 'ppBodyHealth' + const isBmi = key === 'ppBMI' + if (!d) { + return { label, labelExtra: '', labelExtraColor: '', value: '-', unit: '' } + } return { - label: d.bodyParamName || k, + label, // BMI 名称后跟体型状态(消瘦/正常/超重/肥胖) labelExtra: isBmi ? data.bmiType || '' : '', labelExtraColor: isBmi ? BMI_TYPE_COLOR[data.bmiType || ''] || DEFAULT_STATUS_COLOR : '', // 健康评价展示等级文案(如"亚健康"),其余展示测量数值 - value: isHealth ? d.standardTitle || d.currentValue || '' : d.currentValue || '', + value: isHealth ? d.standardTitle || d.currentValue || '-' : d.currentValue || '-', // 健康评分补"分" unit: isScore ? d.unit || '分' : isHealth ? '' : d.unit || '', } @@ -350,7 +360,8 @@ Page({ ['右腿', 'ppBodyFatKgRightLeg', 'ppBodyFatRateRightLeg'], ['躯干', 'ppBodyFatKgTrunk', 'ppBodyFatRateTrunk'], ] - const bodyFat = isEight + const hasBodyFatData = fatPartLabels.some(([, massKey, rateKey]) => map[massKey] || map[rateKey]) + const bodyFat = isEight && hasBodyFatData ? { title: '躯干/四肢脂肪', rows: chunkParts( @@ -368,7 +379,8 @@ Page({ ['右腿', 'ppMuscleKgRightLeg', 'ppMuscleRateRightLeg'], ['躯干', 'ppMuscleKgTrunk', 'ppMuscleRateTrunk'], ] - const bodyMuscle = isEight + const hasBodyMuscleData = musclePartLabels.some(([, massKey, rateKey]) => map[massKey] || map[rateKey]) + const bodyMuscle = isEight && hasBodyMuscleData ? { title: '躯干/四肢肌肉', rows: chunkParts(