fix
This commit is contained in:
parent
0b26a83cf4
commit
5e36018722
@ -47,6 +47,10 @@ final class DetailModel {
|
|||||||
var status: Int = 0
|
var status: Int = 0
|
||||||
var channels: [Channel] = []
|
var channels: [Channel] = []
|
||||||
|
|
||||||
|
// 当前选中的channel
|
||||||
|
var selectedChannelIdx: Int = 0
|
||||||
|
var selectedEpisodes: [Episode] = []
|
||||||
|
|
||||||
@MainActor
|
@MainActor
|
||||||
func loadData(dramaId: Int) async {
|
func loadData(dramaId: Int) async {
|
||||||
let response = await API.getDramaDetail(as: DramaDetailResponse.self)
|
let response = await API.getDramaDetail(as: DramaDetailResponse.self)
|
||||||
@ -59,8 +63,17 @@ final class DetailModel {
|
|||||||
self.voiceActors = detail.voice_actors
|
self.voiceActors = detail.voice_actors
|
||||||
self.status = detail.status
|
self.status = detail.status
|
||||||
self.channels = detail.channels
|
self.channels = detail.channels
|
||||||
|
|
||||||
|
self.selectedChannelIdx = 0
|
||||||
|
self.selectedEpisodes = detail.channels[0].episodes
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func toggleChannel(channelIdx: Int) {
|
||||||
|
self.selectedChannelIdx = channelIdx
|
||||||
|
self.selectedEpisodes = self.channels[channelIdx].episodes
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct DetailView: View {
|
struct DetailView: View {
|
||||||
@ -100,7 +113,39 @@ struct DetailView: View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 渠道列表
|
// 渠道列表
|
||||||
|
HStack(alignment: .center) {
|
||||||
|
ForEach(Array(detailModel.channels.enumerated()), id: \.offset) { idx, channel in
|
||||||
|
Text(channel.name)
|
||||||
|
.font(.system(size: 16))
|
||||||
|
.foregroundColor(idx == detailModel.selectedChannelIdx ? .blue : .black)
|
||||||
|
.onTapGesture {
|
||||||
|
detailModel.toggleChannel(channelIdx: idx)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 渠道相关的数据列表
|
||||||
|
ScrollView(.horizontal, showsIndicators: false) {
|
||||||
|
HStack(alignment: .center) {
|
||||||
|
ForEach(detailModel.selectedEpisodes, id: \.id) { episode in
|
||||||
|
VStack(alignment: .center) {
|
||||||
|
AsyncImage(url: URL(string: episode.thumb)) { image in
|
||||||
|
image.resizable()
|
||||||
|
} placeholder: {
|
||||||
|
ProgressView()
|
||||||
|
}
|
||||||
|
.frame(width: 80, height: 80)
|
||||||
|
.overlay {
|
||||||
|
Text(episode.numName)
|
||||||
|
}
|
||||||
|
|
||||||
|
Text(episode.name)
|
||||||
|
.lineLimit(1)
|
||||||
|
}
|
||||||
|
.frame(width: 100, height: 120)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
.task {
|
.task {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user