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.
217 lines
7.1 KiB
217 lines
7.1 KiB
import SwiftUI
|
|
|
|
// MARK: - 输入组件工厂
|
|
struct InputComponentFactory {
|
|
|
|
// 根据QR码类型返回相应的输入组件
|
|
static func createInputComponent(
|
|
for qrCodeType: QRCodeType,
|
|
content: Binding<String>,
|
|
emailAddress: Binding<String>,
|
|
emailSubject: Binding<String>,
|
|
emailBody: Binding<String>,
|
|
emailCc: Binding<String>,
|
|
emailBcc: Binding<String>,
|
|
focusedEmailField: FocusState<EmailInputView.EmailField?>,
|
|
isContentFieldFocused: FocusState<Bool>,
|
|
ssid: Binding<String>,
|
|
password: Binding<String>,
|
|
encryptionType: Binding<WiFiInputView.WiFiEncryptionType>,
|
|
focusedWiFiField: FocusState<WiFiInputView.WiFiField?>,
|
|
firstName: Binding<String>,
|
|
lastName: Binding<String>,
|
|
phone: Binding<String>,
|
|
email: Binding<String>,
|
|
company: Binding<String>,
|
|
title: Binding<String>,
|
|
address: Binding<String>,
|
|
website: Binding<String>,
|
|
focusedContactField: FocusState<ContactInputView.ContactField?>,
|
|
latitude: Binding<String>,
|
|
longitude: Binding<String>,
|
|
locationName: Binding<String>,
|
|
focusedLocationField: FocusState<LocationInputView.LocationField?>,
|
|
eventTitle: Binding<String>,
|
|
eventDescription: Binding<String>,
|
|
startDate: Binding<Date>,
|
|
endDate: Binding<Date>,
|
|
location: Binding<String>,
|
|
focusedCalendarField: FocusState<CalendarInputView.CalendarField?>,
|
|
username: Binding<String>,
|
|
message: Binding<String>,
|
|
focusedSocialField: FocusState<SocialInputView.SocialField?>,
|
|
phoneNumber: Binding<String>,
|
|
phoneMessage: Binding<String>,
|
|
focusedPhoneField: FocusState<PhoneInputView.PhoneField?>,
|
|
url: Binding<String>,
|
|
isUrlFieldFocused: FocusState<Bool>
|
|
) -> AnyView {
|
|
|
|
switch qrCodeType {
|
|
case .mail:
|
|
return AnyView(
|
|
EmailInputView(
|
|
emailAddress: emailAddress,
|
|
emailSubject: emailSubject,
|
|
emailBody: emailBody,
|
|
emailCc: emailCc,
|
|
emailBcc: emailBcc,
|
|
focusedEmailField: focusedEmailField
|
|
)
|
|
)
|
|
|
|
case .wifi:
|
|
return AnyView(
|
|
WiFiInputView(
|
|
ssid: ssid,
|
|
password: password,
|
|
encryptionType: encryptionType,
|
|
focusedField: focusedWiFiField
|
|
)
|
|
)
|
|
|
|
case .vcard, .mecard:
|
|
return AnyView(
|
|
ContactInputView(
|
|
firstName: firstName,
|
|
lastName: lastName,
|
|
phone: phone,
|
|
email: email,
|
|
company: company,
|
|
title: title,
|
|
address: address,
|
|
website: website,
|
|
focusedField: focusedContactField
|
|
)
|
|
)
|
|
|
|
case .location:
|
|
return AnyView(
|
|
LocationInputView(
|
|
latitude: latitude,
|
|
longitude: longitude,
|
|
locationName: locationName,
|
|
focusedField: focusedLocationField
|
|
)
|
|
)
|
|
|
|
case .calendar:
|
|
return AnyView(
|
|
CalendarInputView(
|
|
eventTitle: eventTitle,
|
|
eventDescription: eventDescription,
|
|
startDate: startDate,
|
|
endDate: endDate,
|
|
location: location
|
|
)
|
|
)
|
|
|
|
case .instagram, .facebook, .twitter, .tiktok, .snapchat, .whatsapp, .viber, .spotify:
|
|
let platform = SocialInputView.SocialPlatform(rawValue: qrCodeType.rawValue.capitalized) ?? .instagram
|
|
return AnyView(
|
|
SocialInputView(
|
|
username: username,
|
|
message: message,
|
|
platform: platform,
|
|
focusedField: focusedSocialField
|
|
)
|
|
)
|
|
|
|
case .phone, .sms:
|
|
let inputType: PhoneInputView.PhoneInputType = qrCodeType == .phone ? .phone : .sms
|
|
return AnyView(
|
|
PhoneInputView(
|
|
phoneNumber: phoneNumber,
|
|
message: phoneMessage,
|
|
inputType: inputType,
|
|
focusedField: focusedPhoneField
|
|
)
|
|
)
|
|
|
|
case .url:
|
|
return AnyView(
|
|
URLInputView(
|
|
url: url,
|
|
isUrlFieldFocused: isUrlFieldFocused
|
|
)
|
|
)
|
|
|
|
default:
|
|
// 默认使用通用文本输入组件
|
|
return AnyView(
|
|
TextInputView(
|
|
content: content,
|
|
isContentFieldFocused: isContentFieldFocused,
|
|
placeholder: getPlaceholderText(for: qrCodeType),
|
|
maxCharacters: getMaxCharacters(for: qrCodeType)
|
|
)
|
|
)
|
|
}
|
|
}
|
|
|
|
// 获取占位符文本
|
|
private static func getPlaceholderText(for qrCodeType: QRCodeType) -> String {
|
|
switch qrCodeType {
|
|
case .text:
|
|
return "输入任意文本内容..."
|
|
case .phone:
|
|
return "输入电话号码..."
|
|
case .sms:
|
|
return "输入短信内容..."
|
|
case .wifi:
|
|
return "输入WiFi信息..."
|
|
case .vcard:
|
|
return "输入联系人信息..."
|
|
case .mecard:
|
|
return "输入联系人信息..."
|
|
case .location:
|
|
return "输入地理位置..."
|
|
case .calendar:
|
|
return "输入日历事件信息..."
|
|
case .instagram:
|
|
return "输入Instagram信息..."
|
|
case .facebook:
|
|
return "输入Facebook信息..."
|
|
case .spotify:
|
|
return "输入Spotify信息..."
|
|
case .twitter:
|
|
return "输入Twitter信息..."
|
|
case .whatsapp:
|
|
return "输入WhatsApp信息..."
|
|
case .viber:
|
|
return "输入Viber信息..."
|
|
case .snapchat:
|
|
return "输入Snapchat信息..."
|
|
case .tiktok:
|
|
return "输入TikTok信息..."
|
|
case .mail:
|
|
return "输入邮件内容..."
|
|
case .url:
|
|
return "输入网址..."
|
|
}
|
|
}
|
|
|
|
// 获取最大字符数
|
|
private static func getMaxCharacters(for qrCodeType: QRCodeType) -> Int {
|
|
switch qrCodeType {
|
|
case .text:
|
|
return 150
|
|
case .phone, .sms:
|
|
return 100
|
|
case .wifi:
|
|
return 200
|
|
case .vcard, .mecard:
|
|
return 500
|
|
case .location:
|
|
return 200
|
|
case .calendar:
|
|
return 300
|
|
case .instagram, .facebook, .twitter, .tiktok, .snapchat, .whatsapp, .viber, .spotify:
|
|
return 200
|
|
case .mail:
|
|
return 1200
|
|
case .url:
|
|
return 500
|
|
}
|
|
}
|
|
} |