feat/blind_box_v2 #4

Merged
txcjh merged 18 commits from feat/blind_box_v2 into main 2025-09-07 22:23:23 +08:00
5 changed files with 93 additions and 42 deletions
Showing only changes of commit 4d1486560e - Show all commits

View File

@ -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:

View File

@ -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()
}
}
}

View File

@ -223,20 +223,20 @@ struct BlindBoxView: View {
}
}
//
NetworkService.shared.get(
path: "/blind_box/available/quantity",
parameters: nil
) { (result: Result<APIResponse<BlindCount>, 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<APIResponse<BlindCount>, 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 {

View File

@ -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 {

View File

@ -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 {
//