import SwiftUI // MARK: - 数据类型选择界面 struct CodeTypeSelectionView: View { @State private var selectedDataType: DataType = .qrcode @State private var selectedBarcodeType: BarcodeType = .ean13 @State private var selectedQRCodeType: QRCodeType = .text var body: some View { VStack(spacing: 30) { // 数据类型选择 VStack(spacing: 20) { Text("数据类型") .font(.headline) .foregroundColor(.primary) .frame(maxWidth: .infinity, alignment: .leading) HStack(spacing: 0) { ForEach(DataType.allCases, id: \.self) { type in Button(action: { selectedDataType = type // 添加触觉反馈 let impactFeedback = UIImpactFeedbackGenerator(style: .light) impactFeedback.impactOccurred() }) { HStack(spacing: 6) { Image(systemName: type.icon) .font(.system(size: 16, weight: .medium)) .foregroundColor(selectedDataType == type ? .white : .primary) Text(type.displayName) .font(.system(size: 15, weight: .medium)) .foregroundColor(selectedDataType == type ? .white : .primary) } .frame(maxWidth: .infinity) .padding(.vertical, 12) .background( RoundedRectangle(cornerRadius: 8) .fill(selectedDataType == type ? Color.blue : Color(.systemGray6)) ) } .buttonStyle(PlainButtonStyle()) } } .background( RoundedRectangle(cornerRadius: 8) .fill(Color(.systemGray6)) ) .overlay( RoundedRectangle(cornerRadius: 8) .stroke(Color(.systemGray4), lineWidth: 0.5) ) } .padding(.horizontal, 20) // 具体类型选择 VStack(spacing: 20) { if selectedDataType == .barcode { VStack(spacing: 12) { Text("条形码类型") .font(.headline) .foregroundColor(.primary) .frame(maxWidth: .infinity, alignment: .leading) Picker("条形码类型", selection: $selectedBarcodeType) { ForEach(BarcodeType.allCases, id: \.self) { type in HStack { Image(systemName: type.icon) Text(type.displayName) } .tag(type) } } .pickerStyle(WheelPickerStyle()) } } else { VStack(spacing: 12) { Text("二维码类型") .font(.headline) .foregroundColor(.primary) .frame(maxWidth: .infinity, alignment: .leading) Picker("二维码类型", selection: $selectedQRCodeType) { ForEach(QRCodeType.allCases, id: \.self) { type in HStack { Image(systemName: type.icon) Text(type.displayName) } .tag(type) } } .pickerStyle(WheelPickerStyle()) } } } .padding(.horizontal, 20) Spacer() // 下一步按钮 NavigationLink( destination: CreateCodeView( selectedDataType: selectedDataType, selectedBarcodeType: selectedBarcodeType, selectedQRCodeType: selectedQRCodeType ) ) { HStack(spacing: 8) { Text("下一步") .font(.system(size: 18, weight: .semibold)) .foregroundColor(.white) Image(systemName: "arrow.right") .font(.system(size: 16, weight: .medium)) .foregroundColor(.white) } .frame(maxWidth: .infinity) .padding(.vertical, 16) .background( RoundedRectangle(cornerRadius: 12) .fill(Color.blue) ) } .padding(.horizontal, 20) .padding(.bottom, 30) } .navigationTitle("选择类型") .navigationBarTitleDisplayMode(.inline) } } #Preview { CodeTypeSelectionView() }