You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

137 lines
4.6 KiB

//
// 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