fix
This commit is contained in:
parent
a3ae2c6630
commit
4ac9a2d5bf
@ -29,8 +29,11 @@ struct API {
|
|||||||
|
|
||||||
static let url = "http://localhost:18085/api/dimensionhub/"
|
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)
|
return await doRequest(request: request, as: T.self)
|
||||||
}
|
}
|
||||||
@ -61,6 +64,9 @@ struct API {
|
|||||||
return .error(-1, "http status error")
|
return .error(-1, "http status error")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let x = String(data: data, encoding: .utf8)!
|
||||||
|
|
||||||
|
print("url: \(request.url?.path()), data is: \(x)")
|
||||||
do {
|
do {
|
||||||
let result = try JSONDecoder().decode(APISuccessResponse<T>.self, from: data)
|
let result = try JSONDecoder().decode(APISuccessResponse<T>.self, from: data)
|
||||||
return .result(result.result)
|
return .result(result.result)
|
||||||
|
|||||||
@ -17,14 +17,7 @@ final class IndexModel {
|
|||||||
let id: Int32
|
let id: Int32
|
||||||
let name: String
|
let name: String
|
||||||
let thumb: String
|
let thumb: String
|
||||||
let numName: String
|
let num_name: String
|
||||||
|
|
||||||
enum CodingKeys: String, CodingKey {
|
|
||||||
case id = "id"
|
|
||||||
case name = "name"
|
|
||||||
case thumb = "thumb"
|
|
||||||
case numName = "num_name"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let id: Int32
|
let id: Int32
|
||||||
@ -36,23 +29,18 @@ final class IndexModel {
|
|||||||
struct Item: Codable {
|
struct Item: Codable {
|
||||||
let id: Int
|
let id: Int
|
||||||
let name: String
|
let name: String
|
||||||
|
let time: Int
|
||||||
let thumb: String
|
let thumb: String
|
||||||
let desc: String
|
let status: String
|
||||||
}
|
}
|
||||||
|
|
||||||
let groupId: String
|
let group_id: String
|
||||||
let groupName: String
|
let group_name: String
|
||||||
let items: [Item]
|
let items: [Item]
|
||||||
|
|
||||||
enum CodingKeys: String, CodingKey {
|
|
||||||
case groupId = "group_id"
|
|
||||||
case groupName = "group_name"
|
|
||||||
case items
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct IndexResponse: Codable {
|
struct IndexResponse: Codable {
|
||||||
let updateDramas: [UpdateDramaGroup]
|
let update_dramas: [UpdateDramaGroup]
|
||||||
let dramas: [DramaItem]
|
let dramas: [DramaItem]
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -82,14 +70,14 @@ final class IndexModel {
|
|||||||
|
|
||||||
@MainActor
|
@MainActor
|
||||||
func loadData() async {
|
func loadData() async {
|
||||||
let response = await API.getIndexData(as: IndexResponse.self)
|
let response = await API.getIndexData(userId: 1, as: IndexResponse.self)
|
||||||
switch response {
|
switch response {
|
||||||
case .error(let code, let message):
|
case .error(let code, let message):
|
||||||
print(code)
|
print(code)
|
||||||
print(message)
|
print(message)
|
||||||
case .result(let result):
|
case .result(let result):
|
||||||
self.dramas = result.dramas
|
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):
|
case .group(let group):
|
||||||
HStack {
|
HStack {
|
||||||
Spacer()
|
Spacer()
|
||||||
Text(group.groupName)
|
Text(group.group_name)
|
||||||
.font(.system(size: 18))
|
.font(.system(size: 18))
|
||||||
.fontWeight(.regular)
|
.fontWeight(.regular)
|
||||||
.onTapGesture {
|
.onTapGesture {
|
||||||
selectGroupId = group.groupId
|
selectGroupId = group.group_id
|
||||||
print("current group_id: \(self.selectGroupId)")
|
print("current group_id: \(self.selectGroupId)")
|
||||||
indexModel.selectedDate = group.groupId
|
indexModel.selectedDate = group.group_id
|
||||||
showDateNavPopover = true
|
showDateNavPopover = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -185,7 +173,7 @@ struct IndexView: View {
|
|||||||
.foregroundColor(Color(hex: "#333333"))
|
.foregroundColor(Color(hex: "#333333"))
|
||||||
.lineLimit(1)
|
.lineLimit(1)
|
||||||
|
|
||||||
Text(item.desc)
|
Text(item.status)
|
||||||
.font(.system(size: 12))
|
.font(.system(size: 12))
|
||||||
.foregroundColor(Color(hex: "#333333"))
|
.foregroundColor(Color(hex: "#333333"))
|
||||||
.lineLimit(1)
|
.lineLimit(1)
|
||||||
@ -284,7 +272,7 @@ extension IndexView {
|
|||||||
.overlay {
|
.overlay {
|
||||||
VStack {
|
VStack {
|
||||||
HStack(alignment: .center) {
|
HStack(alignment: .center) {
|
||||||
Text(item.numName)
|
Text(item.num_name)
|
||||||
.font(.system(size: 12))
|
.font(.system(size: 12))
|
||||||
.foregroundColor(Color(hex: "#333333"))
|
.foregroundColor(Color(hex: "#333333"))
|
||||||
|
|
||||||
@ -320,7 +308,7 @@ extension IndexView {
|
|||||||
var body: some View {
|
var body: some View {
|
||||||
switch showItem.element {
|
switch showItem.element {
|
||||||
case .group(let group):
|
case .group(let group):
|
||||||
Text(group.groupName)
|
Text(group.group_name)
|
||||||
.onTapGesture {
|
.onTapGesture {
|
||||||
showDateNavPopover = true
|
showDateNavPopover = true
|
||||||
}
|
}
|
||||||
@ -337,7 +325,7 @@ extension IndexView {
|
|||||||
Text(item.name)
|
Text(item.name)
|
||||||
.lineLimit(1)
|
.lineLimit(1)
|
||||||
|
|
||||||
Text(item.desc)
|
Text(item.status)
|
||||||
.lineLimit(1)
|
.lineLimit(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user