fix(timeline): add missing SwiftData import + @MainActor on caller props
- TimelineEntry.swift: 缺 import SwiftData,4 处 persistentModelID 报错 - ArchiveListView.allEntries / HomeView.recentEntries: 显式 @MainActor, 否则 default-isolation=MainActor 下被推断为 nonisolated,调用 MainActor 方法 TimelineEntry.from(...) 触发 4+4 个 isolation 警告
This commit is contained in:
@@ -1,8 +1,35 @@
|
||||
import SwiftUI
|
||||
import SwiftData
|
||||
|
||||
struct HomeView: View {
|
||||
var onTapArchive: () -> Void = {}
|
||||
|
||||
@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]
|
||||
|
||||
@MainActor
|
||||
private var recentEntries: [TimelineEntry] {
|
||||
let all =
|
||||
indicators.map(TimelineEntry.from(indicator:)) +
|
||||
reports.map(TimelineEntry.from(report:)) +
|
||||
diaries.map(TimelineEntry.from(diary:)) +
|
||||
symptoms.map(TimelineEntry.from(symptom:))
|
||||
return all.sorted { $0.date > $1.date }.prefix(6).map { $0 }
|
||||
}
|
||||
|
||||
private var recentGrouped: [(section: DateSection, items: [TimelineEntry])] {
|
||||
TimelineGrouping.group(recentEntries)
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
ScrollView(showsIndicators: false) {
|
||||
VStack(alignment: .leading, spacing: 0) {
|
||||
@@ -93,37 +120,48 @@ struct HomeView: View {
|
||||
HStack(alignment: .lastTextBaseline) {
|
||||
Text("最近记录").font(.tjH2()).foregroundStyle(Tj.Palette.text)
|
||||
Spacer()
|
||||
Text("全部 ›")
|
||||
.font(.system(size: 12))
|
||||
.foregroundStyle(Tj.Palette.text3)
|
||||
Button(action: onTapArchive) {
|
||||
Text("全部 ›")
|
||||
.font(.system(size: 12))
|
||||
.foregroundStyle(Tj.Palette.text3)
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
}
|
||||
|
||||
VStack(spacing: 10) {
|
||||
RecentItemRow(
|
||||
date: "昨天 18:20",
|
||||
type: "异常项快拍",
|
||||
name: "低密度脂蛋白 LDL-C",
|
||||
value: "3.84 mmol/L",
|
||||
status: .high
|
||||
)
|
||||
RecentItemRow(
|
||||
date: "5 月 23 日",
|
||||
type: "关键报告归档",
|
||||
name: "春季年度体检 · 共 3 页",
|
||||
value: "3 项偏高",
|
||||
status: .archive
|
||||
)
|
||||
RecentItemRow(
|
||||
date: "5 月 22 日",
|
||||
type: "文字日记",
|
||||
name: "头痛 · 上午 10 点起,午后缓解",
|
||||
value: nil,
|
||||
status: .diary
|
||||
)
|
||||
if recentEntries.isEmpty {
|
||||
emptyRecent
|
||||
} else {
|
||||
VStack(alignment: .leading, spacing: 14) {
|
||||
ForEach(recentGrouped, id: \.section) { group in
|
||||
VStack(alignment: .leading, spacing: 8) {
|
||||
Text(group.section.label)
|
||||
.font(.system(size: 11, weight: .semibold))
|
||||
.tracking(0.5)
|
||||
.foregroundStyle(Tj.Palette.text3)
|
||||
VStack(spacing: 10) {
|
||||
ForEach(group.items) { entry in
|
||||
TimelineRow(entry: entry)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private var emptyRecent: some View {
|
||||
HStack {
|
||||
Text("还没有任何记录,点底部 + 号开始第一条")
|
||||
.font(.system(size: 13))
|
||||
.foregroundStyle(Tj.Palette.text3)
|
||||
Spacer()
|
||||
}
|
||||
.padding(.vertical, 14)
|
||||
.padding(.horizontal, 16)
|
||||
.tjCard(bordered: true)
|
||||
}
|
||||
|
||||
private var archiveSection: some View {
|
||||
VStack(alignment: .leading, spacing: 10) {
|
||||
Text("影像档案").font(.tjH2()).foregroundStyle(Tj.Palette.text)
|
||||
|
||||
Reference in New Issue
Block a user