diff --git a/wake/Utils/Router.swift b/wake/Utils/Router.swift index a33b5e6..39ee741 100644 --- a/wake/Utils/Router.swift +++ b/wake/Utils/Router.swift @@ -8,7 +8,7 @@ enum AppRoute: Hashable { case feedbackDetail(type: FeedbackView.FeedbackType) case mediaUpload 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 subscribe case userInfo @@ -33,8 +33,8 @@ enum AppRoute: Hashable { MediaUploadView() case .blindBox(let mediaType, let blindBoxId): BlindBoxView(mediaType: mediaType, blindBoxId: blindBoxId) - case .blindOutcome(let media, let time, let description): - BlindOutcomeView(media: media, time: time, description: description) + case .blindOutcome(let media, let time, let description, let isMember): + BlindOutcomeView(media: media, time: time, description: description, isMember: isMember) case .memories: MemoriesView() case .subscribe: diff --git a/wake/View/Blind/BlindOutCome.swift b/wake/View/Blind/BlindOutCome.swift index cdd4bc9..ed1ee34 100644 --- a/wake/View/Blind/BlindOutCome.swift +++ b/wake/View/Blind/BlindOutCome.swift @@ -6,6 +6,7 @@ struct BlindOutcomeView: View { let media: MediaType let time: String? let description: String? + let isMember: Bool @Environment(\.presentationMode) var presentationMode @State private var isFullscreen = false @State private var isPlaying = false @@ -13,10 +14,11 @@ struct BlindOutcomeView: View { @State private var showIPListModal = false @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.time = time self.description = description + self.isMember = isMember } var body: some View { @@ -351,4 +353,4 @@ class PlayerView: UIView { deinit { cleanup() } -} \ No newline at end of file +} diff --git a/wake/View/Blind/ContentView.swift b/wake/View/Blind/ContentView.swift index e5d7098..916dbdb 100644 --- a/wake/View/Blind/ContentView.swift +++ b/wake/View/Blind/ContentView.swift @@ -223,20 +223,20 @@ struct BlindBoxView: View { } } // 盲盒数量 - NetworkService.shared.get( - path: "/blind_box/available/quantity", - parameters: nil - ) { (result: Result, NetworkError>) in - DispatchQueue.main.async { - switch result { - case .success(let response): - self.blindCount = response.data - print("✅ 成功获取盲盒数量:", response.data) - case .failure(let error): - print("❌ 获取数量失败:", error) - } - } - } + // NetworkService.shared.get( + // path: "/blind_box/available/quantity", + // parameters: nil + // ) { (result: Result, NetworkError>) in + // DispatchQueue.main.async { + // switch result { + // case .success(let response): + // self.blindCount = response.data + // print("✅ 成功获取盲盒数量:", response.data) + // case .failure(let error): + // print("❌ 获取数量失败:", error) + // } + // } + // } // } } @@ -254,11 +254,12 @@ struct BlindBoxView: View { self.blindGenerate = data // 根据盲盒类型设置媒体URL - if mediaType == .video { - self.videoURL = data.resultFile?.url ?? "" - } else if mediaType == .image { + if mediaType == .image { self.imageURL = data.resultFile?.url ?? "" } + else { + self.videoURL = data.resultFile?.url ?? "" + } print("✅ 成功获取盲盒数据: \(data.name), 状态: \(data.status)") @@ -291,9 +292,25 @@ struct BlindBoxView: View { do { let blindBoxList = try await BlindBoxApi.shared.getBlindBoxList() print("✅ 获取盲盒列表: \(blindBoxList?.count ?? 0) 条") - // 检查是否有未打开的盲盒 + + // 统计未开启盲盒数量 + self.blindCount = BlindCount(availableQuantity: blindBoxList?.filter({ $0.status == "Unopened" }).count ?? 0) + + // 设置第一个未开启的盲盒 if let blindBox = blindBoxList?.first(where: { $0.status == "Unopened" }) { 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() break } else { @@ -561,7 +578,7 @@ struct BlindBoxView: View { .edgesIgnoringSafeArea(.all) Group { - if mediaType == .video, let player = videoPlayer { + if mediaType == .all, let player = videoPlayer { // Video Player AVPlayerController(player: $videoPlayer) .frame(width: scaledWidth, height: scaledHeight) @@ -589,10 +606,10 @@ struct BlindBoxView: View { HStack { Button(action: { // 导航到BlindOutcomeView - if mediaType == .video, !videoURL.isEmpty, let url = URL(string: videoURL) { - Router.shared.navigate(to: .blindOutcome(media: .video(url, nil), time: blindGenerate?.name ?? "Your box", description:blindGenerate?.description ?? "")) + 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 ?? "", isMember: self.isMember)) } 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") @@ -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 { animationPhase = .opening } @@ -799,7 +826,7 @@ struct BlindBoxView: View { // 显示媒体内容 self.showScalingOverlay = true - if mediaType == .video { + if mediaType == .all { loadVideo() } else if mediaType == .image { loadImage() @@ -857,11 +884,33 @@ struct BlindBoxView: View { if mediaType == .all { Button(action: { if animationPhase == .ready { - // 处理准备就绪状态的操作 - // 导航到订阅页面 - Router.shared.navigate(to: .subscribe) - } else { - showUserProfile() + // 准备就绪点击,开启盲盒 + // 标记盲盒开启 + if let boxId = self.currentBoxId { + Task { + 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 { diff --git a/wake/View/OnBoarding/MediaUploadView.swift b/wake/View/OnBoarding/MediaUploadView.swift index 8beff4b..4f25b55 100644 --- a/wake/View/OnBoarding/MediaUploadView.swift +++ b/wake/View/OnBoarding/MediaUploadView.swift @@ -342,7 +342,7 @@ struct MediaUploadView: View { let blindBoxId = result.id ?? "" print("🎉 盲盒ID: \(blindBoxId)") // 导航到盲盒首页等待盲盒开启 - Router.shared.navigate(to: .blindBox(mediaType: .video, blindBoxId: blindBoxId)) + Router.shared.navigate(to: .blindBox(mediaType: .all, blindBoxId: blindBoxId)) } } } catch { diff --git a/wake/WakeApp.swift b/wake/WakeApp.swift index 4c5752f..5b1f2f1 100644 --- a/wake/WakeApp.swift +++ b/wake/WakeApp.swift @@ -47,14 +47,14 @@ struct WakeApp: App { // 已登录:显示主页面 NavigationStack(path: $router.path) { // FIXME 调回来 -// BlindBoxView(mediaType: .all) -// .navigationDestination(for: AppRoute.self) { route in -// route.view -// } - UserInfo() - .navigationDestination(for: AppRoute.self) { route in - route.view - } + BlindBoxView(mediaType: .all) + .navigationDestination(for: AppRoute.self) { route in + route.view + } + // UserInfo() + // .navigationDestination(for: AppRoute.self) { route in + // route.view + // } } } else { // 未登录:显示登录界面