Files
kangkang/康康/RootView.swift
link2026 adb589af16 feat(quick): 异常项快拍改为局部小框 + VL 识别
将「异常项快拍」从复用整页报告归档流程,改造成独立的局部识别路径:
小框拍局部 → Qwen-VL 只抽 indicators → 用户确认逐项编辑 → 存成独立
Indicator(不建 Report、不留原图,与「记录指标」统一落库)。

- RegionCameraView: AVFoundation 实时预览 + 居中小框,快门后按
  metadataOutputRectConverted 裁剪到框内区域;含裁剪纯函数与权限态。
- VLPrompts.regionExtraction(): 局部识别 prompt,严格 JSON 只要 indicators。
- CaptureService.recognizeRegion(): 临时文件推理后即删,不写 Vault;
  新增 parseIndicatorsJSON / extractBalancedJSON 解析容错。
- QuickRegionConfirmView: 异常项高亮置顶、默认勾选,可编辑/增删/选纳入。
- QuickRegionCaptureFlow: 状态机 idle→analyzing→confirm,30s 超时回退手动。
- RootView: .quick 路由改指向新流程(.archive 仍走 UnifiedCaptureFlow)。
- 删除 5 个无引用的旧 mockup(A1/A2/A3/SmartFramer/QuickCaptureFlow)。

模拟器无相机退化为相册整图;小框裁剪坐标需真机验证。
设计见 docs/superpowers/specs/2026-05-31-abnormal-quick-capture-design.md

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-05-31 17:12:36 +08:00

235 lines
7.8 KiB
Swift

