fix(health): 趋势图数据不显示 — 后端 DTO 元组→结构体 + 前端解包修复
- 后端 IndicatorTimeseriesResp.data 从 Vec<(NaiveDate, f64)> 改为 Vec<DataPoint>
解决 JSON 序列化为数组而非对象导致前端无法识别的问题
- 前端 VitalSignsChart 正确解包 API 返回的 { indicator, data } 响应结构
- 移除趋势图无用的指标下拉选择器,固定显示收缩压(晨)趋势
- 修复 PatientDetail Card body padding 三层嵌套空白问题
This commit is contained in:
@@ -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>,
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user