diff --git a/dimensionhub/Views/DetailView.swift b/dimensionhub/Views/DetailView.swift index 6e41a7f..091f71f 100644 --- a/dimensionhub/Views/DetailView.swift +++ b/dimensionhub/Views/DetailView.swift @@ -47,6 +47,10 @@ final class DetailModel { var status: Int = 0 var channels: [Channel] = [] + // 当前选中的channel + var selectedChannelIdx: Int = 0 + var selectedEpisodes: [Episode] = [] + @MainActor func loadData(dramaId: Int) async { let response = await API.getDramaDetail(as: DramaDetailResponse.self) @@ -59,8 +63,17 @@ final class DetailModel { self.voiceActors = detail.voice_actors self.status = detail.status 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 { @@ -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 {