- Zwei-Finger-Pinch zoomt im Kamerabild naeher an einen Code heran (digital, auf Faktor 6 begrenzt). - Blitz geht nach dem ersten erfolgreichen Scan wieder aus. Per Langdruck auf den Blitz-Knopf bleibt er dauerhaft an (gesperrt, gelb); Tippen schaltet aus und hebt die Sperre auf. Gilt fuer alle Scan-Bildschirme. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
78 lines
2.9 KiB
Swift
78 lines
2.9 KiB
Swift
import SwiftUI
|
||
|
||
/// Nur ansehen: Barcode → Artikel, Einzelstück-QR → genau dieses Stück.
|
||
/// Kein Ein-/Auslagern – zum schnellen Nachschauen (z.B. wann gekauft, Garantie).
|
||
struct LookupScanView: View {
|
||
@Environment(\.dismiss) private var dismiss
|
||
@EnvironmentObject private var display: DisplaySettings
|
||
|
||
@State private var paused = false
|
||
@State private var torchOn = false
|
||
@State private var torchLocked = false
|
||
@State private var error: String?
|
||
@State private var item: Item?
|
||
@State private var product: Product?
|
||
|
||
var body: some View {
|
||
ScrollView {
|
||
VStack(spacing: 14) {
|
||
ScannerView(onCode: { code in Task { await resolve(code) } },
|
||
isPaused: $paused, torchOn: $torchOn, torchLocked: $torchLocked)
|
||
.aspectRatio(4.0 / 3.0, contentMode: .fit)
|
||
.clipShape(RoundedRectangle(cornerRadius: 16))
|
||
.padding(.horizontal)
|
||
|
||
Text("Barcode oder Einzelstück-QR scannen – nur ansehen")
|
||
.font(.caption).foregroundStyle(.secondary)
|
||
|
||
if let error {
|
||
Text(error).font(.callout).foregroundStyle(.red)
|
||
.frame(maxWidth: .infinity, alignment: .leading)
|
||
.padding(.horizontal)
|
||
}
|
||
}
|
||
.padding(.vertical)
|
||
}
|
||
.navigationTitle("Nachschlagen")
|
||
.navigationBarTitleDisplayMode(.inline)
|
||
.toolbar {
|
||
ToolbarItem(placement: .topBarLeading) { Button("Fertig") { dismiss() } }
|
||
ToolbarItem(placement: .topBarTrailing) { TorchButton(isOn: $torchOn, locked: $torchLocked) }
|
||
}
|
||
.sheet(item: $item, onDismiss: { paused = false }) { it in
|
||
NavigationStack { ItemEditView(item: it) }
|
||
}
|
||
.sheet(item: $product, onDismiss: { paused = false }) { p in
|
||
NavigationStack { ProductDetailView(product: p) }
|
||
.environmentObject(display)
|
||
}
|
||
}
|
||
|
||
private func resolve(_ code: String) async {
|
||
paused = true
|
||
error = nil
|
||
// Einzelstück-QR (…/i/<UID>)?
|
||
if let r = code.range(of: "/i/") {
|
||
let uid = String(code[r.upperBound...])
|
||
.trimmingCharacters(in: CharacterSet(charactersIn: "/ ")).uppercased()
|
||
if !uid.isEmpty, let found = try? await APIClient.shared.itemByUid(uid: uid) {
|
||
item = found
|
||
return
|
||
}
|
||
}
|
||
// Sonst als Barcode auflösen.
|
||
do {
|
||
let result = try await APIClient.shared.lookup(barcode: code)
|
||
if let existing = result.existingProduct {
|
||
product = existing
|
||
} else {
|
||
error = "Nicht im Katalog: \(code)"
|
||
paused = false
|
||
}
|
||
} catch {
|
||
self.error = error.localizedDescription
|
||
paused = false
|
||
}
|
||
}
|
||
}
|