import SwiftUI // MARK: - 扫描界面覆盖层 struct ScanningOverlayView: View { let showPreviewPause: Bool @Binding var selectedStyle: ScanningLineStyle let detectedCodesCount: Int let onClose: () -> Void var body: some View { VStack { Spacer() // 扫描线组件 if !showPreviewPause { ScanningLineView(style: selectedStyle) } // 提示文本 ScanningInstructionView( showPreviewPause: showPreviewPause, detectedCodesCount: detectedCodesCount ) Spacer() // 底部按钮区域 ScanningBottomButtonsView( showPreviewPause: showPreviewPause, selectedStyle: $selectedStyle, onClose: onClose ) } } } // MARK: - 扫描指令视图 struct ScanningInstructionView: View { let showPreviewPause: Bool let detectedCodesCount: Int var body: some View { if showPreviewPause { VStack(spacing: 8) { Text("detected_codes".localized) .foregroundColor(.white) .font(.headline) if detectedCodesCount == 1 { Text("auto_result_1s".localized) .foregroundColor(.green) .font(.subheadline) } else { Text("select_code_instruction".localized) .foregroundColor(.white.opacity(0.8)) .font(.subheadline) } } .padding(.top, 20) } else { Text("scan_instruction".localized) .foregroundColor(.white) .font(.headline) .padding(.top, 20) } } } // MARK: - 扫描底部按钮视图 struct ScanningBottomButtonsView: View { let showPreviewPause: Bool @Binding var selectedStyle: ScanningLineStyle let onClose: () -> Void var body: some View { VStack(spacing: 15) { // 扫描线样式选择器 if !showPreviewPause { ScanningStyleSelectorView(selectedStyle: $selectedStyle) } // 关闭按钮 - 只在非预览选择状态时显示 if !showPreviewPause { Button("close_button".localized) { onClose() } .foregroundColor(.white) .padding() .background(Color.black.opacity(0.6)) .cornerRadius(10) } } .padding(.bottom, 50) } } // MARK: - 扫描线样式选择器 struct ScanningStyleSelectorView: View { @Binding var selectedStyle: ScanningLineStyle var body: some View { HStack(spacing: 10) { ForEach(ScanningLineStyle.allCases, id: \.self) { style in Button(style.localizedName) { selectedStyle = style } .foregroundColor(.white) .padding(.horizontal, 8) .padding(.vertical, 4) .background(selectedStyle == style ? Color.green : Color.gray.opacity(0.6)) .cornerRadius(8) .font(.caption) } } .padding(.bottom, 10) } }