feat: 开启盲盒

This commit is contained in:
Junhui Chen 2025-09-07 21:42:19 +08:00
parent 62c12a3bf8
commit 373456dfd8
2 changed files with 36 additions and 0 deletions

View File

@ -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 {
// APIdatanull
print("✅ 盲盒开启成功")
} else {
throw NetworkError.serverError("服务器返回错误码: \(response.code)")
}
}
} }

View File

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