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以扩大点击区域 - 修复提醒行展开按钮尺寸,保证不同提醒类型的垂直对齐 ```
258 lines
9.2 KiB
Swift
258 lines
9.2 KiB
Swift
import SwiftUI
|
|
import SwiftData
|
|
|
|
struct MeView: View {
|
|
@Environment(\.modelContext) private var ctx
|
|
@Query private var profiles: [UserProfile]
|
|
@Query private var customMetrics: [CustomMonitorMetric]
|
|
|
|
@State private var downloadService = ModelDownloadService.shared
|
|
@State private var appLock = AppLock.shared
|
|
@State private var lang = LanguageManager.shared
|
|
// key 必须与 AppLock.enabledKey 一致。
|
|
@AppStorage("faceIDLockEnabled") private var lockEnabled = false
|
|
|
|
private var profile: UserProfile? { profiles.first }
|
|
|
|
/// 真实读取 Bundle 版本号,与「关于」页保持一致。
|
|
private var appVersionText: String {
|
|
let short = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? "0.1"
|
|
return "v\(short)"
|
|
}
|
|
|
|
var body: some View {
|
|
NavigationStack {
|
|
ScrollView {
|
|
VStack(spacing: 12) {
|
|
HStack {
|
|
Text("我的")
|
|
.font(.tjTitle())
|
|
.foregroundStyle(Tj.Palette.text)
|
|
Spacer()
|
|
}
|
|
.padding(.top, 4)
|
|
.padding(.bottom, 6)
|
|
|
|
profileCard
|
|
customMetricsCard
|
|
modelManagementCard
|
|
languageCard
|
|
faceIDCard
|
|
NavigationLink {
|
|
AboutView()
|
|
} label: {
|
|
settingsCard(title: String(appLoc: "关于"),
|
|
detail: appVersionText,
|
|
icon: "info.circle")
|
|
}
|
|
.buttonStyle(.plain)
|
|
}
|
|
.padding(.horizontal, 16)
|
|
.padding(.vertical, 20)
|
|
}
|
|
.background(Tj.Palette.sand.ignoresSafeArea())
|
|
// 标题改用内容文字渲染(与 主页/记录/趋势 一致),不走 .navigationTitle:
|
|
// 大标题导航栏在真机状态栏区域会露出系统白底,破坏全 App 的沙色背景。
|
|
.onAppear {
|
|
if profiles.isEmpty {
|
|
_ = UserProfileStore.loadOrCreate(in: ctx)
|
|
}
|
|
downloadService.refreshStates()
|
|
appLock.refreshAvailability()
|
|
}
|
|
}
|
|
}
|
|
|
|
// 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 var customMetricsCard: some View {
|
|
NavigationLink {
|
|
CustomMetricsListView()
|
|
} label: {
|
|
HStack(spacing: 12) {
|
|
ZStack {
|
|
Circle()
|
|
.fill(customMetrics.isEmpty ? Tj.Palette.sand2 : Tj.Palette.leafSoft)
|
|
Image(systemName: "slider.horizontal.3")
|
|
.font(.system(size: 18))
|
|
.foregroundStyle(customMetrics.isEmpty ? Tj.Palette.text2 : 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(customMetricsLine)
|
|
.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 var customMetricsLine: String {
|
|
if customMetrics.isEmpty { return String(appLoc: "添加你自己的长期监测项") }
|
|
return String(appLoc: "\(customMetrics.count) 项")
|
|
}
|
|
|
|
private var modelManagementCard: some View {
|
|
NavigationLink {
|
|
ModelManagementView()
|
|
} label: {
|
|
settingsCard(title: String(appLoc: "模型管理"), detail: modelDetail, icon: "cpu")
|
|
}
|
|
.buttonStyle(.plain)
|
|
}
|
|
|
|
private var modelDetail: String {
|
|
let states = downloadService.states
|
|
if ModelKind.allCases.allSatisfy({ states[$0]?.phase == .ready }) { return String(appLoc: "已就绪") }
|
|
if downloadService.isAnyDownloading { return String(appLoc: "下载中…") }
|
|
let readyCount = ModelKind.allCases.filter { states[$0]?.phase == .ready }.count
|
|
return readyCount == 0 ? String(appLoc: "未下载") : String(appLoc: "\(readyCount)/\(ModelKind.allCases.count) 就绪")
|
|
}
|
|
|
|
private var languageCard: some View {
|
|
NavigationLink {
|
|
LanguageSettingsView()
|
|
} label: {
|
|
settingsCard(title: String(appLoc: "语言"),
|
|
detail: lang.current.displayName,
|
|
icon: "character.bubble")
|
|
}
|
|
.buttonStyle(.plain)
|
|
}
|
|
|
|
// MARK: - Face ID 启动锁(可交互 Toggle 卡)
|
|
|
|
private var faceIDCard: some View {
|
|
HStack(spacing: 12) {
|
|
ZStack {
|
|
Circle().fill(lockEnabled ? Tj.Palette.amber.opacity(0.25) : Tj.Palette.sand2)
|
|
Image(systemName: "faceid")
|
|
.font(.system(size: 18))
|
|
.foregroundStyle(lockEnabled ? Tj.Palette.ink : Tj.Palette.text2)
|
|
}
|
|
.frame(width: 44, height: 44)
|
|
|
|
VStack(alignment: .leading, spacing: 2) {
|
|
Text("Face ID 启动锁")
|
|
.font(.system(size: 15, weight: .medium))
|
|
.foregroundStyle(Tj.Palette.text)
|
|
Text(faceIDLine)
|
|
.font(.system(size: 12))
|
|
.foregroundStyle(Tj.Palette.text3)
|
|
}
|
|
Spacer()
|
|
Toggle("", isOn: faceIDBinding)
|
|
.labelsHidden()
|
|
.disabled(!appLock.biometryAvailable)
|
|
}
|
|
.padding(14)
|
|
.tjCard()
|
|
}
|
|
|
|
private var faceIDLine: String {
|
|
if !appLock.biometryAvailable { return String(appLoc: "本设备未设置 Face ID 或密码") }
|
|
return lockEnabled ? String(appLoc: "已开启 · \(appLock.biometryLabel)") : String(appLoc: "关闭")
|
|
}
|
|
|
|
/// 打开 → 先认证一次,成功才置 enabled(失败则开关弹回);关闭 → 直接关。
|
|
private var faceIDBinding: Binding<Bool> {
|
|
Binding(
|
|
get: { lockEnabled },
|
|
set: { newValue in
|
|
if newValue {
|
|
Task { await appLock.enableWithAuth() }
|
|
} else {
|
|
appLock.disable()
|
|
}
|
|
}
|
|
)
|
|
}
|
|
|
|
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 String(appLoc: "点这里完善你的资料")
|
|
}
|
|
return p.summaryLine
|
|
}
|
|
}
|
|
|
|
#Preview {
|
|
MeView()
|
|
.modelContainer(for: [
|
|
UserProfile.self, Indicator.self, Report.self, DiaryEntry.self,
|
|
Asset.self, ChatTurn.self, Symptom.self, MetricReminder.self,
|
|
CustomMonitorMetric.self,
|
|
], inMemory: true)
|
|
}
|