From 373456dfd8154b40a59d26d35d5379f0c143534c Mon Sep 17 00:00:00 2001 From: Junhui Chen Date: Sun, 7 Sep 2025 21:42:19 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=BC=80=E5=90=AF=E7=9B=B2=E7=9B=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- wake/Utils/ApiClient/BlindBoxApi.swift | 24 ++++++++++++++++++++++++ wake/View/Blind/ContentView.swift | 12 ++++++++++++ 2 files changed, 36 insertions(+) diff --git a/wake/Utils/ApiClient/BlindBoxApi.swift b/wake/Utils/ApiClient/BlindBoxApi.swift index a6501c3..05696a5 100644 --- a/wake/Utils/ApiClient/BlindBoxApi.swift +++ b/wake/Utils/ApiClient/BlindBoxApi.swift @@ -23,6 +23,12 @@ struct BlindBoxListResponse: Codable { let data: [BlindBoxData] } +// MARK: - Open Blind Box Response Model +struct OpenBlindBoxResponse: Codable { + let code: Int + let data: BlindBoxData? +} + // MARK: - Blind Box API Client class BlindBoxApi { static let shared = BlindBoxApi() @@ -141,4 +147,22 @@ class BlindBoxApi { 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)") + } + } } diff --git a/wake/View/Blind/ContentView.swift b/wake/View/Blind/ContentView.swift index 4ddd81b..e5d7098 100644 --- a/wake/View/Blind/ContentView.swift +++ b/wake/View/Blind/ContentView.swift @@ -753,6 +753,18 @@ struct BlindBoxView: View { .frame(width: 300, height: 300) .onTapGesture { print("点击了盲盒") + + // 标记盲盒开启 + if let boxId = self.currentBoxId { + Task { + do { + try await BlindBoxApi.shared.openBlindBox(boxId: boxId) + print("✅ 盲盒开启成功") + } catch { + print("❌ 开启盲盒失败: \(error)") + } + } + } withAnimation { animationPhase = .opening }