feat(capture): 统一报告捕获流程并集成视觉语言模型识别
- 替换 QuickCaptureFlow 和 ArchiveFlow 为 UnifiedCaptureFlow 统一流程 - 新增 VLSession 封装 Qwen2.5-VL 模型进行图像文本推理 - 实现 AIRuntime 中 VL 模型的准备和分析功能 - 添加 VLPrompts 定义体检化验单识别的 JSON 输出模板 - 创建 CaptureReviewForm 提供 VL 解析结果的可编辑表单界面 - 集成 VisionKit 文档扫描器支持真机多页文档扫描 - 为模拟器实现 PhotosPicker 回退方案选择已有照片 - 在 RootView 中统一使用 UnifiedCaptureFlow 处理快速和归档流程 - 添加 CustomMetricEditor 支持自定义监测指标的创建编辑删除 - 扩展 KangkangApp 模型配置以支持新数据类型 - 实现档案列表中症状结束功能通过时间线行点击触发
This commit is contained in:
68
康康/Features/Capture/DocumentScanner.swift
Normal file
68
康康/Features/Capture/DocumentScanner.swift
Normal file
@@ -0,0 +1,68 @@
|
||||
import SwiftUI
|
||||
import VisionKit
|
||||
import UIKit
|
||||
|
||||
#if canImport(VisionKit) && os(iOS)
|
||||
|
||||
/// VisionKit 文档扫描器的 SwiftUI 包装。
|
||||
/// - 真机:全屏多页文档扫描,自动透视校正
|
||||
/// - 模拟器:`VNDocumentCameraViewController.isSupported == false`,
|
||||
/// 父 View 不要 present 这个,改走 PhotosPicker 回退(见 PhotoPickerSheet)
|
||||
struct DocumentScannerView: UIViewControllerRepresentable {
|
||||
let onFinish: ([UIImage]) -> Void
|
||||
let onCancel: () -> Void
|
||||
|
||||
func makeUIViewController(context: Context) -> VNDocumentCameraViewController {
|
||||
let vc = VNDocumentCameraViewController()
|
||||
vc.delegate = context.coordinator
|
||||
return vc
|
||||
}
|
||||
|
||||
func updateUIViewController(_ uiViewController: VNDocumentCameraViewController,
|
||||
context: Context) {}
|
||||
|
||||
func makeCoordinator() -> Coordinator {
|
||||
Coordinator(onFinish: onFinish, onCancel: onCancel)
|
||||
}
|
||||
|
||||
final class Coordinator: NSObject, VNDocumentCameraViewControllerDelegate {
|
||||
let onFinish: ([UIImage]) -> Void
|
||||
let onCancel: () -> Void
|
||||
|
||||
init(onFinish: @escaping ([UIImage]) -> Void,
|
||||
onCancel: @escaping () -> Void) {
|
||||
self.onFinish = onFinish
|
||||
self.onCancel = onCancel
|
||||
}
|
||||
|
||||
func documentCameraViewController(
|
||||
_ controller: VNDocumentCameraViewController,
|
||||
didFinishWith scan: VNDocumentCameraScan
|
||||
) {
|
||||
var images: [UIImage] = []
|
||||
for i in 0..<scan.pageCount {
|
||||
images.append(scan.imageOfPage(at: i))
|
||||
}
|
||||
onFinish(images)
|
||||
}
|
||||
|
||||
func documentCameraViewControllerDidCancel(
|
||||
_ controller: VNDocumentCameraViewController
|
||||
) {
|
||||
onCancel()
|
||||
}
|
||||
|
||||
func documentCameraViewController(
|
||||
_ controller: VNDocumentCameraViewController,
|
||||
didFailWithError error: Error
|
||||
) {
|
||||
onCancel()
|
||||
}
|
||||
}
|
||||
|
||||
static var isSupported: Bool {
|
||||
VNDocumentCameraViewController.isSupported
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user