import SwiftUI /// 锁屏:全遮罩,onAppear 自动触发一次认证;失败/取消后停留,可点按钮重试。 struct LockScreenView: View { @State private var appLock = AppLock.shared /// 认证按钮 / 图标随设备能力变化。 private var glyph: String { switch appLock.biometryLabel { case "Face ID": return "faceid" case "Touch ID": return "touchid" default: return "lock.fill" } } var body: some View { ZStack { Tj.Palette.sand.ignoresSafeArea() VStack(spacing: 18) { Spacer() ZStack { Circle() .fill(Tj.Palette.paper) .overlay(Circle().strokeBorder(Tj.Palette.line, lineWidth: 1)) Image(systemName: "lock.fill") .font(.system(size: 34)) .foregroundStyle(Tj.Palette.ink) } .frame(width: 92, height: 92) .shadow(color: Tj.Palette.ink.opacity(0.06), radius: 12, y: 4) VStack(spacing: 6) { Text("康康 已锁定") .font(.tjH2()) .foregroundStyle(Tj.Palette.text) Text("你的健康档案已加密保护") .font(.system(size: 13)) .foregroundStyle(Tj.Palette.text3) } Spacer() Button { Task { await appLock.authenticate() } } label: { Label("\(appLock.biometryLabel) 解锁", systemImage: glyph) .frame(maxWidth: .infinity) } .buttonStyle(TjPrimaryButton(height: 52, fontSize: 16)) .padding(.horizontal, 40) .padding(.bottom, 48) } } .onAppear { Task { await appLock.authenticate() } } } } /// 隐私遮罩:进任务切换器 / 后台时盖在内容之上,挡住多任务快照里的健康数据。 /// 无交互,纯品牌底。 struct PrivacyCoverView: View { var body: some View { ZStack { Tj.Palette.sand.ignoresSafeArea() VStack(spacing: 14) { ZStack { Circle() .fill(Tj.Palette.paper) .overlay(Circle().strokeBorder(Tj.Palette.line, lineWidth: 1)) Image(systemName: "heart.text.square.fill") .font(.system(size: 30)) .foregroundStyle(Tj.Palette.ink) } .frame(width: 80, height: 80) Text("康康") .font(.tjH2()) .foregroundStyle(Tj.Palette.text) } } } } #Preview("锁屏") { LockScreenView() } #Preview("隐私遮罩") { PrivacyCoverView() }