feat: 控制第一个盲盒生成
This commit is contained in:
parent
5b9413699f
commit
3dc171aefe
@ -11,7 +11,7 @@ enum AppRoute: Hashable {
|
||||
case blindOutcome(media: MediaType, title: String? = nil, description: String? = nil, isMember: Bool, goToFeedback: Bool = false)
|
||||
case memories
|
||||
case subscribe
|
||||
case userInfo
|
||||
case userInfo(createFirstBlindBox: Bool = false)
|
||||
case account
|
||||
case about
|
||||
case permissionManagement
|
||||
@ -51,8 +51,8 @@ enum AppRoute: Hashable {
|
||||
MemoriesView()
|
||||
case .subscribe:
|
||||
SubscribeView()
|
||||
case .userInfo:
|
||||
UserInfo()
|
||||
case .userInfo(let createFirstBlindBox):
|
||||
UserInfo(createFirstBlindBox: createFirstBlindBox)
|
||||
case .account:
|
||||
AccountView()
|
||||
case .about:
|
||||
|
||||
@ -98,7 +98,7 @@ struct UserProfileModal: View {
|
||||
}
|
||||
}
|
||||
.onTapGesture {
|
||||
Router.shared.navigate(to: .userInfo)
|
||||
Router.shared.navigate(to: .userInfo(createFirstBlindBox: false))
|
||||
}
|
||||
} else {
|
||||
Image(systemName: "person.circle.fill")
|
||||
|
||||
@ -264,7 +264,7 @@ struct LoginView: View {
|
||||
self.showError = true
|
||||
}
|
||||
// 跳转到userinfo
|
||||
Router.shared.navigate(to: .userInfo)
|
||||
Router.shared.navigate(to: .userInfo(createFirstBlindBox: true))
|
||||
|
||||
case .failure(let error):
|
||||
print("❌ [15] 后端认证失败")
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
import SwiftUI
|
||||
|
||||
struct UserInfo: View {
|
||||
let createFirstBlindBox: Bool
|
||||
|
||||
@Environment(\.dismiss) private var dismiss
|
||||
@StateObject private var router = Router.shared
|
||||
|
||||
@ -44,9 +46,10 @@ struct UserInfo: View {
|
||||
.map { _ in false })
|
||||
.receive(on: RunLoop.main)
|
||||
|
||||
init() {
|
||||
init(createFirstBlindBox: Bool) {
|
||||
// 在初始化时预加载键盘
|
||||
_ = UserInfo.keyboardPreloader
|
||||
self.createFirstBlindBox = createFirstBlindBox
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
@ -182,31 +185,35 @@ struct UserInfo: View {
|
||||
self.userName = userData.username
|
||||
}
|
||||
|
||||
// 上传头像为素材
|
||||
MaterialUpload.shared.addMaterial(
|
||||
fileId: uploadedFileId ?? "",
|
||||
previewFileId: uploadedFileId ?? ""
|
||||
) { result in
|
||||
switch result {
|
||||
case .success(let data):
|
||||
print("素材添加成功,返回ID: \(data ?? [])")
|
||||
// 触发盲盒生成
|
||||
BlindBoxApi.shared.generateBlindBox(
|
||||
boxType: "First",
|
||||
materialIds: data ?? []
|
||||
) { result in
|
||||
switch result {
|
||||
case .success(let blindBoxData):
|
||||
print("✅ 盲盒生成成功: \(blindBoxData?.id ?? "0")")
|
||||
// 导航到首页盲盒等待用户开启第一个盲盒
|
||||
Router.shared.navigate(to: .blindBox(mediaType: .image, blindBoxId: blindBoxData?.id ?? "0"))
|
||||
case .failure(let error):
|
||||
print("❌ 盲盒生成失败: \(error.localizedDescription)")
|
||||
if createFirstBlindBox {
|
||||
// 上传头像为素材
|
||||
MaterialUpload.shared.addMaterial(
|
||||
fileId: uploadedFileId ?? "",
|
||||
previewFileId: uploadedFileId ?? ""
|
||||
) { result in
|
||||
switch result {
|
||||
case .success(let data):
|
||||
print("素材添加成功,返回ID: \(data ?? [])")
|
||||
// 触发盲盒生成
|
||||
BlindBoxApi.shared.generateBlindBox(
|
||||
boxType: "First",
|
||||
materialIds: data ?? []
|
||||
) { result in
|
||||
switch result {
|
||||
case .success(let blindBoxData):
|
||||
print("✅ 盲盒生成成功: \(blindBoxData?.id ?? "0")")
|
||||
// 导航到首页盲盒等待用户开启第一个盲盒
|
||||
Router.shared.navigate(to: .blindBox(mediaType: .image, blindBoxId: blindBoxData?.id ?? "0"))
|
||||
case .failure(let error):
|
||||
print("❌ 盲盒生成失败: \(error.localizedDescription)")
|
||||
}
|
||||
}
|
||||
case .failure(let error):
|
||||
print("素材添加失败: \(error.localizedDescription)")
|
||||
}
|
||||
case .failure(let error):
|
||||
print("素材添加失败: \(error.localizedDescription)")
|
||||
}
|
||||
} else {
|
||||
Router.shared.navigate(to: .blindBox(mediaType: .all))
|
||||
}
|
||||
case .failure(let error):
|
||||
print("❌ 用户信息更新失败: \(error.localizedDescription)")
|
||||
@ -327,6 +334,6 @@ struct SettingsRow: View {
|
||||
// MARK: - Preview
|
||||
struct UserInfo_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
UserInfo()
|
||||
UserInfo(createFirstBlindBox: false)
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user