|
|
import SwiftUI
|
|
|
|
|
|
// MARK: - 邮件输入配置
|
|
|
struct EmailInputConfig {
|
|
|
let emailAddress: Binding<String>
|
|
|
let emailSubject: Binding<String>
|
|
|
let emailBody: Binding<String>
|
|
|
let emailCc: Binding<String>
|
|
|
let emailBcc: Binding<String>
|
|
|
}
|
|
|
|
|
|
// MARK: - WiFi输入配置
|
|
|
struct WiFiInputConfig {
|
|
|
let ssid: Binding<String>
|
|
|
let password: Binding<String>
|
|
|
let encryptionType: Binding<WiFiInputView.WiFiEncryptionType>
|
|
|
}
|
|
|
|
|
|
// MARK: - 联系人输入配置
|
|
|
struct ContactInputConfig {
|
|
|
let firstName: Binding<String>
|
|
|
let lastName: Binding<String>
|
|
|
let phone: Binding<String>
|
|
|
let email: Binding<String>
|
|
|
let company: Binding<String>
|
|
|
let title: Binding<String>
|
|
|
let address: Binding<String>
|
|
|
let website: Binding<String>
|
|
|
let nickname: Binding<String>
|
|
|
let birthday: Binding<Date>
|
|
|
let note: Binding<String>
|
|
|
}
|
|
|
|
|
|
// MARK: - 位置输入配置
|
|
|
struct LocationInputConfig {
|
|
|
let latitude: Binding<String>
|
|
|
let longitude: Binding<String>
|
|
|
let locationName: Binding<String>
|
|
|
}
|
|
|
|
|
|
// MARK: - 日历输入配置
|
|
|
struct CalendarInputConfig {
|
|
|
let eventTitle: Binding<String>
|
|
|
let eventDescription: Binding<String>
|
|
|
let startDate: Binding<Date>
|
|
|
let endDate: Binding<Date>
|
|
|
let location: Binding<String>
|
|
|
}
|
|
|
|
|
|
// MARK: - 社交输入配置
|
|
|
struct SocialInputConfig {
|
|
|
let username: Binding<String>
|
|
|
let message: Binding<String>
|
|
|
}
|
|
|
|
|
|
// MARK: - 电话输入配置
|
|
|
struct PhoneInputConfig {
|
|
|
let phoneNumber: Binding<String>
|
|
|
let phoneMessage: Binding<String>
|
|
|
}
|
|
|
|
|
|
// MARK: - URL输入配置
|
|
|
struct URLInputConfig {
|
|
|
let url: Binding<String>
|
|
|
}
|
|
|
|
|
|
// MARK: - 文本输入配置
|
|
|
struct TextInputConfig {
|
|
|
let content: Binding<String>
|
|
|
}
|
|
|
|
|
|
// MARK: - 输入组件工厂
|
|
|
struct InputComponentFactory {
|
|
|
|
|
|
// 创建邮件输入组件
|
|
|
static func createEmailInput(with config: EmailInputConfig) -> AnyView {
|
|
|
return AnyView(
|
|
|
EmailInputView(
|
|
|
emailAddress: config.emailAddress,
|
|
|
emailSubject: config.emailSubject,
|
|
|
emailBody: config.emailBody,
|
|
|
emailCc: config.emailCc,
|
|
|
emailBcc: config.emailBcc
|
|
|
)
|
|
|
)
|
|
|
}
|
|
|
|
|
|
// 创建WiFi输入组件
|
|
|
static func createWiFiInput(with config: WiFiInputConfig) -> AnyView {
|
|
|
return AnyView(
|
|
|
WiFiInputView(
|
|
|
ssid: config.ssid,
|
|
|
password: config.password,
|
|
|
encryptionType: config.encryptionType
|
|
|
)
|
|
|
)
|
|
|
}
|
|
|
|
|
|
// 创建联系人输入组件
|
|
|
static func createContactInput(with config: ContactInputConfig) -> AnyView {
|
|
|
return AnyView(
|
|
|
ContactInputView(
|
|
|
firstName: config.firstName,
|
|
|
lastName: config.lastName,
|
|
|
phone: config.phone,
|
|
|
email: config.email,
|
|
|
company: config.company,
|
|
|
title: config.title,
|
|
|
address: config.address,
|
|
|
website: config.website,
|
|
|
nickname: config.nickname,
|
|
|
birthday: config.birthday,
|
|
|
note: config.note
|
|
|
)
|
|
|
)
|
|
|
}
|
|
|
|
|
|
// 创建位置输入组件
|
|
|
static func createLocationInput(with config: LocationInputConfig) -> AnyView {
|
|
|
return AnyView(
|
|
|
LocationInputView(
|
|
|
latitude: config.latitude,
|
|
|
longitude: config.longitude,
|
|
|
locationName: config.locationName
|
|
|
)
|
|
|
)
|
|
|
}
|
|
|
|
|
|
// 创建日历输入组件
|
|
|
static func createCalendarInput(with config: CalendarInputConfig) -> AnyView {
|
|
|
return AnyView(
|
|
|
CalendarInputView(
|
|
|
eventTitle: config.eventTitle,
|
|
|
eventDescription: config.eventDescription,
|
|
|
startDate: config.startDate,
|
|
|
endDate: config.endDate,
|
|
|
location: config.location
|
|
|
)
|
|
|
)
|
|
|
}
|
|
|
|
|
|
// 创建社交输入组件
|
|
|
static func createSocialInput(with config: SocialInputConfig, platform: SocialInputView.SocialPlatform) -> AnyView {
|
|
|
return AnyView(
|
|
|
SocialInputView(
|
|
|
username: config.username,
|
|
|
message: config.message,
|
|
|
platform: platform
|
|
|
)
|
|
|
)
|
|
|
}
|
|
|
|
|
|
// 创建电话输入组件
|
|
|
static func createPhoneInput(with config: PhoneInputConfig, inputType: PhoneInputView.PhoneInputType) -> AnyView {
|
|
|
return AnyView(
|
|
|
PhoneInputView(
|
|
|
phoneNumber: config.phoneNumber,
|
|
|
message: config.phoneMessage,
|
|
|
inputType: inputType
|
|
|
)
|
|
|
)
|
|
|
}
|
|
|
|
|
|
// 创建URL输入组件
|
|
|
static func createURLInput(with config: URLInputConfig) -> AnyView {
|
|
|
return AnyView(
|
|
|
URLInputView(
|
|
|
url: config.url
|
|
|
)
|
|
|
)
|
|
|
}
|
|
|
|
|
|
// 创建文本输入组件
|
|
|
static func createTextInput(with config: TextInputConfig, placeholder: String, maxCharacters: Int) -> AnyView {
|
|
|
return AnyView(
|
|
|
TextInputView(
|
|
|
content: config.content,
|
|
|
placeholder: placeholder,
|
|
|
maxCharacters: maxCharacters
|
|
|
)
|
|
|
)
|
|
|
}
|
|
|
|
|
|
// 根据QR码类型返回相应的输入组件 - 需要从CreateQRCodeView传入具体的绑定
|
|
|
static func createInputComponent(
|
|
|
for qrCodeType: QRCodeType,
|
|
|
emailConfig: EmailInputConfig? = nil,
|
|
|
wifiConfig: WiFiInputConfig? = nil,
|
|
|
contactConfig: ContactInputConfig? = nil,
|
|
|
locationConfig: LocationInputConfig? = nil,
|
|
|
calendarConfig: CalendarInputConfig? = nil,
|
|
|
socialConfig: SocialInputConfig? = nil,
|
|
|
phoneConfig: PhoneInputConfig? = nil,
|
|
|
urlConfig: URLInputConfig? = nil,
|
|
|
textConfig: TextInputConfig? = nil
|
|
|
) -> AnyView {
|
|
|
|
|
|
switch qrCodeType {
|
|
|
case .mail:
|
|
|
guard let config = emailConfig else {
|
|
|
return AnyView(EmptyView())
|
|
|
}
|
|
|
return createEmailInput(with: config)
|
|
|
|
|
|
case .wifi:
|
|
|
guard let config = wifiConfig else {
|
|
|
return AnyView(EmptyView())
|
|
|
}
|
|
|
return createWiFiInput(with: config)
|
|
|
|
|
|
case .vcard, .mecard:
|
|
|
guard let config = contactConfig else {
|
|
|
return AnyView(EmptyView())
|
|
|
}
|
|
|
return createContactInput(with: config)
|
|
|
|
|
|
case .location:
|
|
|
guard let config = locationConfig else {
|
|
|
return AnyView(EmptyView())
|
|
|
}
|
|
|
return createLocationInput(with: config)
|
|
|
|
|
|
case .calendar:
|
|
|
guard let config = calendarConfig else {
|
|
|
return AnyView(EmptyView())
|
|
|
}
|
|
|
return createCalendarInput(with: config)
|
|
|
|
|
|
case .instagram, .facebook, .twitter, .tiktok, .snapchat, .whatsapp, .viber, .spotify:
|
|
|
guard let config = socialConfig else {
|
|
|
return AnyView(EmptyView())
|
|
|
}
|
|
|
let platform = SocialInputView.SocialPlatform(rawValue: qrCodeType.rawValue.capitalized) ?? .instagram
|
|
|
return createSocialInput(with: config, platform: platform)
|
|
|
|
|
|
case .phone, .sms:
|
|
|
guard let config = phoneConfig else {
|
|
|
return AnyView(EmptyView())
|
|
|
}
|
|
|
let inputType: PhoneInputView.PhoneInputType = qrCodeType == .phone ? .phone : .sms
|
|
|
return createPhoneInput(with: config, inputType: inputType)
|
|
|
|
|
|
case .url:
|
|
|
guard let config = urlConfig else {
|
|
|
return AnyView(EmptyView())
|
|
|
}
|
|
|
return createURLInput(with: config)
|
|
|
|
|
|
default:
|
|
|
guard let config = textConfig else {
|
|
|
return AnyView(EmptyView())
|
|
|
}
|
|
|
return createTextInput(
|
|
|
with: config,
|
|
|
placeholder: getPlaceholderText(for: qrCodeType),
|
|
|
maxCharacters: getMaxCharacters(for: qrCodeType)
|
|
|
)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 获取占位符文本
|
|
|
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用户ID..."
|
|
|
case .spotify:
|
|
|
return "输入Spotify信息..."
|
|
|
case .twitter:
|
|
|
return "输入Twitter信息..."
|
|
|
case .whatsapp:
|
|
|
return "输入WhatsApp电话号码(如:+1234567890)..."
|
|
|
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
|
|
|
}
|
|
|
}
|
|
|
} |