feat(nutrition): 添加营养成分表拍照分析功能

新增营养成分表拍照识别功能,用户可通过拍摄食物包装上的成分表自动解析营养信息:
- 创建成分表分析页面,支持拍照/选择图片和结果展示
- 集成新的营养成分分析API,支持图片上传和流式分析
- 在营养雷达卡片中添加成分表分析入口
- 更新应用版本至1.0.19
This commit is contained in:
richarjiang
2025-10-16 12:16:08 +08:00
parent bef7d645a8
commit 5013464a2c
9 changed files with 1177 additions and 13 deletions

View File

@@ -47,13 +47,9 @@ async function doFetch<T>(path: string, options: ApiRequestOptions = {}): Promis
signal: options.signal,
});
const text = await response.text();
let json: any = null;
try {
json = text ? JSON.parse(text) : null;
} catch {
// 非 JSON 响应
}
const json = await response.json()
console.log('json', json);
if (!response.ok) {
const errorMessage = (json && (json.message || json.error)) || `HTTP ${response.status}`;
@@ -63,6 +59,15 @@ async function doFetch<T>(path: string, options: ApiRequestOptions = {}): Promis
throw error;
}
if (json.code !== undefined && json.code !== 0) {
const errorMessage = (json && (json.message || json.error)) || `HTTP ${response.status}`;
const error = new Error(errorMessage);
// @ts-expect-error augment
error.status = response.status;
throw error;
}
// 支持后端返回 { data: ... } 或直接返回对象
return (json && (json.data ?? json)) as T;
}