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.
101 lines
3.3 KiB
101 lines
3.3 KiB
//
|
|
// ContentView.swift
|
|
// MyQrCode
|
|
//
|
|
// Created by dev on 2025/8/19.
|
|
//
|
|
|
|
import SwiftUI
|
|
|
|
struct ContentView: View {
|
|
@State private var showScanner = false
|
|
@State private var scannedCode: String?
|
|
@State private var showLanguageSettings = false
|
|
@ObservedObject private var languageManager = LanguageManager.shared
|
|
|
|
var body: some View {
|
|
NavigationView {
|
|
VStack(spacing: 30) {
|
|
HStack {
|
|
Spacer()
|
|
Button(action: {
|
|
showLanguageSettings = true
|
|
}) {
|
|
HStack(spacing: 4) {
|
|
Text(languageManager.currentLanguage.flag)
|
|
Text(languageManager.currentLanguage.displayName)
|
|
.font(.caption)
|
|
}
|
|
.padding(.horizontal, 12)
|
|
.padding(.vertical, 6)
|
|
.background(Color.blue.opacity(0.1))
|
|
.cornerRadius(15)
|
|
}
|
|
}
|
|
.padding(.horizontal)
|
|
|
|
Image(systemName: "qrcode.viewfinder")
|
|
.font(.system(size: 100))
|
|
.foregroundColor(.blue)
|
|
|
|
Text("main_title".localized)
|
|
.font(.largeTitle)
|
|
.fontWeight(.bold)
|
|
|
|
if let code = scannedCode {
|
|
VStack(spacing: 10) {
|
|
Text("scan_result".localized)
|
|
.font(.headline)
|
|
Text(code)
|
|
.font(.body)
|
|
.padding()
|
|
.background(Color.gray.opacity(0.1))
|
|
.cornerRadius(8)
|
|
}
|
|
}
|
|
|
|
Button(action: {
|
|
showScanner = true
|
|
}) {
|
|
HStack {
|
|
Image(systemName: "camera")
|
|
Text("start_scan_button".localized)
|
|
}
|
|
.font(.title2)
|
|
.foregroundColor(.white)
|
|
.padding()
|
|
.background(Color.blue)
|
|
.cornerRadius(10)
|
|
}
|
|
|
|
Spacer()
|
|
}
|
|
.padding()
|
|
.navigationTitle("app_title".localized)
|
|
.sheet(isPresented: $showScanner) {
|
|
ScannerView()
|
|
.onReceive(NotificationCenter.default.publisher(for: .scannerDidScanCode)) { notification in
|
|
if let code = notification.object as? String {
|
|
scannedCode = code
|
|
showScanner = false
|
|
}
|
|
}
|
|
}
|
|
.sheet(isPresented: $showLanguageSettings) {
|
|
LanguageSettingsView()
|
|
}
|
|
.onReceive(NotificationCenter.default.publisher(for: .languageChanged)) { _ in
|
|
// 语言变化时刷新界面
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
#if DEBUG
|
|
struct ContentView_Previews: PreviewProvider {
|
|
static var previews: some View {
|
|
ContentView()
|
|
}
|
|
}
|
|
#endif
|