主体:多语言支持(简体中文源 + 英/日/韩)
- 基础设施:Localizable.xcstrings(String Catalog,sourceLanguage=zh-Hans)
+ pbxproj developmentRegion/knownRegions 注册 en/ja/ko
- 全部硬编码 Locale("zh_CN") → Locale.current;中文 dateFormat → Date.FormatStyle(跟随系统)
- UI 中文字面量统一为 String(appLoc:)(显式绑定所选语言 bundle+locale,即时切换)
Text 字面量走环境 \.locale + Bundle 重定向
- 549 个 catalog key 全部 en/ja/ko 翻译完成(0 未翻译)
- App 内语言切换:我的 → 语言(LanguageManager + 即时生效,无需重启)
- 双用预设(症状/监测指标/慢病)本地化:static→computed 避免缓存
注:本提交为 WIP,一并打包了并行进行的功能模块
(HealthExport 健康导出、Security/Face ID 锁、DiaryAssist 日记 AI 辅助)
及 App 图标、CLAUDE.md、docs/scripts。
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
218 lines
7.7 KiB
Swift
218 lines
7.7 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]
|
|
|
|
@Query(sort: \HealthExport.createdAt, order: .reverse)
|
|
private var exports: [HealthExport]
|
|
|
|
@State private var filter: TimelineKind? = nil
|
|
@State private var endingSymptom: Symptom?
|
|
@State private var showExportSheet = false
|
|
@State private var showExportList = false
|
|
|
|
@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 {
|
|
NavigationStack {
|
|
content
|
|
.navigationDestination(isPresented: $showExportList) {
|
|
HealthExportListView()
|
|
}
|
|
}
|
|
}
|
|
|
|
private var content: 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)
|
|
}
|
|
.fullScreenCover(isPresented: $showExportSheet) {
|
|
HealthExportSheet()
|
|
}
|
|
}
|
|
|
|
@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 ? "" : String(appLoc: "\(totalCount) 条"))
|
|
.font(.system(size: 12))
|
|
.foregroundStyle(Tj.Palette.text3)
|
|
Spacer()
|
|
Menu {
|
|
Button {
|
|
showExportSheet = true
|
|
} label: {
|
|
Label("生成新导出", systemImage: "doc.text.below.ecg")
|
|
}
|
|
if !exports.isEmpty {
|
|
Button {
|
|
showExportList = true
|
|
} label: {
|
|
Label("我的导出 · \(exports.count) 份", systemImage: "clock.arrow.circlepath")
|
|
}
|
|
}
|
|
} label: {
|
|
HStack(spacing: 6) {
|
|
Image(systemName: "doc.text.below.ecg")
|
|
.font(.system(size: 12, weight: .semibold))
|
|
Text("导出")
|
|
.font(.system(size: 13, weight: .semibold))
|
|
Image(systemName: "chevron.down")
|
|
.font(.system(size: 9, weight: .semibold))
|
|
}
|
|
.foregroundStyle(Tj.Palette.paper)
|
|
.padding(.horizontal, 12)
|
|
.padding(.vertical, 7)
|
|
.background(Capsule().fill(Tj.Palette.ink))
|
|
}
|
|
}
|
|
}
|
|
|
|
private var filterChips: some View {
|
|
ScrollView(.horizontal, showsIndicators: false) {
|
|
HStack(spacing: 8) {
|
|
chip(label: String(appLoc: "全部"), 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: String(appLoc: "还没有任何记录\n点底部 + 号开始"))
|
|
.frame(width: 240, height: 140)
|
|
Text(filter == nil ? String(appLoc: "记录会按时间归类显示") : String(appLoc: "这个类别下没有记录"))
|
|
.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,
|
|
HealthExport.self, ChatTurn.self, UserProfile.self,
|
|
MetricReminder.self, CustomMonitorMetric.self
|
|
], inMemory: true)
|
|
}
|