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.
146 lines
5.0 KiB
146 lines
5.0 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 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)
|
|
|
|
// 扫描按钮 - 改为NavigationLink
|
|
NavigationLink(destination: ScannerView()) {
|
|
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)
|
|
|
|
// 历史记录按钮
|
|
NavigationLink(destination: HistoryView()) {
|
|
HStack {
|
|
Image(systemName: "clock.arrow.circlepath")
|
|
Text("历史记录")
|
|
}
|
|
.font(.title3)
|
|
.foregroundColor(.white)
|
|
.padding()
|
|
.frame(maxWidth: .infinity)
|
|
.background(Color.orange)
|
|
.cornerRadius(10)
|
|
}
|
|
.padding(.horizontal, 60)
|
|
|
|
// 测试日志按钮
|
|
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)
|
|
}
|
|
.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
|