import SwiftUI enum RecordKind: String, Identifiable, CaseIterable { case quick, indicator, archive, diary, symptom var id: String { rawValue } var title: String { switch self { case .quick: return "异常项快拍" case .indicator: return "指标记录" case .archive: return "关键报告归档" case .diary: return "文字日记" case .symptom: return "症状开始" } } var subtitle: String { switch self { case .quick: return "拍一张化验单,VL 自动识别" case .indicator: return "手动填一项指标(免拍照)" case .archive: return "完整保存整份报告(可多页)" case .diary: return "记录心情、用药、其他" case .symptom: return "开始一个持续症状,结束时再点结束" } } var icon: String { switch self { case .quick: return "camera.fill" case .indicator: return "number.square.fill" case .archive: return "doc.fill" case .diary: return "pencil" case .symptom: return "waveform.path.ecg" } } var accent: Color { switch self { case .quick: return Tj.Palette.brick case .indicator: return Tj.Palette.brick case .archive: return Tj.Palette.ink case .diary: return Tj.Palette.leaf case .symptom: return Tj.Palette.amber } } } struct RecordSheet: View { var onPick: (RecordKind) -> Void var body: some View { VStack(spacing: 0) { Capsule() .fill(Tj.Palette.line) .frame(width: 40, height: 4) .padding(.top, 10) .padding(.bottom, 16) HStack { Text("记录什么?") .font(.tjH2()) .foregroundStyle(Tj.Palette.text) Spacer() Text("本地处理 · 永不上传") .font(.system(size: 12)) .foregroundStyle(Tj.Palette.text3) } .padding(.bottom, 14) VStack(spacing: 10) { ForEach(RecordKind.allCases) { kind in Button { onPick(kind) } label: { HStack(spacing: 14) { ZStack { RoundedRectangle(cornerRadius: Tj.Radius.sm, style: .continuous) .fill(kind.accent) Image(systemName: kind.icon) .font(.system(size: 18, weight: .medium)) .foregroundStyle(Tj.Palette.paper) } .frame(width: 44, height: 44) VStack(alignment: .leading, spacing: 2) { Text(kind.title) .font(.system(size: 15, weight: .semibold)) .foregroundStyle(Tj.Palette.text) Text(kind.subtitle) .font(.system(size: 12)) .foregroundStyle(Tj.Palette.text3) } Spacer() Image(systemName: "chevron.right") .font(.system(size: 14, weight: .medium)) .foregroundStyle(Tj.Palette.text3) } .padding(16) .tjCard() } .buttonStyle(.plain) } } .padding(.bottom, 22) } .padding(.horizontal, 18) .background( Tj.Palette.sand .clipShape(RoundedRectangle(cornerRadius: Tj.Radius.xl, style: .continuous)) .ignoresSafeArea(edges: .bottom) ) .presentationDetents([.fraction(0.8)]) .presentationDragIndicator(.hidden) .presentationBackground(Tj.Palette.sand) .presentationCornerRadius(Tj.Radius.xl) } } #Preview("RecordSheet · 直接渲染") { RecordSheet { kind in print("picked: \(kind)") } .frame(width: 390, height: 560) .background(Tj.Palette.sand) } #Preview("RecordSheet · sheet 模式") { PreviewContainer() } private struct PreviewContainer: View { @State private var show = true var body: some View { Text("点这里再开一次") .onTapGesture { show = true } .frame(maxWidth: .infinity, maxHeight: .infinity) .background(Tj.Palette.sand.ignoresSafeArea()) .sheet(isPresented: $show) { RecordSheet { kind in print("picked: \(kind)"); show = false } } } }