- ProfileEditView Form 风格,即改即存,onDisappear 触发 ctx.save - basics(出生年 / 性别 / 身高 / 血型) - 慢病 chips(8 预设 + 自定义) - allergies / familyHistory / medications 通用 list section - FlowLayout(Layout 协议自实现)用于 chip 流式换行 - MeView 改造:NavigationStack + ProfileCard 显示 summaryLine, 3 个 settings 卡片(模型 / Face ID / 关于)stub,DEBUG 块仍在底部 - IndicatorQuickSheet 整合 MonitorMetric: - 顶部 LazyVGrid 2 列展示 8 个 MonitorMetric(进趋势) - 下方 horizontal scroll 化验项快捷(不进趋势) - 选血压切到 2 字段 UI(收缩/舒张),保存写 2 条 Indicator(同 capturedAt) - 选单字段 monitor:自动算 status,锁 name/unit/range - 选 lab preset:辅助填 name/unit/range,status 手动 - 自由输入路径不变 - 身高 monitor 保存时回写 UserProfile.heightCM - Profile-aware range hint:'按 67 岁调整' 仅在 effectiveRange 不同于 baseRange 时显示
120 lines
3.8 KiB
Swift
120 lines
3.8 KiB
Swift
import SwiftUI
|
|
import SwiftData
|
|
|
|
struct MeView: View {
|
|
@Environment(\.modelContext) private var ctx
|
|
@Query private var profiles: [UserProfile]
|
|
|
|
private var profile: UserProfile? { profiles.first }
|
|
|
|
var body: some View {
|
|
NavigationStack {
|
|
ScrollView {
|
|
VStack(spacing: 12) {
|
|
profileCard
|
|
settingsCard(title: "模型管理",
|
|
detail: "未配置",
|
|
icon: "cpu")
|
|
settingsCard(title: "Face ID 启动锁",
|
|
detail: "关闭",
|
|
icon: "faceid")
|
|
settingsCard(title: "关于",
|
|
detail: "v0.1 · W2",
|
|
icon: "info.circle")
|
|
|
|
#if DEBUG
|
|
DebugAIRunner()
|
|
.padding(.top, 8)
|
|
#endif
|
|
}
|
|
.padding(.horizontal, 16)
|
|
.padding(.vertical, 20)
|
|
}
|
|
.background(Tj.Palette.sand.ignoresSafeArea())
|
|
.navigationTitle("我的")
|
|
.navigationBarTitleDisplayMode(.large)
|
|
.onAppear {
|
|
if profiles.isEmpty {
|
|
_ = UserProfileStore.loadOrCreate(in: ctx)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// MARK: - Cards
|
|
|
|
private var profileCard: some View {
|
|
NavigationLink {
|
|
ProfileEditView()
|
|
} label: {
|
|
HStack(spacing: 12) {
|
|
ZStack {
|
|
Circle()
|
|
.fill(Tj.Palette.amber.opacity(0.25))
|
|
Image(systemName: "person.crop.circle.fill")
|
|
.font(.system(size: 22))
|
|
.foregroundStyle(Tj.Palette.ink)
|
|
}
|
|
.frame(width: 44, height: 44)
|
|
|
|
VStack(alignment: .leading, spacing: 2) {
|
|
Text("个人资料")
|
|
.font(.system(size: 15, weight: .semibold))
|
|
.foregroundStyle(Tj.Palette.text)
|
|
Text(profileLine)
|
|
.font(.system(size: 12))
|
|
.foregroundStyle(Tj.Palette.text3)
|
|
.lineLimit(1)
|
|
}
|
|
Spacer()
|
|
Image(systemName: "chevron.right")
|
|
.font(.system(size: 13, weight: .medium))
|
|
.foregroundStyle(Tj.Palette.text3)
|
|
}
|
|
.padding(14)
|
|
.tjCard()
|
|
}
|
|
.buttonStyle(.plain)
|
|
}
|
|
|
|
private func settingsCard(title: String, detail: String, icon: String) -> some View {
|
|
HStack(spacing: 12) {
|
|
ZStack {
|
|
Circle().fill(Tj.Palette.sand2)
|
|
Image(systemName: icon)
|
|
.font(.system(size: 18))
|
|
.foregroundStyle(Tj.Palette.text2)
|
|
}
|
|
.frame(width: 44, height: 44)
|
|
|
|
Text(title)
|
|
.font(.system(size: 15, weight: .medium))
|
|
.foregroundStyle(Tj.Palette.text)
|
|
Spacer()
|
|
Text(detail)
|
|
.font(.system(size: 12))
|
|
.foregroundStyle(Tj.Palette.text3)
|
|
Image(systemName: "chevron.right")
|
|
.font(.system(size: 13, weight: .medium))
|
|
.foregroundStyle(Tj.Palette.text3)
|
|
}
|
|
.padding(14)
|
|
.tjCard()
|
|
}
|
|
|
|
private var profileLine: String {
|
|
guard let p = profile, p.hasAnyBasics else {
|
|
return "点这里完善你的资料"
|
|
}
|
|
return p.summaryLine
|
|
}
|
|
}
|
|
|
|
#Preview {
|
|
MeView()
|
|
.modelContainer(for: [
|
|
UserProfile.self, Indicator.self, Report.self, DiaryEntry.self,
|
|
Asset.self, ChatTurn.self, Symptom.self,
|
|
], inMemory: true)
|
|
}
|