2025-08-15 16:51:55 +08:00

94 lines
2.9 KiB
Swift

//
// ListView.swift
// dimensionhub
//
// Created by on 2025/2/21.
//
import SwiftUI
struct ListView: View {
@Environment(\.userId) private var userId
@State var detailModel = ListModel()
let id: Int
let selectedChannelIdx: Int
var body: some View {
VStack(alignment: .center, spacing: 20) {
HStack {
Spacer()
}
.padding([.leading, .top, .bottom], 10)
.background(Color(hex: "#F2F2F2"), ignoresSafeAreaEdges: [.top])
VStack(alignment: .center) {
//
HStack(alignment: .center, spacing: 15) {
ForEach(Array(detailModel.channels.enumerated()), id: \.offset) { idx, channel in
Text(channel.name)
.font(.system(size: 13))
.foregroundColor(idx == detailModel.selectedChannelIdx ? Color(hex: "#169BD5") : Color(hex: "#666666"))
.onTapGesture {
detailModel.toggleChannel(channelIdx: idx)
}
}
Spacer()
}
//
ScrollView(.vertical, showsIndicators: false) {
LazyVStack(alignment: .center, spacing: 15) {
ForEach(detailModel.selectedEpisodes) { episode in
EpisodeView(episode: episode)
}
}
}
Spacer()
}
.frame(width: 370, alignment: .center)
}
.navigationTitle(detailModel.name)
.task {
await detailModel.loadData(userId: self.userId, id: self.id, selectedChannelIdx: self.selectedChannelIdx)
}
}
}
extension ListView {
struct EpisodeView: View {
let episode: ListModel.Episode
var body: some View {
HStack(alignment: .center) {
FlexImage(urlString: episode.thumb, width: 90, height: 60, placeholder: "ph_img_medium")
.frame(width: 90, height: 60)
VStack(alignment: .leading, spacing: 20) {
Text(episode.num_name)
.font(.system(size: 12))
.foregroundColor(Color(hex: "#333333"))
Text(episode.name)
.font(.system(size: 12))
.foregroundColor(Color(hex: "#333333"))
.lineLimit(1)
}
Spacer()
}
.onTapGesture {
if let playUrl = URL(string: episode.play) {
UIApplication.shared.open(playUrl)
}
}
}
}
}
#Preview {
ListView(id: 19625, selectedChannelIdx: 0)
}