145 lines
4.8 KiB
Swift
145 lines
4.8 KiB
Swift
//
|
|
// FavorView.swift
|
|
// dimensionhub
|
|
//
|
|
// Created by 安礼成 on 2025/3/18.
|
|
//
|
|
|
|
import Foundation
|
|
import SwiftUI
|
|
|
|
struct FollowListView: View {
|
|
@AppStorage("userId") private var userId: String = Utils.defaultUserId()
|
|
@State var followModel = FollowListModel()
|
|
@State var isMoreLoading: Bool = false
|
|
|
|
var body: some View {
|
|
VStack(alignment: .center) {
|
|
Rectangle()
|
|
.frame(height: 0)
|
|
.background(Color(hex: "#F2F2F2"), ignoresSafeAreaEdges: .top)
|
|
.border(.red)
|
|
|
|
Group {
|
|
if followModel.dramas.count > 0 {
|
|
ScrollView(.vertical, showsIndicators: false) {
|
|
LazyVStack(alignment: .center) {
|
|
ForEach(followModel.dramas, id: \.id) { drama in
|
|
DramaCellView(dramaItem: drama)
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
VStack {
|
|
Spacer()
|
|
Text("这里什么都没有")
|
|
.font(.system(size: 16))
|
|
.foregroundColor(.black)
|
|
Spacer()
|
|
}
|
|
}
|
|
}
|
|
.frame(width: 370)
|
|
}
|
|
.ignoresSafeArea(edges: .bottom)
|
|
.navigationTitle("番剧补完计划")
|
|
.task {
|
|
await self.followModel.loadData(userId: self.userId)
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
extension FollowListView {
|
|
|
|
// 显示剧集的列表信息
|
|
struct DramaCellView: View {
|
|
let dramaItem: FollowListModel.DramaItem
|
|
|
|
var body: some View {
|
|
VStack(alignment: .leading) {
|
|
|
|
NavigationLink(destination: DetailView(id: dramaItem.id)) {
|
|
Text(dramaItem.title)
|
|
.font(.system(size: 20))
|
|
.foregroundColor(Color(hex: "#333333"))
|
|
.lineLimit(1)
|
|
}
|
|
|
|
ScrollView(.horizontal, showsIndicators: false) {
|
|
LazyHStack(alignment: .center, spacing: 5) {
|
|
ForEach(dramaItem.episodes) { item in
|
|
DramaCellEpisodeView(item: item)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
struct DramaCellEpisodeView: View {
|
|
let item: FollowListModel.DramaItem.Episode
|
|
|
|
var body: some View {
|
|
VStack(alignment: .center) {
|
|
GeometryReader { geometry in
|
|
|
|
AsyncImage(url: URL(string: item.thumb)) { phase in
|
|
switch phase {
|
|
case .empty:
|
|
ProgressView()
|
|
case .success(let image):
|
|
image
|
|
.resizable()
|
|
.aspectRatio(contentMode: .fill)
|
|
.frame(width: geometry.frame(in: .local).width, height: 80)
|
|
.clipped()
|
|
default:
|
|
Image("ph_img_medium")
|
|
.resizable()
|
|
.aspectRatio(contentMode: .fill)
|
|
.frame(width: geometry.frame(in: .local).width, height: 80)
|
|
.clipped()
|
|
}
|
|
}
|
|
.frame(width: geometry.frame(in: .local).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()
|
|
}
|