diff --git a/MyQrCode/Models/QRCodeParser.swift b/MyQrCode/Models/QRCodeParser.swift index 4ff226b..6ce1bfd 100644 --- a/MyQrCode/Models/QRCodeParser.swift +++ b/MyQrCode/Models/QRCodeParser.swift @@ -178,7 +178,7 @@ class QRCodeParser { } // Spotify - if trimmedContent.hasPrefix("spotify:") { + if trimmedContent.hasPrefix("spotify:search:") { return parseSpotify(trimmedContent) } @@ -538,12 +538,12 @@ class QRCodeParser { // MARK: - 解析Spotify private static func parseSpotify(_ content: String) -> ParsedQRData { - let trackId = content.replacingOccurrences(of: "spotify:track:", with: "") + let searchQuery = content.replacingOccurrences(of: "spotify:search:", with: "") return ParsedQRData( type: .spotify, title: "Spotify", - subtitle: "曲目ID: \(trackId)", + subtitle: "搜索: \(searchQuery)", icon: "music.note" ) } diff --git a/MyQrCode/Views/Components/InputComponentFactory.swift b/MyQrCode/Views/Components/InputComponentFactory.swift index ce627f0..fb84fb9 100644 --- a/MyQrCode/Views/Components/InputComponentFactory.swift +++ b/MyQrCode/Views/Components/InputComponentFactory.swift @@ -282,7 +282,7 @@ struct InputComponentFactory { case .facebook: return "输入Facebook用户ID或链接..." case .spotify: - return "输入Spotify信息..." + return "输入艺术家和歌曲信息..." case .twitter: return "输入X信息..." case .whatsapp: diff --git a/MyQrCode/Views/Components/SocialInputView.swift b/MyQrCode/Views/Components/SocialInputView.swift index 0083502..14d5f82 100644 --- a/MyQrCode/Views/Components/SocialInputView.swift +++ b/MyQrCode/Views/Components/SocialInputView.swift @@ -103,22 +103,62 @@ struct SocialInputView: View { .fill(Color.blue.opacity(0.1)) ) - // 用户名/链接 (必填) - VStack(alignment: .leading, spacing: 8) { - HStack { - // 根据平台显示不同的提示 - Text(getInputLabel()) - .font(.subheadline) - .foregroundColor(.primary) - Text("*") - .foregroundColor(.red) - Spacer() + // 输入框部分 + if platform == .spotify { + // Spotify专用:Artist和Song两个输入框 + VStack(alignment: .leading, spacing: 12) { + // Artist输入框 + VStack(alignment: .leading, spacing: 8) { + HStack { + Text("艺术家") + .font(.subheadline) + .foregroundColor(.primary) + Text("*") + .foregroundColor(.red) + Spacer() + } + + TextField("输入艺术家名称", text: $username) + .textFieldStyle(RoundedBorderTextFieldStyle()) + .autocapitalization(.none) + .focused($focusedField, equals: .username) + } + + // Song输入框 + VStack(alignment: .leading, spacing: 8) { + HStack { + Text("歌曲名称") + .font(.subheadline) + .foregroundColor(.primary) + Text("*") + .foregroundColor(.red) + Spacer() + } + + TextField("输入歌曲名称", text: $message) + .textFieldStyle(RoundedBorderTextFieldStyle()) + .autocapitalization(.none) + .focused($focusedField, equals: .message) + } + } + } else { + // 其他平台的单输入框 + VStack(alignment: .leading, spacing: 8) { + HStack { + // 根据平台显示不同的提示 + Text(getInputLabel()) + .font(.subheadline) + .foregroundColor(.primary) + Text("*") + .foregroundColor(.red) + Spacer() + } + + TextField(platform.placeholder, text: $username) + .textFieldStyle(RoundedBorderTextFieldStyle()) + .autocapitalization(.none) + .focused($focusedField, equals: .username) } - - TextField(platform.placeholder, text: $username) - .textFieldStyle(RoundedBorderTextFieldStyle()) - .autocapitalization(.none) - .focused($focusedField, equals: .username) } @@ -200,7 +240,7 @@ struct SocialInputView: View { case .viber: return "• 输入Viber电话号码(如:+1234567890)\n• 将生成viber://add?number=格式\n• 用户扫描后可直接添加Viber联系人" case .spotify: - return "• 输入歌曲或播放列表链接\n• 或输入Spotify ID" + return "• 输入艺术家名称和歌曲名称\n• 将生成spotify:search:艺术家;歌曲格式\n• 用户扫描后可直接在Spotify中搜索" } } } diff --git a/MyQrCode/Views/CreateQRCodeView.swift b/MyQrCode/Views/CreateQRCodeView.swift index 70c963a..ba507a5 100644 --- a/MyQrCode/Views/CreateQRCodeView.swift +++ b/MyQrCode/Views/CreateQRCodeView.swift @@ -511,7 +511,7 @@ struct CreateQRCodeView: View { let facebookId = extractFacebookId(from: socialUsername) return "fb://profile/\(facebookId)" case .spotify: - return "https://open.spotify.com/track/\(socialUsername)" + return "spotify:search:\(socialUsername);\(socialMessage)" case .twitter: return "twitter://user?screen_name=\(socialUsername)" case .whatsapp: @@ -535,7 +535,7 @@ struct CreateQRCodeView: View { let facebookId = extractFacebookId(from: socialUsername) return "fb://profile/\(facebookId)" case .spotify: - return "https://open.spotify.com/track/\(socialUsername)" + return "spotify:search:\(socialUsername);\(socialMessage)" case .twitter: return "twitter://user?screen_name=\(socialUsername)" case .whatsapp: @@ -670,6 +670,6 @@ struct CreateQRCodeView: View { #Preview { NavigationView { - CreateQRCodeView(selectedQRCodeType: .sms) + CreateQRCodeView(selectedQRCodeType: .spotify) } } diff --git a/docs/QRCODE_DETAIL_VIEW_README.md b/docs/QRCODE_DETAIL_VIEW_README.md index f831bfb..578a52a 100644 --- a/docs/QRCODE_DETAIL_VIEW_README.md +++ b/docs/QRCODE_DETAIL_VIEW_README.md @@ -92,7 +92,7 @@ END:VEVENT // 社交媒体 Instagram: instagram://user?username=<用户名> Facebook: fb://profile/<用户ID> -Spotify: spotify:track:<曲目ID> +Spotify: spotify:search:<艺术家>;<歌曲> X: twitter://user?screen_name=<用户名> WhatsApp: whatsapp://send?phone=<电话号码> Viber: viber://add?number=<电话号码>