feat(AI): 优化AIRuntime任务取消机制并增强安全保护 - 在AI推理流中添加Task.checkCancellation()检查,使消费者取消时能快速退出 - 为异步流添加onTermination回调以取消内部Task,与LLMSession一致 - 实现SwiftData store的completeUnlessOpen文件保护,提升数据安全性 - 在store备份过程中同样应用加密保护 feat(home): 优化主页交互体验并统一详情查看功能 - 在主页"最近记录"中点击任意条目可打开只读详情sheet - 将时间线详情解析逻辑统一收敛到TimelineDetail.resolve方法 - 修复血压条目的精确反查逻辑,避免时间窗匹配错误 feat(archive): 新增提醒任务汇总卡并完善档案库功能 - 在档案库页面新增提醒任务汇总卡,显示总数和启用状态 - 添加按更新时间倒序合并的提醒标题预览功能 - 实现RemindersListView导航路由,统一管理提醒任务 - 优化导出列表显示,优先使用中文标签展示 feat(me): 优化个人中心界面并改进语言设置体验 - 将个人中心标题改为内容文字渲染,解决导航栏背景问题 - 为语言选择器添加个性化图标,使用本族语代表字区分 - 修复语言设置视图的图标显示逻辑 feat(timeline): 新增记录详情页删除功能并优化图表显示 - 在时间线详情页添加永久删除按钮和确认弹窗 - 实现完整的删除逻辑,包括SwiftData硬删和Vault原图unlink - 修复系列图表的数值范围计算,处理同值数据的对称留白 - 优化血压图表合并逻辑,只保留有数据点的线条 refactor(calendar): 修复DST切换导致的月份天数计算错误 - 使用calendar.range(of:.day,in:.month)替代日期间隔计算 - 避免在夏令时切换月份出现天数偏差问题 fix(ui): 修复多个UI组件的交互响应区域问题 - 为纯描边按钮和胶囊添加contentShape以扩大点击区域 - 修复提醒行展开按钮尺寸,保证不同提醒类型的垂直对齐 ```
190 lines
6.6 KiB
Swift
190 lines
6.6 KiB
Swift
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]
|
||
|
||
/// 点「最近记录」某行 → 打开只读详情 sheet(与档案库 C1 同款交互)。
|
||
@State private var selectedEntry: TimelineEntry?
|
||
|
||
@MainActor
|
||
private var recentEntries: [TimelineEntry] {
|
||
let all =
|
||
TimelineEntry.from(indicators: indicators) +
|
||
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) {
|
||
greeting
|
||
.padding(.top, 4)
|
||
.padding(.bottom, 18)
|
||
|
||
TodayRemindersCard()
|
||
|
||
OngoingSymptomsCard()
|
||
.padding(.bottom, 18)
|
||
|
||
recentSection
|
||
.padding(.bottom, 22)
|
||
|
||
archiveSection
|
||
}
|
||
.padding(.horizontal, 20)
|
||
.padding(.bottom, 20)
|
||
}
|
||
.background(Tj.Palette.sand.ignoresSafeArea())
|
||
.sheet(item: $selectedEntry) { entry in
|
||
if let d = TimelineDetail.resolve(
|
||
for: entry,
|
||
indicators: indicators, reports: reports,
|
||
diaries: diaries, symptoms: symptoms
|
||
) {
|
||
TimelineEntryDetailView(detail: d)
|
||
}
|
||
}
|
||
}
|
||
|
||
private var greeting: some View {
|
||
HStack(alignment: .top) {
|
||
VStack(alignment: .leading, spacing: 4) {
|
||
Text(todayLine)
|
||
.font(.system(size: 12))
|
||
.tracking(1)
|
||
.foregroundStyle(Tj.Palette.text3)
|
||
Text(greetingWord)
|
||
.font(.tjTitle())
|
||
.foregroundStyle(Tj.Palette.text)
|
||
}
|
||
Spacer()
|
||
TjLockChip()
|
||
.padding(.top, 4)
|
||
}
|
||
}
|
||
|
||
private var todayLine: String {
|
||
let now = Date()
|
||
let day = now.formatted(.dateTime.month().day())
|
||
let weekday = now.formatted(.dateTime.weekday(.abbreviated))
|
||
return "\(day) · \(weekday)"
|
||
}
|
||
|
||
private var greetingWord: String {
|
||
switch Calendar.current.component(.hour, from: Date()) {
|
||
case 5..<12: return String(appLoc: "早安")
|
||
case 12..<18: return String(appLoc: "下午好")
|
||
default: return String(appLoc: "晚上好")
|
||
}
|
||
}
|
||
|
||
private var recentSection: some View {
|
||
VStack(alignment: .leading, spacing: 10) {
|
||
HStack(alignment: .lastTextBaseline) {
|
||
Text("最近记录").font(.tjH2()).foregroundStyle(Tj.Palette.text)
|
||
Spacer()
|
||
Button(action: onTapArchive) {
|
||
Text("全部 ›")
|
||
.font(.system(size: 12))
|
||
.foregroundStyle(Tj.Palette.text3)
|
||
}
|
||
.buttonStyle(.plain)
|
||
}
|
||
|
||
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
|
||
Button {
|
||
if TimelineDetail.resolve(
|
||
for: entry,
|
||
indicators: indicators, reports: reports,
|
||
diaries: diaries, symptoms: symptoms
|
||
) != nil {
|
||
selectedEntry = entry
|
||
}
|
||
} label: {
|
||
TimelineRow(entry: entry)
|
||
}
|
||
.buttonStyle(.plain)
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
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)
|
||
|
||
Button(action: onTapArchive) {
|
||
HStack(spacing: 14) {
|
||
TjPlaceholder(label: String(appLoc: "档案 · \(reports.count)"))
|
||
.frame(width: 56, height: 56)
|
||
VStack(alignment: .leading, spacing: 2) {
|
||
Text("我的报告档案")
|
||
.font(.system(size: 14, weight: .semibold))
|
||
.foregroundStyle(Tj.Palette.text)
|
||
Text("\(reports.count) 份 · \(indicators.count) 项指标 · 端侧加密")
|
||
.font(.system(size: 11))
|
||
.foregroundStyle(Tj.Palette.text3)
|
||
}
|
||
Spacer()
|
||
Image(systemName: "chevron.right")
|
||
.font(.system(size: 14, weight: .medium))
|
||
.foregroundStyle(Tj.Palette.text3)
|
||
}
|
||
.padding(14)
|
||
.tjCard(bordered: true)
|
||
}
|
||
.buttonStyle(.plain)
|
||
}
|
||
}
|
||
}
|
||
|
||
#Preview {
|
||
HomeView()
|
||
}
|