Files
msh-system/scripts/logs/agent-BUG-004-171409.log
scottpan 4be53dcd1b feat: 集成 KieAI 服务,移除 models-integration 子项目
- 添加 Gemini 2.5 Flash 对话接口(流式+非流式)
- 添加 NanoBanana 图像生成/编辑接口
- 添加 Sora2 视频生成接口(文生视频、图生视频、去水印)
- 移除 models-integration 子项目(功能已迁移至主后端)
- 新增测试文档和 Playwright E2E 配置
- 更新前端页面和 API 接口
- 更新后端配置和日志处理
2026-03-03 15:33:50 +08:00

68 lines
3.5 KiB
Plaintext
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
BUG-004 已按你的要求修好,修改总结如下。
---
## 1. 根因API 参数错误)
- **后端**`ToolController.getFoodDetail(@PathVariable Long id)` 只接受 **Long 类型 id**。
- **前端**:食物百科列表跳转详情时用了 **`item.name`**(如「羊肉(熟)」「儿童营养饼干」),导致后端报 `NumberFormatException`,接口失败,页面只提示「数据加载失败」。
日志中可见:`Failed to convert value of type 'java.lang.String' to required type 'java.lang.Long'`.
---
## 2. 修改内容
### 2.1 `msh_single_uniapp/pages/tool/food-encyclopedia.vue`
- **跳转参数**:改为传 **`item.id`**(后端列表返回的 `id`),不再传 `item.name`。
- 若某条没有 `id`,则回退为 `item.name`,并对 name 做 `encodeURIComponent`,避免中文等字符在 URL 里出错。
```javascript
// 后端详情接口需要 Long 类型 id传 id 而非 name
const id = item.id != null ? item.id : item.name
url: `/pages/tool/food-detail?id=${encodeURIComponent(id)}`
```
这样从列表点进详情会带正确的 id接口可正常返回数据。
---
### 2.2 `msh_single_uniapp/pages/tool/food-detail.vue`
1. **请求参数打印**
- `onLoad``console.log('[food-detail] onLoad params:', { id: options.id, name: options.name })`
- `loadFoodData``console.log('[food-detail] getFoodDetail request param:', { id, type: typeof id })`
便于确认传参是否正确。
2. **`loadError` 与调试**
- 增加 `loadError: ''`。
- 在 `loadFoodData` 的 **catch** 里把 `loadError` 设为具体错误信息(`error.message || error.msg || error`),便于调试。
3. **失败时用默认数据 + 缓存提示**
- 抽取 **`applyDefaultFoodData(clearError)`**:用 `defaultFoodData` 填充 `foodData`,并对 `keyNutrients`、`nutritionTable` 做数组拷贝,保证不为空数组、能正常渲染 `.food-name-overlay` / `.nutrient-card` / `.nutrition-row`。
- 在 catch 里:先设置 `loadError`,再调用 `applyDefaultFoodData(false)`(不再清空 `loadError`),并保留原有 `showToast('数据加载失败')`。
- 无入参时仍走默认数据,此时调用 `applyDefaultFoodData()` 会清空 `loadError`。
4. **「当前数据来自缓存」提示**
- 当 `loadError` 有值时,在页面顶部展示提示条:「当前数据来自缓存,可能不是最新」,并增加 `.cache-notice` 样式。
5. **默认数据下的展示**
- `defaultFoodData` 已包含完整的 `name`、`category`、`safetyTag`、`image`、`keyNutrients`、`nutritionTable`(均为非空数组),应用 `applyDefaultFoodData` 后,`.food-name-overlay`、`.nutrient-card`、`.nutrition-row` 在默认数据下也能正常渲染。
6. **样式**
- 为 `.nutrition-dot` 增加 `&.high`,避免后端返回 `level: 'high'` 时缺样式。
---
## 3. 行为小结
| 场景 | 行为 |
|----------------|------|
| 列表点击条目 | 传 `item.id`,详情接口用 id 请求,正常展示该食物。 |
| 接口失败/异常 | 设置 `loadError`、用 `defaultFoodData` 填页面、Toast「数据加载失败」、顶部显示「当前数据来自缓存可能不是最新」名称/营养成分等仍可正常显示。 |
| 无 id/name 入参 | 直接使用默认数据,不显示缓存提示。 |
按当前逻辑,从食物百科点进详情应能正常看到名称和营养成分;若接口仍失败,会显示默认示例数据并提示「当前数据来自缓存,可能不是最新」,同时控制台和 `loadError` 可用来排查具体错误。