fix data
This commit is contained in:
parent
d785eef3df
commit
d74414a6c5
@ -77,11 +77,13 @@ struct API {
|
||||
do {
|
||||
let (data, response) = try await URLSession.shared.data(for: request)
|
||||
guard let response = response as? HTTPURLResponse, response.statusCode == 200 else {
|
||||
print("url: \(request.url!.absoluteString)")
|
||||
// print(String(data: data, encoding: .utf8)!)
|
||||
return .error(-1, "http status error")
|
||||
}
|
||||
|
||||
let x = String(data: data, encoding: .utf8)!
|
||||
print("url: \(request.url!.path()), data is: \(x)")
|
||||
// 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)
|
||||
|
||||
@ -90,6 +90,8 @@ final class DetailModel {
|
||||
print(message)
|
||||
case .result(let detail):
|
||||
self.name = detail.name
|
||||
self.summary = detail.summary
|
||||
self.thumb = detail.thumb
|
||||
self.statuses = detail.status.flatMap({ s in
|
||||
if let status = DramaStatus(s) {
|
||||
return [status]
|
||||
@ -123,18 +125,24 @@ struct DetailView: View {
|
||||
.font(.system(size: 28))
|
||||
.fontWeight(.bold)
|
||||
.foregroundColor(Color(hex: "#333333"))
|
||||
|
||||
Text(detailModel.summary)
|
||||
.lineLimit(3)
|
||||
.multilineTextAlignment(.leading)
|
||||
.padding()
|
||||
//.frame(maxWidth: .infinity, alignment: .leading)
|
||||
}
|
||||
.padding([.top, .leading], 10)
|
||||
.background(Color(hex: "#F2F2F2"), ignoresSafeAreaEdges: [.bottom])
|
||||
|
||||
// HStack(alignment: .center, spacing: 10) {
|
||||
// Spacer()
|
||||
// ForEach(detailModel.statuses, id: \.status) { status in
|
||||
// FollowButtonView(title: status.config.name, bgColor: status.config.bgColor, fontColor: status.config.fontColor) {
|
||||
// print("call me follow button clicked")
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
HStack(alignment: .center, spacing: 10) {
|
||||
Spacer()
|
||||
ForEach(detailModel.statuses, id: \.status) { status in
|
||||
FollowButtonView(title: status.config.name, bgColor: status.config.bgColor, fontColor: status.config.fontColor) {
|
||||
print("call me follow button clicked")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 渠道列表
|
||||
HStack(alignment: .center, spacing: 15) {
|
||||
@ -203,6 +211,7 @@ struct DetailView: View {
|
||||
.frame(width: 370, alignment: .center)
|
||||
.task {
|
||||
await detailModel.loadData(userId: 1, id: self.id)
|
||||
print(detailModel.summary)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -54,6 +54,8 @@ final class ListModel {
|
||||
print(message)
|
||||
case .result(let detail):
|
||||
self.name = detail.name
|
||||
self.summary = detail.summary
|
||||
self.thumb = detail.thumb
|
||||
self.channels = detail.channels
|
||||
|
||||
self.selectedChannelIdx = 0
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user