fix(health): 趋势图数据不显示 — 后端 DTO 元组→结构体 + 前端解包修复
Some checks failed
CI / rust-check (push) Has been cancelled
CI / rust-test (push) Has been cancelled
CI / frontend-build (push) Has been cancelled
CI / security-audit (push) Has been cancelled

- 后端 IndicatorTimeseriesResp.data 从 Vec<(NaiveDate, f64)> 改为 Vec<DataPoint>
  解决 JSON 序列化为数组而非对象导致前端无法识别的问题
- 前端 VitalSignsChart 正确解包 API 返回的 { indicator, data } 响应结构
- 移除趋势图无用的指标下拉选择器,固定显示收缩压(晨)趋势
- 修复 PatientDetail Card body padding 三层嵌套空白问题
This commit is contained in:
iven
2026-04-26 09:35:05 +08:00
parent 6c60be0047
commit 1f8fd0465d
4 changed files with 60 additions and 105 deletions

View File

@@ -192,7 +192,7 @@ pub struct TrendResp {
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
pub struct IndicatorTimeseriesResp {
pub indicator: String,
pub data: Vec<(NaiveDate, f64)>,
pub data: Vec<DataPoint>,
}
// ---------------------------------------------------------------------------

View File

@@ -214,7 +214,7 @@ pub async fn get_indicator_timeseries(
.all(&state.db)
.await?;
let data: Vec<(chrono::NaiveDate, f64)> = vitals.into_iter().filter_map(|v| {
let data: Vec<DataPoint> = vitals.into_iter().filter_map(|v| {
let val = match indicator.as_str() {
"heart_rate" => v.heart_rate.map(|x| x as f64),
"weight" => v.weight.map(|d| d.to_f64().unwrap_or(0.0)),
@@ -225,7 +225,10 @@ pub async fn get_indicator_timeseries(
"diastolic_bp_evening" => v.diastolic_bp_evening.map(|x| x as f64),
_ => None,
};
val.map(|fv| (v.record_date, fv))
val.map(|fv| DataPoint {
date: v.record_date.to_string(),
value: fv,
})
}).collect();
Ok(IndicatorTimeseriesResp { indicator, data })
@@ -393,15 +396,8 @@ pub async fn get_mini_trend(
)
.await?;
// 4. 转换为 DataPoint 格式
let data_points = timeseries
.data
.into_iter()
.map(|(date, value)| DataPoint {
date: date.to_string(),
value,
})
.collect();
// 4. 直接使用 DataPoint
let data_points = timeseries.data;
Ok(MiniTrendResp {
indicator,