// // ContentView.swift // MyQrCode // // Created by dev on 2025/8/19. // import SwiftUI struct ContentView: View { @StateObject private var languageManager = LanguageManager.shared @State private var showScanner = false @State private var scannedResult: String? var body: some View { NavigationView { VStack(spacing: 30) { // 应用图标 Image(systemName: "qrcode.viewfinder") .font(.system(size: 100)) .foregroundColor(.blue) // 标题 Text("app_title".localized) .font(.largeTitle) .fontWeight(.bold) .multilineTextAlignment(.center) // 描述 Text("app_description".localized) .font(.body) .foregroundColor(.secondary) .multilineTextAlignment(.center) .padding(.horizontal) // 扫描按钮 Button(action: { showScanner = true }) { HStack { Image(systemName: "camera.fill") Text("start_scanning".localized) } .font(.title2) .foregroundColor(.white) .padding() .frame(maxWidth: .infinity) .background(Color.blue) .cornerRadius(15) } .padding(.horizontal, 40) // 测试日志按钮 Button(action: { testLogging() }) { HStack { Image(systemName: "doc.text.fill") Text("测试日志系统") } .font(.title3) .foregroundColor(.white) .padding() .frame(maxWidth: .infinity) .background(Color.green) .cornerRadius(10) } .padding(.horizontal, 60) // 语言选择器 HStack { Text("language".localized) .font(.headline) Picker("language".localized, selection: $languageManager.currentLanguage) { ForEach(Language.allCases, id: \.self) { language in Text(language.displayName).tag(language) } } .pickerStyle(SegmentedPickerStyle()) } .padding(.horizontal, 40) // 扫描结果显示 if let result = scannedResult { VStack(spacing: 10) { Text("scan_result".localized) .font(.headline) .foregroundColor(.green) Text(result) .font(.body) .padding() .background(Color.gray.opacity(0.1)) .cornerRadius(10) .multilineTextAlignment(.center) } .padding(.horizontal, 40) } Spacer() } .padding() .navigationTitle("MyQrCode") .navigationBarTitleDisplayMode(.inline) } .sheet(isPresented: $showScanner) { ScannerView() } .onReceive(NotificationCenter.default.publisher(for: .scannerDidScanCode)) { notification in if let result = notification.object as? String { scannedResult = result } } .onAppear { // 设置默认语言 languageManager.currentLanguage = .english } } private func testLogging() { logDebug("这是一条调试日志", className: "ContentView") logInfo("这是一条信息日志", className: "ContentView") logWarning("这是一条警告日志", className: "ContentView") logError("这是一条错误日志", className: "ContentView") logSuccess("这是一条成功日志", className: "ContentView") } } #if DEBUG struct ContentView_Previews: PreviewProvider { static var previews: some View { ContentView() } } #endif