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.
130 lines
4.0 KiB
130 lines
4.0 KiB
import SwiftUI
|
|
|
|
// MARK: - WiFi输入组件
|
|
struct WiFiInputView: View {
|
|
@Binding var ssid: String
|
|
@Binding var password: String
|
|
@Binding var encryptionType: WiFiEncryptionType
|
|
@FocusState var focusedField: WiFiField?
|
|
|
|
// WiFi字段枚举
|
|
enum WiFiField: Hashable {
|
|
case ssid, password
|
|
}
|
|
|
|
// WiFi加密类型
|
|
enum WiFiEncryptionType: String, CaseIterable, Identifiable {
|
|
case none = "None"
|
|
case wep = "WEP"
|
|
case wpa = "WPA"
|
|
case wpa2 = "WPA2"
|
|
case wpa3 = "WPA3"
|
|
|
|
var id: String { rawValue }
|
|
|
|
var displayName: String {
|
|
switch self {
|
|
case .none: return "无加密"
|
|
case .wep: return "WEP"
|
|
case .wpa: return "WPA"
|
|
case .wpa2: return "WPA2"
|
|
case .wpa3: return "WPA3"
|
|
}
|
|
}
|
|
}
|
|
|
|
var body: some View {
|
|
VStack(spacing: 16) {
|
|
// SSID (必填)
|
|
VStack(alignment: .leading, spacing: 8) {
|
|
HStack {
|
|
Text("网络名称 (SSID)")
|
|
.font(.subheadline)
|
|
.foregroundColor(.primary)
|
|
Text("*")
|
|
.foregroundColor(.red)
|
|
Spacer()
|
|
}
|
|
|
|
TextField("MyWiFi", text: $ssid)
|
|
.textFieldStyle(RoundedBorderTextFieldStyle())
|
|
.focused($focusedField, equals: .ssid)
|
|
}
|
|
|
|
// 密码
|
|
VStack(alignment: .leading, spacing: 8) {
|
|
HStack {
|
|
Text("密码")
|
|
.font(.subheadline)
|
|
.foregroundColor(.primary)
|
|
Spacer()
|
|
}
|
|
|
|
SecureField("WiFi密码", text: $password)
|
|
.textFieldStyle(RoundedBorderTextFieldStyle())
|
|
.focused($focusedField, equals: .password)
|
|
}
|
|
|
|
// 加密类型
|
|
VStack(alignment: .leading, spacing: 8) {
|
|
HStack {
|
|
Text("加密类型")
|
|
.font(.subheadline)
|
|
.foregroundColor(.primary)
|
|
Spacer()
|
|
}
|
|
|
|
Picker("加密类型", selection: $encryptionType) {
|
|
ForEach(WiFiEncryptionType.allCases) { type in
|
|
Text(type.displayName).tag(type)
|
|
}
|
|
}
|
|
.pickerStyle(SegmentedPickerStyle())
|
|
}
|
|
|
|
// 格式说明
|
|
VStack(alignment: .leading, spacing: 8) {
|
|
HStack {
|
|
Image(systemName: "info.circle")
|
|
.font(.caption)
|
|
.foregroundColor(.blue)
|
|
|
|
Text("格式说明")
|
|
.font(.caption)
|
|
.foregroundColor(.primary)
|
|
|
|
Spacer()
|
|
}
|
|
|
|
Text("• 网络名称(SSID)为必填项\n• 密码为可选项,无加密时可留空\n• 将生成标准WiFi连接格式")
|
|
.font(.caption)
|
|
.foregroundColor(.secondary)
|
|
.lineLimit(nil)
|
|
}
|
|
.padding(.horizontal, 12)
|
|
.padding(.vertical, 8)
|
|
.background(
|
|
RoundedRectangle(cornerRadius: 8)
|
|
.fill(Color.blue.opacity(0.1))
|
|
)
|
|
}
|
|
.toolbar {
|
|
ToolbarItemGroup(placement: .keyboard) {
|
|
Spacer()
|
|
Button("完成") {
|
|
focusedField = nil
|
|
}
|
|
.foregroundColor(.blue)
|
|
.font(.system(size: 16, weight: .medium))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
#Preview {
|
|
WiFiInputView(
|
|
ssid: .constant(""),
|
|
password: .constant(""),
|
|
encryptionType: .constant(.wpa2)
|
|
)
|
|
} |