feat: 重复购买第二个盲盒
This commit is contained in:
parent
373456dfd8
commit
4d1486560e
@ -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:
|
||||||
|
|||||||
@ -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 {
|
||||||
|
|||||||
@ -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 {
|
||||||
|
|||||||
@ -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 {
|
||||||
|
|||||||
@ -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
|
.navigationDestination(for: AppRoute.self) { route in
|
||||||
// route.view
|
route.view
|
||||||
// }
|
}
|
||||||
UserInfo()
|
// UserInfo()
|
||||||
.navigationDestination(for: AppRoute.self) { route in
|
// .navigationDestination(for: AppRoute.self) { route in
|
||||||
route.view
|
// route.view
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// 未登录:显示登录界面
|
// 未登录:显示登录界面
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user