dimensionhub/dimensionhub/Views/FollowList/FollowListView.swift
2025-09-10 16:40:33 +08:00

158 lines
5.4 KiB
Swift

//
// FavorView.swift
// dimensionhub
//
// Created by on 2025/3/18.
//
import Foundation
import SwiftUI
struct FollowListView: View {
@Environment(\.userId) private var userId
@State var followModel = FollowListModel()
@State var isMoreLoading: Bool = false
@State var num: Int
var body: some View {
VStack(alignment: .center) {
Rectangle()
.frame(height: 0)
.background(Color(hex: "#F2F2F2"), ignoresSafeAreaEdges: .top)
.border(.red)
if num == 0 {
EmptyFollowListView()
.frame(width: 370)
} else {
Group {
if followModel.dramas.count > 0 {
ScrollView(.vertical, showsIndicators: false) {
LazyVStack(alignment: .center) {
ForEach(followModel.dramas, id: \.id) { drama in
DramaCellView(dramaModel: FollowDramaModel(drama: drama))
}
}
}
} else {
ProgressView()
}
}
.frame(width: 370)
.task {
self.num = await self.followModel.loadData(userId: self.userId)
_ = await API.userEvent(userId: self.userId, event: "view_follow_list", as: String.self)
}
}
}
.ignoresSafeArea(edges: .bottom)
.navigationTitle("番剧补完计划")
}
}
extension FollowListView {
struct EmptyFollowListView: View {
var body: some View {
VStack {
Spacer()
Text("这里什么都没有")
.font(.system(size: 16))
.foregroundColor(.black)
Spacer()
}
}
}
//
struct DramaCellView: View {
let dramaModel: FollowDramaModel
var body: some View {
VStack(alignment: .leading, spacing: 8) {
NavigationLink(destination: DetailView(id: dramaModel.drama.id, channelName: nil)) {
HStack {
Text(dramaModel.drama.title)
.font(.system(size: 20))
.foregroundColor(Color(hex: "#333333"))
.lineLimit(1)
Spacer()
}
}
//
HStack(alignment: .center, spacing: 15) {
ForEach(Array(dramaModel.drama.channels.enumerated()), id: \.offset) { idx, channel in
Text(channel.name)
.font(.system(size: 13, weight: idx == dramaModel.checkedChannelId ? .medium : .regular))
.foregroundColor(idx == dramaModel.checkedChannelId ? Color(hex: "#202020") : Color(hex: "#666666"))
.onTapGesture {
dramaModel.changeChannel(channelId: idx)
}
}
Spacer()
}
ScrollView(.horizontal, showsIndicators: false) {
LazyHStack(alignment: .center, spacing: 5) {
ForEach(dramaModel.episodes) { item in
DramaCellEpisodeView(item: item)
}
}
}
}
}
}
struct DramaCellEpisodeView: View {
let item: FollowListModel.DramaItem.Channel.Episode
var body: some View {
VStack(alignment: .center) {
GeometryReader { geometry in
let width = geometry.frame(in: .local).width
FlexImage(urlString: item.thumb, width: width, height: 80, placeholder: "ph_img_medium")
.frame(width: width, height: 80)
.overlay(alignment: .topLeading) {
if !item.num_name.isEmpty {
HStack(alignment: .center) {
Text(item.num_name)
.font(.system(size: 12))
.foregroundColor(.white)
.lineLimit(1)
}
.padding(3)
.background(
Color.black.opacity(0.6)
)
.cornerRadius(3)
.padding(3)
} else {
EmptyView()
}
}
}
Text(item.name)
.font(.system(size: 12))
.foregroundColor(Color(hex: "#333333"))
.lineLimit(1)
}
.frame(width: 120, height: 100)
.onTapGesture {
if let playUrl = URL(string: item.play) {
UIApplication.shared.open(playUrl)
}
}
}
}
}
#Preview {
FollowListView(num: 0)
}