This commit is contained in:
anlicheng 2025-02-24 14:53:42 +08:00
parent a3ae2c6630
commit 4ac9a2d5bf
2 changed files with 23 additions and 29 deletions

View File

@ -29,8 +29,11 @@ struct API {
static let url = "http://localhost:18085/api/dimensionhub/"
static func getIndexData<T: Codable>(as: T.Type) async -> APIResponse<T> {
let request = URLRequest(url: URL(string: url + "index")!)
//
static let baseUrl = "http://39.98.184.67:8500"
static func getIndexData<T: Codable>(userId: Int, as: T.Type) async -> APIResponse<T> {
let request = URLRequest(url: URL(string: baseUrl + "/api/index?user_id=\(userId)")!)
return await doRequest(request: request, as: T.self)
}
@ -61,6 +64,9 @@ struct API {
return .error(-1, "http status error")
}
let x = String(data: data, encoding: .utf8)!
print("url: \(request.url?.path()), data is: \(x)")
do {
let result = try JSONDecoder().decode(APISuccessResponse<T>.self, from: data)
return .result(result.result)

View File

@ -17,14 +17,7 @@ final class IndexModel {
let id: Int32
let name: String
let thumb: String
let numName: String
enum CodingKeys: String, CodingKey {
case id = "id"
case name = "name"
case thumb = "thumb"
case numName = "num_name"
}
let num_name: String
}
let id: Int32
@ -36,23 +29,18 @@ final class IndexModel {
struct Item: Codable {
let id: Int
let name: String
let time: Int
let thumb: String
let desc: String
let status: String
}
let groupId: String
let groupName: String
let group_id: String
let group_name: String
let items: [Item]
enum CodingKeys: String, CodingKey {
case groupId = "group_id"
case groupName = "group_name"
case items
}
}
struct IndexResponse: Codable {
let updateDramas: [UpdateDramaGroup]
let update_dramas: [UpdateDramaGroup]
let dramas: [DramaItem]
}
@ -82,14 +70,14 @@ final class IndexModel {
@MainActor
func loadData() async {
let response = await API.getIndexData(as: IndexResponse.self)
let response = await API.getIndexData(userId: 1, as: IndexResponse.self)
switch response {
case .error(let code, let message):
print(code)
print(message)
case .result(let result):
self.dramas = result.dramas
self.showUpdateDramas = groupUpdateDramas(updateDramaGroups: result.updateDramas)
self.showUpdateDramas = groupUpdateDramas(updateDramaGroups: result.update_dramas)
}
}
@ -160,13 +148,13 @@ struct IndexView: View {
case .group(let group):
HStack {
Spacer()
Text(group.groupName)
Text(group.group_name)
.font(.system(size: 18))
.fontWeight(.regular)
.onTapGesture {
selectGroupId = group.groupId
selectGroupId = group.group_id
print("current group_id: \(self.selectGroupId)")
indexModel.selectedDate = group.groupId
indexModel.selectedDate = group.group_id
showDateNavPopover = true
}
}
@ -185,7 +173,7 @@ struct IndexView: View {
.foregroundColor(Color(hex: "#333333"))
.lineLimit(1)
Text(item.desc)
Text(item.status)
.font(.system(size: 12))
.foregroundColor(Color(hex: "#333333"))
.lineLimit(1)
@ -284,7 +272,7 @@ extension IndexView {
.overlay {
VStack {
HStack(alignment: .center) {
Text(item.numName)
Text(item.num_name)
.font(.system(size: 12))
.foregroundColor(Color(hex: "#333333"))
@ -320,7 +308,7 @@ extension IndexView {
var body: some View {
switch showItem.element {
case .group(let group):
Text(group.groupName)
Text(group.group_name)
.onTapGesture {
showDateNavPopover = true
}
@ -337,7 +325,7 @@ extension IndexView {
Text(item.name)
.lineLimit(1)
Text(item.desc)
Text(item.status)
.lineLimit(1)
}
}