import SwiftUI
enum TjTab: String, Hashable, CaseIterable {
case home, records, trend, me
var label: String {
switch self {
case .home: return String(appLoc: "主页")
case .records: return String(appLoc: "记录")
case .trend: return String(appLoc: "趋势")
case .me: return String(appLoc: "我的")
}
}
var icon: String {
switch self {
case .home: return "house"
case .records: return "list.bullet.rectangle"
case .trend: return "chart.line.uptrend.xyaxis"
case .me: return "person.circle"
}
}
/// , push
var index: Int {
switch self {
case .home: return 0
case .records: return 1
case .trend: return 2
case .me: return 3
}
}
}
enum ActiveFlow: Identifiable {
case quick, archive
var id: String { String(describing: self) }
}
struct RootView: View {
@State private var tab: TjTab = .home
/// push : tab trailing , leading
@State private var pushEdge: Edge = .trailing
@State private var showRecordSheet = false
@State private var activeFlow: ActiveFlow?
@State private var showSymptomStart = false
@State private var showDiary = false
@State private var showIndicator = false
@State private var showReminders = false
/// tab : pushEdge, tab
/// tab ,
private func select(_ newTab: TjTab) {
guard newTab != tab else { return }
pushEdge = newTab.index > tab.index ? .trailing : .leading
withAnimation(.easeInOut(duration: 0.26)) { tab = newTab }
}
var body: some View {
VStack(spacing: 0) {
Group {
switch tab {
case .home: HomeView(onTapArchive: { select(.records) })
case .records: ArchiveListView()
case .trend: TrendsView()
case .me: MeView()
}
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
.id(tab)
.transition(.push(from: pushEdge))
TabBar(active: tab,
onTap: { select($0) },
onTapRecord: { showRecordSheet = true })
}
.background(Tj.Palette.sand.ignoresSafeArea())
.sheet(isPresented: $showRecordSheet) {
RecordSheet { kind in
showRecordSheet = false
DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
switch kind {
case .quick: activeFlow = .quick
case .archive: activeFlow = .archive
case .symptom: showSymptomStart = true
case .diary: showDiary = true
case .indicator: showIndicator = true
case .reminder: showReminders = true
}
}
}
}
.sheet(isPresented: $showSymptomStart) {
SymptomStartSheet()
}
.sheet(isPresented: $showDiary) {
DiaryQuickSheet()
}
.sheet(isPresented: $showIndicator) {
IndicatorQuickSheet()
}
.sheet(isPresented: $showReminders) {
// NavigationStack ;sheet
NavigationStack { RemindersListView(presentedAsSheet: true) }
}
#if os(iOS)
.fullScreenCover(item: $activeFlow) { flow in
switch flow {
case .quick:
QuickRegionCaptureFlow(onClose: { activeFlow = nil })
case .archive:
UnifiedCaptureFlow(onClose: { activeFlow = nil })
}
}
#else
.sheet(item: $activeFlow) { flow in
switch flow {
case .quick:
QuickRegionCaptureFlow(onClose: { activeFlow = nil })
case .archive:
UnifiedCaptureFlow(onClose: { activeFlow = nil })
}
}
#endif
}
}
private struct TabBar: View {
let active: TjTab
let onTap: (TjTab) -> Void
let onTapRecord: () -> Void
@Namespace private var indicatorNS
private let cornerRadius: CGFloat = 22
private let slotHeight: CGFloat = 34
var body: some View {
HStack(alignment: .bottom, spacing: 0) {
tabItem(.home)
tabItem(.records)
recordSlot
tabItem(.trend)
tabItem(.me)
}
.padding(.horizontal, 4)
.padding(.top, 10)
.padding(.bottom, 6)
.background(barBackground)
.animation(.spring(response: 0.35, dampingFraction: 0.75), value: active)
}
private var barBackground: some View {
UnevenRoundedRectangle(
topLeadingRadius: cornerRadius,
bottomLeadingRadius: 0,
bottomTrailingRadius: 0,
topTrailingRadius: cornerRadius,
style: .continuous
)
.fill(Tj.Palette.paper)
.overlay(alignment: .top) {
Rectangle()
.fill(Tj.Palette.lineSoft)
.frame(height: 1)
}
.shadow(color: Tj.Palette.ink.opacity(0.05), radius: 10, x: 0, y: -2)
}
private func tabItem(_ t: TjTab) -> some View {
let isActive = active == t
return Button { onTap(t) } label: {
VStack(spacing: 4) {
ZStack {
if isActive {
Capsule()
.fill(Tj.Palette.sand2)
.frame(width: 44, height: slotHeight - 6)
.matchedGeometryEffect(id: "tabIndicator", in: indicatorNS)
}
Image(systemName: t.icon)
.font(.system(size: 18, weight: isActive ? .semibold : .regular))
}
.frame(width: 50, height: slotHeight)
Text(t.label)
.font(.system(size: 11, weight: isActive ? .semibold : .regular))
}
.foregroundStyle(isActive ? Tj.Palette.ink : Tj.Palette.text3)
.frame(maxWidth: .infinity)
.contentShape(Rectangle())
}
.buttonStyle(TabPressStyle())
}
private var recordSlot: some View {
Button(action: onTapRecord) {
VStack(spacing: 4) {
ZStack {
Circle()
.fill(Tj.Palette.ink)
.overlay(
Circle()
.strokeBorder(Tj.Palette.paper, lineWidth: 2)
)
.shadow(color: Tj.Palette.ink.opacity(0.18),
radius: 4, x: 0, y: 2)
Image(systemName: "plus")
.font(.system(size: 16, weight: .semibold))
.foregroundStyle(Tj.Palette.paper)
}
.frame(width: slotHeight, height: slotHeight)
Text("新建")
.font(.system(size: 11, weight: .semibold))
.foregroundStyle(Tj.Palette.ink)
}
.frame(maxWidth: .infinity)
.contentShape(Rectangle())
}
.buttonStyle(TabPressStyle())
}
}
//
private struct TabPressStyle: ButtonStyle {
func makeBody(configuration: Configuration) -> some View {
configuration.label
.scaleEffect(configuration.isPressed ? 0.92 : 1.0)
.animation(.spring(response: 0.25, dampingFraction: 0.7),
value: configuration.isPressed)
}
}
#Preview {
RootView()
}