fix: 修复帖子详情营养数据为空时无法从打卡记录补充的问题
问题原因:
- nutritionDataJson 为 "{}" 时生成 4 项都是 "-" 的数组
- 因为 length===4 而非 0,未触发从打卡详情补数据逻辑
修复内容:
- 空对象 {} 返回 [],触发后续补数据逻辑
- 全为 "-" 的无效数据也返回 []
- 兼容 check_in_record_id 下划线命名
- 当 checkInRecordId 存在且营养数据为空时,自动从打卡详情补充
由 Cursor CLI 检测并修复
This commit is contained in:
@@ -334,8 +334,9 @@ export default {
|
||||
// 格式化帖子数据
|
||||
this.formatPostData(data)
|
||||
|
||||
// 若详情接口未返回营养数据且有关联打卡记录,则根据打卡详情补充营养统计(等待完成后再结束加载)
|
||||
const checkInId = data.checkInRecordId != null ? (Number(data.checkInRecordId) || data.checkInRecordId) : null
|
||||
// 若详情接口未返回有效营养数据且有关联打卡记录,则根据打卡详情补充营养统计(等待完成后再结束加载)
|
||||
const rawCheckInId = data.checkInRecordId ?? data.check_in_record_id
|
||||
const checkInId = rawCheckInId != null ? (Number(rawCheckInId) || rawCheckInId) : null
|
||||
if (this.postData.nutritionStats.length === 0 && checkInId != null) {
|
||||
await this.fillNutritionStatsFromCheckin(checkInId)
|
||||
}
|
||||
@@ -395,8 +396,17 @@ export default {
|
||||
value: s.value != null ? String(s.value) : '-'
|
||||
})).filter(s => s.label)
|
||||
}
|
||||
// 2b) 对象格式:兼容后端 fill-nutrition 的 energyKcal/proteinG/potassiumMg/phosphorusMg 及常见命名
|
||||
return this.buildNutritionStatsFromNutritionObject(nutritionData)
|
||||
// 2b) 对象格式:空对象 "{}" 视为无营养数据,返回 [] 以便走打卡详情/服务端填充
|
||||
if (!Array.isArray(nutritionData) && Object.keys(nutritionData).length === 0) {
|
||||
return []
|
||||
}
|
||||
// 2c) 有键的对象:兼容后端 fill-nutrition 的 energyKcal/proteinG 等
|
||||
const statsFromJson = this.buildNutritionStatsFromNutritionObject(nutritionData)
|
||||
// 若解析后全部为占位符 "-",视为无效数据,返回 [] 以便走打卡/服务端填充
|
||||
if (statsFromJson.length > 0 && statsFromJson.every(s => s.value === '-')) {
|
||||
return []
|
||||
}
|
||||
return statsFromJson
|
||||
} catch (e) {
|
||||
// ignore
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user