From b07de811a57c1b07001bdebe8d2b4150bba16c75 Mon Sep 17 00:00:00 2001 From: Junhui Chen Date: Sat, 6 Sep 2025 19:00:09 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E8=B0=83=E6=95=B4=E7=9B=B2?= =?UTF-8?q?=E7=9B=92=E7=BB=93=E6=9E=84=E4=BD=93=E5=88=B0Models=E7=9B=AE?= =?UTF-8?q?=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- wake/ContentView.swift | 130 +-------------------------------- wake/Models/BlindModels.swift | 131 ++++++++++++++++++++++++++++++++++ wake/Utils/Router.swift | 2 +- 3 files changed, 133 insertions(+), 130 deletions(-) create mode 100644 wake/Models/BlindModels.swift diff --git a/wake/ContentView.swift b/wake/ContentView.swift index 25add79..e37f488 100644 --- a/wake/ContentView.swift +++ b/wake/ContentView.swift @@ -67,135 +67,7 @@ struct AVPlayerController: UIViewControllerRepresentable { } } -struct BlindBoxView: View { - enum BlindBoxMediaType { - case video - case image - case all - } - // 盲盒列表 - struct BlindList: Codable, Identifiable { - // API 返回为字符串,这里按字符串处理 - let id: String - let boxCode: String - let userId: String - let name: String - let boxType: String - let features: String? - let resultFile: FileInfo? - let status: String - let workflowInstanceId: String? - let videoGenerateTime: String? - let createTime: String - let coverFile: FileInfo? - let description: String? - - struct FileInfo: Codable { - let id: String - let fileName: String? - let url: String? - // 为了兼容任意元数据结构,这里使用字典的最宽松版本 - // 如果后续需要更强类型,可以引入自定义的 AnyCodable/JSONValue - let metadata: [String: String]? - - enum CodingKeys: String, CodingKey { - case id - case fileName = "file_name" - case url - case metadata - } - } - - enum CodingKeys: String, CodingKey { - case id - case boxCode = "box_code" - case userId = "user_id" - case name - case boxType = "box_type" - case features - case resultFile = "result_file" - case status - case workflowInstanceId = "workflow_instance_id" - case videoGenerateTime = "video_generate_time" - case createTime = "create_time" - case coverFile = "cover_file" - case description - } - } - // 盲盒数量 - struct BlindCount: Codable { - let availableQuantity: Int - - enum CodingKeys: String, CodingKey { - case availableQuantity = "available_quantity" - } - } - - // MARK: - BlindBox Response Model - - struct BlindBoxData: Codable { - let id: Int64 - let boxCode: String - let userId: Int64 - let name: String - let boxType: String - let features: String? - let url: String? - let status: String - let workflowInstanceId: String? - // 视频生成时间 - let videoGenerateTime: String? - let createTime: String - let description: String? - - enum CodingKeys: String, CodingKey { - case id - case boxCode = "box_code" - case userId = "user_id" - case name - case boxType = "box_type" - case features - case url - case status - case workflowInstanceId = "workflow_instance_id" - case videoGenerateTime = "video_generate_time" - case createTime = "create_time" - case description - } - - init(id: Int64, boxCode: String, userId: Int64, name: String, boxType: String, features: String?, url: String?, status: String, workflowInstanceId: String?, videoGenerateTime: String?, createTime: String, description: String?) { - self.id = id - self.boxCode = boxCode - self.userId = userId - self.name = name - self.boxType = boxType - self.features = features - self.url = url - self.status = status - self.workflowInstanceId = workflowInstanceId - self.videoGenerateTime = videoGenerateTime - self.createTime = createTime - self.description = description - } - - init(from listItem: BlindList) { - self.init( - id: Int64(listItem.id) ?? 0, - boxCode: listItem.boxCode, - userId: Int64(listItem.userId) ?? 0, - name: listItem.name, - boxType: listItem.boxType, - features: listItem.features, - url: listItem.resultFile?.url, - status: listItem.status, - workflowInstanceId: listItem.workflowInstanceId, - videoGenerateTime: listItem.videoGenerateTime, - createTime: listItem.createTime, - description: listItem.description - ) - } - } - +struct BlindBoxView: View { let mediaType: BlindBoxMediaType @State private var showModal = false // 控制用户资料弹窗显示 @State private var showSettings = false // 控制设置页面显示 diff --git a/wake/Models/BlindModels.swift b/wake/Models/BlindModels.swift new file mode 100644 index 0000000..76412f5 --- /dev/null +++ b/wake/Models/BlindModels.swift @@ -0,0 +1,131 @@ +import Foundation + +// MARK: - Blind Box Media Type +enum BlindBoxMediaType { + case video + case image + case all +} + +// MARK: - Blind Box List +struct BlindList: Codable, Identifiable { + // API 返回为字符串,这里按字符串处理 + let id: String + let boxCode: String + let userId: String + let name: String + let boxType: String + let features: String? + let resultFile: FileInfo? + let status: String + let workflowInstanceId: String? + let videoGenerateTime: String? + let createTime: String + let coverFile: FileInfo? + let description: String? + + struct FileInfo: Codable { + let id: String + let fileName: String? + let url: String? + // 为了兼容任意元数据结构,这里使用字典的最宽松版本 + // 如果后续需要更强类型,可以引入自定义的 AnyCodable/JSONValue + let metadata: [String: String]? + + enum CodingKeys: String, CodingKey { + case id + case fileName = "file_name" + case url + case metadata + } + } + + enum CodingKeys: String, CodingKey { + case id + case boxCode = "box_code" + case userId = "user_id" + case name + case boxType = "box_type" + case features + case resultFile = "result_file" + case status + case workflowInstanceId = "workflow_instance_id" + case videoGenerateTime = "video_generate_time" + case createTime = "create_time" + case coverFile = "cover_file" + case description + } +} + +// MARK: - Blind Box Count +struct BlindCount: Codable { + let availableQuantity: Int + + enum CodingKeys: String, CodingKey { + case availableQuantity = "available_quantity" + } +} + +// MARK: - Blind Box Data +struct BlindBoxData: Codable { + let id: Int64 + let boxCode: String + let userId: Int64 + let name: String + let boxType: String + let features: String? + let url: String? + let status: String + let workflowInstanceId: String? + // 视频生成时间 + let videoGenerateTime: String? + let createTime: String + let description: String? + + enum CodingKeys: String, CodingKey { + case id + case boxCode = "box_code" + case userId = "user_id" + case name + case boxType = "box_type" + case features + case url + case status + case workflowInstanceId = "workflow_instance_id" + case videoGenerateTime = "video_generate_time" + case createTime = "create_time" + case description + } + + init(id: Int64, boxCode: String, userId: Int64, name: String, boxType: String, features: String?, url: String?, status: String, workflowInstanceId: String?, videoGenerateTime: String?, createTime: String, description: String?) { + self.id = id + self.boxCode = boxCode + self.userId = userId + self.name = name + self.boxType = boxType + self.features = features + self.url = url + self.status = status + self.workflowInstanceId = workflowInstanceId + self.videoGenerateTime = videoGenerateTime + self.createTime = createTime + self.description = description + } + + init(from listItem: BlindList) { + self.init( + id: Int64(listItem.id) ?? 0, + boxCode: listItem.boxCode, + userId: Int64(listItem.userId) ?? 0, + name: listItem.name, + boxType: listItem.boxType, + features: listItem.features, + url: listItem.resultFile?.url, + status: listItem.status, + workflowInstanceId: listItem.workflowInstanceId, + videoGenerateTime: listItem.videoGenerateTime, + createTime: listItem.createTime, + description: listItem.description + ) + } +} diff --git a/wake/Utils/Router.swift b/wake/Utils/Router.swift index 0bd118f..609229b 100644 --- a/wake/Utils/Router.swift +++ b/wake/Utils/Router.swift @@ -7,7 +7,7 @@ enum AppRoute: Hashable { case feedbackView case feedbackDetail(type: FeedbackView.FeedbackType) case mediaUpload - case blindBox(mediaType: BlindBoxView.BlindBoxMediaType) + case blindBox(mediaType: BlindBoxMediaType) case blindOutcome(media: MediaType, time: String? = nil, description: String? = nil) case memories case subscribe