fix: 修复6项测试问题并补全配套资源

- 修复油脂类食物推荐量系数 (5.7→2.5) [ToolCalculatorServiceImpl]
- AI营养师接入真实Coze API,替换Mock回复 [ToolAiNutritionistServiceImpl]
- 食物百科详情新增钙/铁/维C/嘌呤/重量基准字段返回 [ToolFoodServiceImpl]
- V2Food模型新增purine、servingSize字段 [V2Food.java]
- 食物百科详情页动态重量标注+新增4项营养展示+替换Figma URL [food-detail.vue]
- 修复营养素列表dataset传参Bug(WeChat camelCase) [nutrition-knowledge.vue]
- 营养素详情页接入后端API+兜底本地数据+替换Figma URL [nutrient-detail.vue]
- 新增数据库迁移脚本及参考初始化数据 [docs/sql/]
- 新增前端占位图标5个 [static/images/]
- 新增开发任务完成报告 [docs/]

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Developer
2026-03-25 14:18:00 +08:00
parent a5de6fb46d
commit ba08abd374
16 changed files with 243 additions and 54 deletions

View File

@@ -29,7 +29,7 @@
<view class="key-nutrients-section">
<view class="section-header">
<text class="section-title">关键营养成分</text>
<view class="unit-badge">每100g</view>
<view class="unit-badge">{{ foodData.servingSize || '每100g' }}</view>
</view>
<view class="key-nutrients-grid">
<view
@@ -51,7 +51,7 @@
<view class="nutrition-table-section">
<view class="section-header">
<text class="section-title">营养成分表</text>
<text class="unit-text">每100g</text>
<text class="unit-text">{{ foodData.servingSize || '每100g' }}</text>
</view>
<view class="nutrition-table">
<view
@@ -92,8 +92,8 @@ import { getFoodDetail } from '@/api/tool.js';
export default {
data() {
return {
iconShare: 'https://www.figma.com/api/mcp/asset/f9f0d7b9-89c0-48d4-9e04-7140229e42f0',
iconSearch: 'https://www.figma.com/api/mcp/asset/aa6bb75b-0a9d-43cb-aaa4-6a71993fbd4d',
iconShare: '/static/images/icon-share.png',
iconSearch: '/static/images/icon-search.png',
loading: false,
/** 加载失败时的具体错误信息,用于调试;有值时页面会展示「当前数据来自缓存」提示 */
loadError: '',
@@ -114,7 +114,7 @@ export default {
category: '谷薯类',
categoryType: 'grain',
safetyTag: '放心吃',
image: 'https://www.figma.com/api/mcp/asset/bf4ff04c-1322-474a-bd03-5b8a49fe33ad',
image: '',
keyNutrients: [
{ name: '磷', value: '13', unit: 'mg', status: '正常' },
{ name: '钾', value: '7', unit: 'mg', status: '正常' },
@@ -315,8 +315,8 @@ export default {
if (data.keyNutrients && Array.isArray(data.keyNutrients)) {
return data.keyNutrients
}
// 从详细营养数据中提取关键营养素
const nutrients = data.nutrients || data.nutritionData || {}
// 从详细营养数据中提取关键营养素(兼容 data.nutrients 子对象和 data 平铺字段)
const nutrients = data.nutrients || data.nutritionData || data
const keyList = []
if (nutrients.phosphorus !== undefined) keyList.push({ name: '磷', value: String(nutrients.phosphorus), unit: 'mg', status: this.getStatus(nutrients.phosphorus, 'phosphorus') })
if (nutrients.potassium !== undefined) keyList.push({ name: '钾', value: String(nutrients.potassium), unit: 'mg', status: this.getStatus(nutrients.potassium, 'potassium') })
@@ -328,7 +328,8 @@ export default {
if (data.nutritionTable && Array.isArray(data.nutritionTable)) {
return data.nutritionTable
}
const nutrients = data.nutrients || data.nutritionData || {}
// 兼容 data.nutrients 子对象和 data 平铺字段
const nutrients = data.nutrients || data.nutritionData || data
const table = []
const items = [
{ key: 'potassium', name: '钾', unit: 'mg', thresholds: [200, 500] },
@@ -336,12 +337,15 @@ export default {
{ key: 'phosphorus', name: '磷', unit: 'mg', thresholds: [100, 300] },
{ key: 'protein', name: '蛋白质', unit: 'g', thresholds: [5, 15] },
{ key: 'sodium', name: '钠', unit: 'mg', thresholds: [100, 500] },
{ key: 'iron', name: '铁', unit: 'mg', thresholds: [5, 15] },
{ key: 'vitaminC', name: '维生素C', unit: 'mg', thresholds: [20, 60] },
{ key: 'purine', name: '嘌呤', unit: 'mg', thresholds: [50, 150] }
]
items.forEach(item => {
const val = nutrients[item.key]
if (val !== undefined) {
const level = val <= item.thresholds[0] ? 'low' : (val <= item.thresholds[1] ? 'medium' : 'high')
if (val !== undefined && val !== null) {
const numVal = Number(val)
const level = numVal <= item.thresholds[0] ? 'low' : (numVal <= item.thresholds[1] ? 'medium' : 'high')
const levelText = level === 'low' ? '低' : (level === 'medium' ? '中' : '高')
table.push({ name: item.name, value: String(val), unit: item.unit, level, levelText })
}

View File

@@ -108,40 +108,34 @@ export default {
data() {
return {
// 图标资源
iconWhyImportant: 'https://www.figma.com/api/mcp/asset/51e00c9b-5719-4391-9dff-68b70d24aece',
iconRecommendation: 'https://www.figma.com/api/mcp/asset/29e03ae9-a3ba-4416-8c6e-962bf3a8c8bb',
iconSuggestions: 'https://www.figma.com/api/mcp/asset/9027fced-f029-4f65-bba1-a0b5883b8d2b',
nutrientData: {
name: '钠',
english: 'Sodium (Na)',
icon: '🧂',
description: '调节体液平衡的电解质',
status: '适量控制',
statusDesc: '可适量补充,保持均衡',
importance: '钠参与调节体液平衡和血压,过多摄入会导致水肿和高血压,增加心血管负担。',
recommendation: 'CKD患者2-3g食盐/天相当于800-1200mg钠',
foodSources: ['食盐', '酱油', '腌制食品', '加工肉类', '咸菜', '味精'],
riskWarning: '摄入过多会导致水肿、高血压、心力衰竭等问题。',
suggestions: [
'每日食盐控制在3-5g约一啤酒瓶盖',
'避免腌制、熏制食品',
'少用酱油、味精等调味品',
'可用葱姜蒜、柠檬汁调味',
'查看食品标签,选择低钠产品',
'透析患者控制饮水量'
],
disclaimer: '以上建议仅供参考,\n\r 具体方案请咨询您的医生或营养师'
}
iconWhyImportant: '/static/images/icon-why-important.png',
iconRecommendation: '/static/images/icon-recommendation.png',
iconSuggestions: '/static/images/icon-suggestions.png',
nutrientName: '',
nutrientData: {}
}
},
onLoad(options) {
// 根据传入的营养素名称加载对应数据
if (options.name) {
this.loadNutrientData(options.name)
this.nutrientName = decodeURIComponent(options.name)
this.loadNutrientData(this.nutrientName)
}
},
methods: {
loadNutrientData(name) {
async loadNutrientData(name) {
// 优先调用后端接口获取营养素详情
try {
const { getNutrientDetail } = await import('@/api/tool.js')
const res = await getNutrientDetail(name)
if (res && res.data) {
this.nutrientData = res.data
return
}
} catch (e) {
console.warn('API获取营养素详情失败使用本地数据', e)
}
// 兜底:使用本地 nutrientMap
const nutrientMap = {
'钠': {
name: '钠',
@@ -271,9 +265,7 @@ export default {
}
}
if (nutrientMap[name]) {
this.nutrientData = nutrientMap[name]
}
this.nutrientData = nutrientMap[name] || {}
}
}
}

View File

@@ -36,7 +36,7 @@
class="nutrient-card"
v-for="(item, index) in nutrientList"
:key="index"
@click="goToNutrientDetail" :data-nutrient-index="index"
@click="goToNutrientDetail(index)"
>
<view class="nutrient-icon-wrapper">
<text class="nutrient-icon">{{ item.icon }}</text>
@@ -290,8 +290,7 @@ export default {
this.currentTab = tab;
await this.loadKnowledgeList();
},
goToNutrientDetail(event) {
const index = event.currentTarget.dataset.nutrientIndex;
goToNutrientDetail(index) {
const item = this.nutrientList[index];
if (!item) return;
uni.navigateTo({