feat: 开启盲盒
This commit is contained in:
parent
62c12a3bf8
commit
373456dfd8
@ -23,6 +23,12 @@ struct BlindBoxListResponse: Codable {
|
|||||||
let data: [BlindBoxData]
|
let data: [BlindBoxData]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MARK: - Open Blind Box Response Model
|
||||||
|
struct OpenBlindBoxResponse: Codable {
|
||||||
|
let code: Int
|
||||||
|
let data: BlindBoxData?
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: - Blind Box API Client
|
// MARK: - Blind Box API Client
|
||||||
class BlindBoxApi {
|
class BlindBoxApi {
|
||||||
static let shared = BlindBoxApi()
|
static let shared = BlindBoxApi()
|
||||||
@ -141,4 +147,22 @@ class BlindBoxApi {
|
|||||||
throw NetworkError.serverError("服务器返回错误码: \(response.code)")
|
throw NetworkError.serverError("服务器返回错误码: \(response.code)")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// 将盲盒标记为开启状态
|
||||||
|
/// - Parameter boxId: 盲盒ID
|
||||||
|
/// - Returns: 开启后的盲盒数据(可能为null)
|
||||||
|
@available(iOS 13.0, *)
|
||||||
|
func openBlindBox(boxId: String) async throws {
|
||||||
|
let response: OpenBlindBoxResponse = try await NetworkService.shared.postWithToken(
|
||||||
|
path: "/blind_box/open",
|
||||||
|
parameters: ["box_id": boxId]
|
||||||
|
)
|
||||||
|
if response.code == 0 {
|
||||||
|
// API返回成功,data可能为null,这是正常的
|
||||||
|
print("✅ 盲盒开启成功")
|
||||||
|
} else {
|
||||||
|
throw NetworkError.serverError("服务器返回错误码: \(response.code)")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -753,6 +753,18 @@ struct BlindBoxView: View {
|
|||||||
.frame(width: 300, height: 300)
|
.frame(width: 300, height: 300)
|
||||||
.onTapGesture {
|
.onTapGesture {
|
||||||
print("点击了盲盒")
|
print("点击了盲盒")
|
||||||
|
|
||||||
|
// 标记盲盒开启
|
||||||
|
if let boxId = self.currentBoxId {
|
||||||
|
Task {
|
||||||
|
do {
|
||||||
|
try await BlindBoxApi.shared.openBlindBox(boxId: boxId)
|
||||||
|
print("✅ 盲盒开启成功")
|
||||||
|
} catch {
|
||||||
|
print("❌ 开启盲盒失败: \(error)")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
withAnimation {
|
withAnimation {
|
||||||
animationPhase = .opening
|
animationPhase = .opening
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user