Files
kangkang/康康/Features/Trends/TrendsView.swift
link2026 77a4ee1c37 缺少代码差异信息,无法生成具体的commit message。请提供code differences内容以便分析并生成符合Angular规范的提交信息。
当您提供代码差异后,我将按照以下格式生成:

```
<type>(<scope>): <subject>

<body>
```

其中type会根据更改类型选择(feat、fix、docs、style、refactor等),scope表示影响范围,subject简要描述变更内容,body详细说明修改内容。
2026-06-07 14:17:18 +08:00

105 lines
3.5 KiB
Swift

import SwiftUI
import SwiftData
/// Tab;:
/// 2 ,(seriesKey)()
struct TrendsView: View {
@Query(sort: \Indicator.capturedAt, order: .reverse)
private var indicators: [Indicator]
@Query private var profiles: [UserProfile]
@Query private var customMetrics: [CustomMonitorMetric]
private var profile: UserProfile? { profiles.first }
private var seriesBuckets: [SeriesBucket] {
SeriesBucket.build(from: indicators,
profile: profile,
customMetrics: customMetrics)
}
private var monitorBuckets: [SeriesBucket] {
seriesBuckets.filter { $0.kind == .monitor }
}
private var labBuckets: [SeriesBucket] {
seriesBuckets.filter { $0.kind == .lab }
}
var body: some View {
NavigationStack {
ScrollView(showsIndicators: false) {
VStack(alignment: .leading, spacing: 18) {
header.padding(.top, 4)
if seriesBuckets.isEmpty {
emptyState
} else {
if !monitorBuckets.isEmpty {
section(title: String(appLoc: "长期监测"), buckets: monitorBuckets)
}
if !labBuckets.isEmpty {
section(title: String(appLoc: "化验指标趋势"), buckets: labBuckets)
}
}
}
.padding(.horizontal, 20)
.padding(.bottom, 24)
}
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .topLeading)
.background(Tj.Palette.sand.ignoresSafeArea())
.navigationBarHidden(true)
}
}
private var header: some View {
Text("趋势")
.font(.tjTitle(26))
.foregroundStyle(Tj.Palette.text)
}
private func section(title: String, buckets: [SeriesBucket]) -> some View {
VStack(alignment: .leading, spacing: 12) {
HStack(alignment: .lastTextBaseline) {
Text(title)
.font(.tjH2())
.foregroundStyle(Tj.Palette.text)
Text("\(buckets.count)")
.font(.tjScaled( 12))
.foregroundStyle(Tj.Palette.text3)
Spacer()
}
VStack(spacing: 12) {
ForEach(buckets) { bucket in
NavigationLink {
TrendDetailView(bucket: bucket)
} label: {
TrendRow(bucket: bucket)
}
.buttonStyle(.plain)
}
}
}
}
private var emptyState: some View {
VStack(spacing: 12) {
TjPlaceholder(label: String(appLoc: "还没有可成趋势的指标"))
.frame(height: 120)
.frame(maxWidth: 260)
Text("同一指标记录满 2 次后,会在这里出现时间序列")
.font(.tjScaled( 12))
.foregroundStyle(Tj.Palette.text3)
.multilineTextAlignment(.center)
}
.frame(maxWidth: .infinity)
.padding(.top, 60)
}
}
#Preview {
TrendsView()
.modelContainer(for: [
Indicator.self, Report.self, DiaryEntry.self, Symptom.self, Asset.self
], inMemory: true)
}