- 替换 QuickCaptureFlow 和 ArchiveFlow 为 UnifiedCaptureFlow 统一流程 - 新增 VLSession 封装 Qwen2.5-VL 模型进行图像文本推理 - 实现 AIRuntime 中 VL 模型的准备和分析功能 - 添加 VLPrompts 定义体检化验单识别的 JSON 输出模板 - 创建 CaptureReviewForm 提供 VL 解析结果的可编辑表单界面 - 集成 VisionKit 文档扫描器支持真机多页文档扫描 - 为模拟器实现 PhotosPicker 回退方案选择已有照片 - 在 RootView 中统一使用 UnifiedCaptureFlow 处理快速和归档流程 - 添加 CustomMetricEditor 支持自定义监测指标的创建编辑删除 - 扩展 KangkangApp 模型配置以支持新数据类型 - 实现档案列表中症状结束功能通过时间线行点击触发
172 lines
5.9 KiB
Swift
172 lines
5.9 KiB
Swift
import SwiftUI
|
|
import SwiftData
|
|
|
|
struct ArchiveListView: View {
|
|
@Query(sort: \Indicator.capturedAt, order: .reverse)
|
|
private var indicators: [Indicator]
|
|
|
|
@Query(sort: \Report.reportDate, order: .reverse)
|
|
private var reports: [Report]
|
|
|
|
@Query(sort: \DiaryEntry.createdAt, order: .reverse)
|
|
private var diaries: [DiaryEntry]
|
|
|
|
@Query(sort: \Symptom.startedAt, order: .reverse)
|
|
private var symptoms: [Symptom]
|
|
|
|
@State private var filter: TimelineKind? = nil
|
|
@State private var endingSymptom: Symptom?
|
|
|
|
@MainActor
|
|
private var allEntries: [TimelineEntry] {
|
|
let mapped =
|
|
TimelineEntry.from(indicators: indicators) +
|
|
reports.map(TimelineEntry.from(report:)) +
|
|
diaries.map(TimelineEntry.from(diary:)) +
|
|
symptoms.map(TimelineEntry.from(symptom:))
|
|
let filtered = filter.map { kind in mapped.filter { $0.kind == kind } } ?? mapped
|
|
return filtered.sorted { $0.date > $1.date }
|
|
}
|
|
|
|
private var grouped: [(section: DateSection, items: [TimelineEntry])] {
|
|
TimelineGrouping.group(allEntries)
|
|
}
|
|
|
|
private var totalCount: Int { allEntries.count }
|
|
|
|
var body: some View {
|
|
VStack(alignment: .leading, spacing: 0) {
|
|
header
|
|
.padding(.horizontal, 20)
|
|
.padding(.top, 8)
|
|
.padding(.bottom, 14)
|
|
|
|
filterChips
|
|
.padding(.bottom, 14)
|
|
|
|
if allEntries.isEmpty {
|
|
emptyState
|
|
} else {
|
|
ScrollView(showsIndicators: false) {
|
|
LazyVStack(alignment: .leading, spacing: 18, pinnedViews: [.sectionHeaders]) {
|
|
ForEach(grouped, id: \.section) { group in
|
|
Section {
|
|
VStack(spacing: 10) {
|
|
ForEach(group.items) { entry in
|
|
rowView(for: entry)
|
|
}
|
|
}
|
|
.padding(.horizontal, 20)
|
|
} header: {
|
|
sectionHeader(group.section, count: group.items.count)
|
|
}
|
|
}
|
|
}
|
|
.padding(.bottom, 24)
|
|
}
|
|
}
|
|
}
|
|
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .topLeading)
|
|
.background(Tj.Palette.sand.ignoresSafeArea())
|
|
.sheet(item: $endingSymptom) { sym in
|
|
SymptomEndSheet(symptom: sym)
|
|
}
|
|
}
|
|
|
|
@ViewBuilder
|
|
private func rowView(for entry: TimelineEntry) -> some View {
|
|
if entry.kind == .symptom, entry.isOngoing,
|
|
let sym = symptoms.first(where: { "symptom-\($0.persistentModelID)" == entry.id }) {
|
|
Button {
|
|
endingSymptom = sym
|
|
} label: {
|
|
TimelineRow(entry: entry)
|
|
}
|
|
.buttonStyle(.plain)
|
|
} else {
|
|
TimelineRow(entry: entry)
|
|
}
|
|
}
|
|
|
|
private var header: some View {
|
|
HStack(alignment: .lastTextBaseline) {
|
|
Text("记录")
|
|
.font(.tjTitle(26))
|
|
.foregroundStyle(Tj.Palette.text)
|
|
Text(totalCount == 0 ? "" : "\(totalCount) 条")
|
|
.font(.system(size: 12))
|
|
.foregroundStyle(Tj.Palette.text3)
|
|
Spacer()
|
|
}
|
|
}
|
|
|
|
private var filterChips: some View {
|
|
ScrollView(.horizontal, showsIndicators: false) {
|
|
HStack(spacing: 8) {
|
|
chip(label: "全部", selected: filter == nil) { filter = nil }
|
|
ForEach(TimelineKind.allCases) { kind in
|
|
chip(label: kind.label, selected: filter == kind) {
|
|
filter = filter == kind ? nil : kind
|
|
}
|
|
}
|
|
}
|
|
.padding(.horizontal, 20)
|
|
}
|
|
}
|
|
|
|
private func chip(label: String, selected: Bool, action: @escaping () -> Void) -> some View {
|
|
Button(action: action) {
|
|
Text(label)
|
|
.font(.system(size: 13, weight: selected ? .semibold : .regular))
|
|
.foregroundStyle(selected ? Tj.Palette.paper : Tj.Palette.text)
|
|
.padding(.horizontal, 14)
|
|
.padding(.vertical, 8)
|
|
.background(
|
|
Capsule().fill(selected ? Tj.Palette.ink : Tj.Palette.paper)
|
|
)
|
|
.overlay(
|
|
Capsule().strokeBorder(Tj.Palette.line, lineWidth: selected ? 0 : 1)
|
|
)
|
|
}
|
|
.buttonStyle(.plain)
|
|
}
|
|
|
|
private func sectionHeader(_ section: DateSection, count: Int) -> some View {
|
|
HStack {
|
|
Text(section.label)
|
|
.font(.system(size: 12, weight: .semibold))
|
|
.tracking(0.5)
|
|
.foregroundStyle(Tj.Palette.text2)
|
|
Rectangle()
|
|
.fill(Tj.Palette.lineSoft)
|
|
.frame(height: 1)
|
|
Text("\(count)")
|
|
.font(.system(size: 11, design: .monospaced))
|
|
.foregroundStyle(Tj.Palette.text3)
|
|
}
|
|
.padding(.horizontal, 20)
|
|
.padding(.vertical, 8)
|
|
.background(Tj.Palette.sand)
|
|
}
|
|
|
|
private var emptyState: some View {
|
|
VStack(spacing: 14) {
|
|
Spacer()
|
|
TjPlaceholder(label: "还没有任何记录\n点底部 + 号开始")
|
|
.frame(width: 240, height: 140)
|
|
Text(filter == nil ? "记录会按时间归类显示" : "这个类别下没有记录")
|
|
.font(.system(size: 13))
|
|
.foregroundStyle(Tj.Palette.text3)
|
|
Spacer()
|
|
}
|
|
.frame(maxWidth: .infinity)
|
|
}
|
|
}
|
|
|
|
#Preview {
|
|
ArchiveListView()
|
|
.modelContainer(for: [
|
|
Indicator.self, Report.self, DiaryEntry.self, Symptom.self, Asset.self
|
|
], inMemory: true)
|
|
}
|