feat: 重复购买第二个盲盒

This commit is contained in:
Junhui Chen 2025-09-07 22:22:10 +08:00
parent 373456dfd8
commit 4d1486560e
5 changed files with 93 additions and 42 deletions

View File

@ -8,7 +8,7 @@ enum AppRoute: Hashable {
case feedbackDetail(type: FeedbackView.FeedbackType) case feedbackDetail(type: FeedbackView.FeedbackType)
case mediaUpload case mediaUpload
case blindBox(mediaType: BlindBoxMediaType, blindBoxId: String? = nil) case blindBox(mediaType: BlindBoxMediaType, blindBoxId: String? = nil)
case blindOutcome(media: MediaType, time: String? = nil, description: String? = nil) case blindOutcome(media: MediaType, time: String? = nil, description: String? = nil, isMember: Bool)
case memories case memories
case subscribe case subscribe
case userInfo case userInfo
@ -33,8 +33,8 @@ enum AppRoute: Hashable {
MediaUploadView() MediaUploadView()
case .blindBox(let mediaType, let blindBoxId): case .blindBox(let mediaType, let blindBoxId):
BlindBoxView(mediaType: mediaType, blindBoxId: blindBoxId) BlindBoxView(mediaType: mediaType, blindBoxId: blindBoxId)
case .blindOutcome(let media, let time, let description): case .blindOutcome(let media, let time, let description, let isMember):
BlindOutcomeView(media: media, time: time, description: description) BlindOutcomeView(media: media, time: time, description: description, isMember: isMember)
case .memories: case .memories:
MemoriesView() MemoriesView()
case .subscribe: case .subscribe:

View File

@ -6,6 +6,7 @@ struct BlindOutcomeView: View {
let media: MediaType let media: MediaType
let time: String? let time: String?
let description: String? let description: String?
let isMember: Bool
@Environment(\.presentationMode) var presentationMode @Environment(\.presentationMode) var presentationMode
@State private var isFullscreen = false @State private var isFullscreen = false
@State private var isPlaying = false @State private var isPlaying = false
@ -13,10 +14,11 @@ struct BlindOutcomeView: View {
@State private var showIPListModal = false @State private var showIPListModal = false
@State private var player: AVPlayer? @State private var player: AVPlayer?
init(media: MediaType, time: String? = nil, description: String? = nil) { init(media: MediaType, time: String? = nil, description: String? = nil, isMember: Bool = false) {
self.media = media self.media = media
self.time = time self.time = time
self.description = description self.description = description
self.isMember = isMember
} }
var body: some View { var body: some View {

View File

@ -223,20 +223,20 @@ struct BlindBoxView: View {
} }
} }
// //
NetworkService.shared.get( // NetworkService.shared.get(
path: "/blind_box/available/quantity", // path: "/blind_box/available/quantity",
parameters: nil // parameters: nil
) { (result: Result<APIResponse<BlindCount>, NetworkError>) in // ) { (result: Result<APIResponse<BlindCount>, NetworkError>) in
DispatchQueue.main.async { // DispatchQueue.main.async {
switch result { // switch result {
case .success(let response): // case .success(let response):
self.blindCount = response.data // self.blindCount = response.data
print("✅ 成功获取盲盒数量:", response.data) // print(" :", response.data)
case .failure(let error): // case .failure(let error):
print("❌ 获取数量失败:", error) // print(" :", error)
} // }
} // }
} // }
// } // }
} }
@ -254,11 +254,12 @@ struct BlindBoxView: View {
self.blindGenerate = data self.blindGenerate = data
// URL // URL
if mediaType == .video { if mediaType == .image {
self.videoURL = data.resultFile?.url ?? ""
} else if mediaType == .image {
self.imageURL = data.resultFile?.url ?? "" self.imageURL = data.resultFile?.url ?? ""
} }
else {
self.videoURL = data.resultFile?.url ?? ""
}
print("✅ 成功获取盲盒数据: \(data.name), 状态: \(data.status)") print("✅ 成功获取盲盒数据: \(data.name), 状态: \(data.status)")
@ -291,9 +292,25 @@ struct BlindBoxView: View {
do { do {
let blindBoxList = try await BlindBoxApi.shared.getBlindBoxList() let blindBoxList = try await BlindBoxApi.shared.getBlindBoxList()
print("✅ 获取盲盒列表: \(blindBoxList?.count ?? 0)") print("✅ 获取盲盒列表: \(blindBoxList?.count ?? 0)")
//
//
self.blindCount = BlindCount(availableQuantity: blindBoxList?.filter({ $0.status == "Unopened" }).count ?? 0)
//
if let blindBox = blindBoxList?.first(where: { $0.status == "Unopened" }) { if let blindBox = blindBoxList?.first(where: { $0.status == "Unopened" }) {
self.blindGenerate = blindBox self.blindGenerate = blindBox
self.animationPhase = .ready
// UI
// URL
if mediaType == .image {
self.imageURL = blindBox.resultFile?.url ?? ""
}
else {
self.videoURL = blindBox.resultFile?.url ?? ""
}
print("✅ 成功获取盲盒数据: \(blindBox.name), 状态: \(blindBox.status)")
stopPolling() stopPolling()
break break
} else { } else {
@ -561,7 +578,7 @@ struct BlindBoxView: View {
.edgesIgnoringSafeArea(.all) .edgesIgnoringSafeArea(.all)
Group { Group {
if mediaType == .video, let player = videoPlayer { if mediaType == .all, let player = videoPlayer {
// Video Player // Video Player
AVPlayerController(player: $videoPlayer) AVPlayerController(player: $videoPlayer)
.frame(width: scaledWidth, height: scaledHeight) .frame(width: scaledWidth, height: scaledHeight)
@ -589,10 +606,10 @@ struct BlindBoxView: View {
HStack { HStack {
Button(action: { Button(action: {
// BlindOutcomeView // BlindOutcomeView
if mediaType == .video, !videoURL.isEmpty, let url = URL(string: videoURL) { if mediaType == .all, !videoURL.isEmpty, let url = URL(string: videoURL) {
Router.shared.navigate(to: .blindOutcome(media: .video(url, nil), time: blindGenerate?.name ?? "Your box", description:blindGenerate?.description ?? "")) Router.shared.navigate(to: .blindOutcome(media: .video(url, nil), time: blindGenerate?.name ?? "Your box", description:blindGenerate?.description ?? "", isMember: self.isMember))
} else if mediaType == .image, let image = displayImage { } else if mediaType == .image, let image = displayImage {
Router.shared.navigate(to: .blindOutcome(media: .image(image), time: blindGenerate?.name ?? "Your box", description:blindGenerate?.description ?? "")) Router.shared.navigate(to: .blindOutcome(media: .image(image), time: blindGenerate?.name ?? "Your box", description:blindGenerate?.description ?? "", isMember: self.isMember))
} }
}) { }) {
Image(systemName: "chevron.left") Image(systemName: "chevron.left")
@ -765,6 +782,16 @@ struct BlindBoxView: View {
} }
} }
} }
if let boxId = self.blindGenerate?.id {
Task {
do {
try await BlindBoxApi.shared.openBlindBox(boxId: boxId)
print("✅ 盲盒开启成功")
} catch {
print("❌ 开启盲盒失败: \(error)")
}
}
}
withAnimation { withAnimation {
animationPhase = .opening animationPhase = .opening
} }
@ -799,7 +826,7 @@ struct BlindBoxView: View {
// //
self.showScalingOverlay = true self.showScalingOverlay = true
if mediaType == .video { if mediaType == .all {
loadVideo() loadVideo()
} else if mediaType == .image { } else if mediaType == .image {
loadImage() loadImage()
@ -857,11 +884,33 @@ struct BlindBoxView: View {
if mediaType == .all { if mediaType == .all {
Button(action: { Button(action: {
if animationPhase == .ready { if animationPhase == .ready {
// //
// //
Router.shared.navigate(to: .subscribe) if let boxId = self.currentBoxId {
} else { Task {
showUserProfile() do {
try await BlindBoxApi.shared.openBlindBox(boxId: boxId)
print("✅ 盲盒开启成功")
} catch {
print("❌ 开启盲盒失败: \(error)")
}
}
}
if let boxId = self.blindGenerate?.id {
Task {
do {
try await BlindBoxApi.shared.openBlindBox(boxId: boxId)
print("✅ 盲盒开启成功")
} catch {
print("❌ 开启盲盒失败: \(error)")
}
}
}
withAnimation {
animationPhase = .opening
}
} else if animationPhase == .none {
Router.shared.navigate(to: .mediaUpload)
} }
}) { }) {
if animationPhase == .loading { if animationPhase == .loading {

View File

@ -342,7 +342,7 @@ struct MediaUploadView: View {
let blindBoxId = result.id ?? "" let blindBoxId = result.id ?? ""
print("🎉 盲盒ID: \(blindBoxId)") print("🎉 盲盒ID: \(blindBoxId)")
// //
Router.shared.navigate(to: .blindBox(mediaType: .video, blindBoxId: blindBoxId)) Router.shared.navigate(to: .blindBox(mediaType: .all, blindBoxId: blindBoxId))
} }
} }
} catch { } catch {

View File

@ -47,14 +47,14 @@ struct WakeApp: App {
// //
NavigationStack(path: $router.path) { NavigationStack(path: $router.path) {
// FIXME // FIXME
// BlindBoxView(mediaType: .all) BlindBoxView(mediaType: .all)
// .navigationDestination(for: AppRoute.self) { route in
// route.view
// }
UserInfo()
.navigationDestination(for: AppRoute.self) { route in .navigationDestination(for: AppRoute.self) { route in
route.view route.view
} }
// UserInfo()
// .navigationDestination(for: AppRoute.self) { route in
// route.view
// }
} }
} else { } else {
// //