Update QRCodeParser and CreateQRCodeView to standardize SMS format to "SMSTO:" and adjust related components for consistency; enhance PhoneInputView with updated placeholder and hints for better user guidance.

main
v504 2 months ago
parent b4cc77cfe8
commit 335ccd25d2

@ -24,7 +24,7 @@ class QRCodeParser {
}
// SMS
if trimmedContent.hasPrefix("sms:") {
if trimmedContent.hasPrefix("SMSTO:") {
return parseSMS(trimmedContent)
}
@ -158,8 +158,8 @@ class QRCodeParser {
// MARK: - SMS
private static func parseSMS(_ content: String) -> ParsedQRData {
let smsInfo = content.replacingOccurrences(of: "sms:", with: "")
let components = smsInfo.components(separatedBy: "?body=")
let smsInfo = content.replacingOccurrences(of: "SMSTO:", with: "")
let components = smsInfo.components(separatedBy: ":")
let phone = components.first ?? ""
let message = components.count > 1 ? components[1] : ""

@ -28,7 +28,7 @@ struct PhoneInputView: View {
var placeholder: String {
switch self {
case .phone: return "+86 138 0013 8000"
case .phone: return "+1 (555) 123-4567"
case .sms: return "输入短信内容"
}
}
@ -84,7 +84,7 @@ struct PhoneInputView: View {
Spacer()
}
TextField(inputType.placeholder, text: $phoneNumber)
TextField("+1 (555) 123-4567", text: $phoneNumber)
.textFieldStyle(RoundedBorderTextFieldStyle())
.keyboardType(.phonePad)
.focused($focusedField, equals: .phoneNumber)
@ -147,9 +147,9 @@ struct PhoneInputView: View {
private func getFormatHint() -> String {
switch inputType {
case .phone:
return "• 支持国际格式:+86 138 0013 8000\n• 或本地格式138 0013 8000\n• 将生成 tel: 链接"
return "• 支持国际格式:+1 (555) 123-4567\n• 或本地格式:(555) 123-4567\n• 将生成 tel: 链接"
case .sms:
return "• 输入电话号码和短信内容\n• 将生成 sms: 链接\n• 用户点击可直接发送短信"
return "• 输入电话号码和短信内容\n• 将生成 SMSTO: 链接\n• 用户点击可直接发送短信"
}
}
}

@ -9,9 +9,8 @@ struct QRCodePreviewView: View {
var body: some View {
VStack(spacing: 16) {
HStack {
Text("预览")
.font(.headline)
.foregroundColor(.primary)
InputTitleView.required("预览", icon: "eye")
.padding(.horizontal, 20)
Spacer()
}
@ -87,4 +86,4 @@ struct QRCodePreviewView: View {
formattedContent: "示例内容",
qrCodeType: .text
)
}
}

@ -13,13 +13,15 @@ struct WiFiInputView: View {
}
// WiFi
enum WiFiEncryptionType: String, CaseIterable {
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 "无加密"
@ -73,7 +75,7 @@ struct WiFiInputView: View {
}
Picker("加密类型", selection: $encryptionType) {
ForEach(WiFiEncryptionType.allCases, id: \.self) { type in
ForEach(WiFiEncryptionType.allCases) { type in
Text(type.displayName).tag(type)
}
}

@ -108,22 +108,16 @@ struct CreateQRCodeView: View {
//
VStack(spacing: 16) {
InputTitleView.required(
selectedQRCodeType == .mail ? "邮件信息" : "输入内容",
icon: getInputIcon()
)
.padding(.horizontal, 20)
// 使InputComponentFactory
createInputComponentForType()
.padding(.horizontal, 20)
}
//
#if DEBUG
if canCreateQRCode() {
VStack(spacing: 16) {
InputTitleView.required("预览", icon: "eye")
.padding(.horizontal, 20)
// 使QRCodePreviewView
QRCodePreviewView(
@ -134,8 +128,8 @@ struct CreateQRCodeView: View {
.padding(.horizontal, 20)
}
}
Spacer(minLength: 100)
#endif
}
.padding(.top, 20)
}
@ -391,7 +385,7 @@ struct CreateQRCodeView: View {
return "tel:\(phoneNumber)"
case .sms:
let smsContent = phoneMessage.isEmpty ? "Hello" : phoneMessage
return "sms:\(phoneNumber):\(smsContent)"
return "SMSTO:\(phoneNumber):\(smsContent)"
case .wifi:
return "WIFI:T:\(wifiEncryptionType.rawValue);S:\(wifiSSID);P:\(wifiPassword);;"
case .vcard:
@ -538,6 +532,6 @@ struct CreateQRCodeView: View {
#Preview {
NavigationView {
CreateQRCodeView(selectedQRCodeType: .mail)
CreateQRCodeView(selectedQRCodeType: .sms)
}
}

@ -396,7 +396,7 @@ private enum PreviewData {
}
static func smsSample(in context: NSManagedObjectContext) -> HistoryItem {
let content = "sms:+8613800138000?body=Hello"
let content = "SMSTO:+8613800138000:Hello"
return makeBaseItem(in: context, content: content, qrType: .sms)
}

@ -51,8 +51,8 @@ tel:+<国家代码><电话号码>
示例: tel:+8613800138000
// 短信
sms:<电话号码>?body=<短信内容>
示例: sms:+8613800138000?body=Hello
SMSTO:<电话号码>:<短信内容>
示例: SMSTO:+8613800138000:Hello
// 联系人信息 (vCard)
BEGIN:VCARD

Loading…
Cancel
Save