refactor(profile,monitor): move height/weight from MonitorMetric to UserProfile

身高/体重对成人变化慢,作为 Profile 静态字段比每次录入 Indicator 更合适。

- MonitorMetric:6 case(从 8 减),删 .height / .weight
- UserProfile:加 weightKG: Double?(支持小数),加 bmi computed
- summaryLine 加体重段:'175cm · 68.5kg'(整数省小数)
- ProfileEditView basics 加 weight 行 + footer 显示 BMI + 分类(偏瘦/正常/超重/肥胖)
- IndicatorQuickSheet:删 .height 回写 Profile 的特殊逻辑
- UserProfileTests:+5 个(weight 字段、summaryLine 含 weight、BMI 计算)

兼容性:老 Indicator 里的 seriesKey 'weight' / 'height' 数据保留(SwiftData String?
不变),只是新录入路径走 Profile 不走 Indicator;Trends 仍能用 String seriesKey
查询历史(如果将来要展示老数据)。

测试:60 case pass / 0 fail / 0 warning。
This commit is contained in:
link2026
2026-05-26 07:58:47 +08:00
parent 37b47b2076
commit 39edc25dc1
5 changed files with 83 additions and 31 deletions

View File

@@ -53,11 +53,28 @@ private struct ProfileEditForm: View {
// MARK: -
private var basicsSection: some View {
Section("基本") {
Section {
birthYearPicker
sexPicker
heightRow
weightRow
bloodTypePicker
} header: {
Text("基本")
} footer: {
if let bmi = profile.bmi {
Text("BMI: \(String(format: "%.1f", bmi)) \(bmiLabel(bmi))")
.font(.system(size: 11))
}
}
}
private func bmiLabel(_ bmi: Double) -> String {
switch bmi {
case ..<18.5: return "(偏瘦)"
case ..<24: return "(正常)"
case ..<28: return "(超重)"
default: return "(肥胖)"
}
}
@@ -97,6 +114,18 @@ private struct ProfileEditForm: View {
}
}
private var weightRow: some View {
HStack {
Text("体重")
Spacer()
TextField("kg", value: $profile.weightKG, format: .number.precision(.fractionLength(0...1)))
.keyboardType(.decimalPad)
.multilineTextAlignment(.trailing)
.frame(width: 80)
Text("kg").foregroundStyle(Tj.Palette.text3)
}
}
private var bloodTypePicker: some View {
Picker("血型", selection: $profile.bloodTypeRaw) {
Text("不知道").tag("")