fix
This commit is contained in:
parent
1d12ff5625
commit
73c4f260d3
@ -12,21 +12,27 @@ import Observation
|
|||||||
final class FollowListModel {
|
final class FollowListModel {
|
||||||
|
|
||||||
struct DramaItem: Codable {
|
struct DramaItem: Codable {
|
||||||
struct Episode: Codable, Identifiable {
|
|
||||||
let id = UUID().uuidString
|
struct Channel: Codable {
|
||||||
let name: String
|
struct Episode: Codable, Identifiable {
|
||||||
let thumb: String
|
let id = UUID().uuidString
|
||||||
let num_name: String
|
let name: String
|
||||||
let play: String
|
let thumb: String
|
||||||
|
let num_name: String
|
||||||
enum CodingKeys: String, CodingKey {
|
let play: String
|
||||||
case name, thumb, num_name, play
|
|
||||||
|
enum CodingKeys: String, CodingKey {
|
||||||
|
case name, thumb, num_name, play
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let name: String
|
||||||
|
let episodes: [Episode]
|
||||||
}
|
}
|
||||||
|
|
||||||
let id: Int
|
let id: Int
|
||||||
let title: String
|
let title: String
|
||||||
let episodes: [Episode]
|
let channels: [Channel]
|
||||||
}
|
}
|
||||||
|
|
||||||
struct FavorResponse: Codable {
|
struct FavorResponse: Codable {
|
||||||
@ -34,6 +40,8 @@ final class FollowListModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var dramas: [DramaItem]
|
var dramas: [DramaItem]
|
||||||
|
// 选中的频道信息
|
||||||
|
var checkedChannels: [Int:Int] = [:]
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
self.dramas = []
|
self.dramas = []
|
||||||
@ -48,14 +56,24 @@ final class FollowListModel {
|
|||||||
self.preloadImages(dramas: result.dramas)
|
self.preloadImages(dramas: result.dramas)
|
||||||
await MainActor.run {
|
await MainActor.run {
|
||||||
self.dramas = result.dramas
|
self.dramas = result.dramas
|
||||||
|
result.dramas.forEach {drama in
|
||||||
|
self.checkedChannels[drama.id] = 0
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func changeChannel(dramaId: Int, channelId: Int) {
|
||||||
|
self.checkedChannels[dramaId] = channelId
|
||||||
|
}
|
||||||
|
|
||||||
private func preloadImages(dramas: [DramaItem]) {
|
private func preloadImages(dramas: [DramaItem]) {
|
||||||
let cacheManager = CacheManager.shared
|
let cacheManager = CacheManager.shared
|
||||||
dramas.forEach { dramaItem in
|
dramas.forEach { dramaItem in
|
||||||
let urls = dramaItem.episodes.map { $0.thumb }
|
let urls = dramaItem.channels.flatMap { channel in
|
||||||
|
channel.episodes.map { $0.thumb }
|
||||||
|
}
|
||||||
|
|
||||||
if urls.count > 0 {
|
if urls.count > 0 {
|
||||||
Task.detached(priority: .medium) {
|
Task.detached(priority: .medium) {
|
||||||
try? await cacheManager.preloadImages(urls: urls)
|
try? await cacheManager.preloadImages(urls: urls)
|
||||||
|
|||||||
@ -25,7 +25,7 @@ struct FollowListView: View {
|
|||||||
ScrollView(.vertical, showsIndicators: false) {
|
ScrollView(.vertical, showsIndicators: false) {
|
||||||
LazyVStack(alignment: .center) {
|
LazyVStack(alignment: .center) {
|
||||||
ForEach(followModel.dramas, id: \.id) { drama in
|
ForEach(followModel.dramas, id: \.id) { drama in
|
||||||
DramaCellView(dramaItem: drama)
|
DramaCellView(dramaItem: drama, followModel: followModel)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -55,6 +55,7 @@ extension FollowListView {
|
|||||||
// 显示剧集的列表信息
|
// 显示剧集的列表信息
|
||||||
struct DramaCellView: View {
|
struct DramaCellView: View {
|
||||||
let dramaItem: FollowListModel.DramaItem
|
let dramaItem: FollowListModel.DramaItem
|
||||||
|
let followModel: FollowListModel
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
VStack(alignment: .leading) {
|
VStack(alignment: .leading) {
|
||||||
@ -65,10 +66,23 @@ extension FollowListView {
|
|||||||
.foregroundColor(Color(hex: "#333333"))
|
.foregroundColor(Color(hex: "#333333"))
|
||||||
.lineLimit(1)
|
.lineLimit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 渠道列表
|
||||||
|
HStack(alignment: .center, spacing: 15) {
|
||||||
|
ForEach(Array(dramaItem.channels.enumerated()), id: \.offset) { idx, channel in
|
||||||
|
Text(channel.name)
|
||||||
|
.font(.system(size: 13))
|
||||||
|
.foregroundColor(idx == followModel.checkedChannels[dramaItem.id] ? Color(hex: "#169BD5") : Color(hex: "#666666"))
|
||||||
|
.onTapGesture {
|
||||||
|
followModel.changeChannel(dramaId: dramaItem.id, channelId: idx)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Spacer()
|
||||||
|
}
|
||||||
|
|
||||||
ScrollView(.horizontal, showsIndicators: false) {
|
ScrollView(.horizontal, showsIndicators: false) {
|
||||||
LazyHStack(alignment: .center, spacing: 5) {
|
LazyHStack(alignment: .center, spacing: 5) {
|
||||||
ForEach(dramaItem.episodes) { item in
|
ForEach(dramaItem.channels[followModel.checkedChannels[dramaItem.id]!].episodes) { item in
|
||||||
DramaCellEpisodeView(item: item)
|
DramaCellEpisodeView(item: item)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -78,7 +92,7 @@ extension FollowListView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct DramaCellEpisodeView: View {
|
struct DramaCellEpisodeView: View {
|
||||||
let item: FollowListModel.DramaItem.Episode
|
let item: FollowListModel.DramaItem.Channel.Episode
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
VStack(alignment: .center) {
|
VStack(alignment: .center) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user