This commit is contained in:
anlicheng 2025-03-18 11:43:33 +08:00
parent d8dae2fa3c
commit 605062c7a8
3 changed files with 46 additions and 134 deletions

View File

@ -54,7 +54,7 @@ final class DetailModel {
self.config = DisplayConfig(name: "前排占位", bgColor: .black, fontColor: .white) self.config = DisplayConfig(name: "前排占位", bgColor: .black, fontColor: .white)
case "following": case "following":
self.status = rawValue self.status = rawValue
self.config = DisplayConfig(name: "追番", bgColor: .black, fontColor: .white) self.config = DisplayConfig(name: "追番", bgColor: .black, fontColor: .white)
case "catching_up": case "catching_up":
self.status = rawValue self.status = rawValue
self.config = DisplayConfig(name: "补番", bgColor: .black, fontColor: .white) self.config = DisplayConfig(name: "补番", bgColor: .black, fontColor: .white)

View File

@ -78,6 +78,7 @@ final class FavorModel {
struct FavorView: View { struct FavorView: View {
@AppStorage("userId") private var userId: String = Utils.defaultUserId() @AppStorage("userId") private var userId: String = Utils.defaultUserId()
@Environment(\.dismiss) private var dismiss
@State var favorModel = FavorModel() @State var favorModel = FavorModel()
@State var isMoreLoading: Bool = false @State var isMoreLoading: Bool = false
@ -87,68 +88,63 @@ struct FavorView: View {
HStack(alignment: .center) { HStack(alignment: .center) {
Color.clear Color.clear
.overlay { .overlay(alignment: .leading) {
HStack(alignment: .center) { Text("< 番剧补完计划")
Text("亚次元") .font(.system(size: 16))
.font(.system(size: 16)) .foregroundColor(Color(hex: "#999999"))
.padding([.top, .bottom], 5) .padding([.top, .bottom], 5)
Spacer() .padding([.leading], 15)
.onTapGesture {
HStack { dismiss()
Text("♡ 12")
.font(.system(size: 16))
.padding([.top, .bottom], 5)
} }
}
.padding([.leading, .trailing], 15)
} }
} }
.frame(height: 50) .frame(height: 50)
.background(Color(hex: "#F2F2F2"), ignoresSafeAreaEdges: .top) .background(Color(hex: "#F2F2F2"), ignoresSafeAreaEdges: .top)
VStack(alignment: .center) { if favorModel.dramas.count > 0 {
VStack(alignment: .center) {
ScrollView(.vertical, showsIndicators: false) { ScrollView(.vertical, showsIndicators: false) {
HStack(alignment: .center) { ForEach(favorModel.dramas, id: \.id) { drama in
Spacer() DramaCellView(dramaItem: drama)
Text("番剧补完计划") }
.font(.system(size: 24))
.foregroundColor(Color(hex: "#999999")) Rectangle()
} .frame(height: 0)
.background(GeometryReader {
ForEach(favorModel.dramas, id: \.id) { drama in geometry in
DramaCellView(dramaItem: drama) Color.clear.onChange(of: geometry.frame(in: .global).minY) {_, offset in
}
let frame = geometry.frame(in: .global)
Rectangle() let screenBounds = UIScreen.main.bounds
.frame(height: 0) let contextFrame = geometry.frame(in: .named("indexScrollView"))
.background(GeometryReader {
geometry in if screenBounds.height - frame.minY > 50 && contextFrame.minY > 0 && !isMoreLoading {
Color.clear.onChange(of: geometry.frame(in: .global).minY) {_, offset in Task {
self.isMoreLoading = true
let frame = geometry.frame(in: .global) await self.favorModel.loadMoreFavorDramas(userId: userId)
let screenBounds = UIScreen.main.bounds self.isMoreLoading = false
let contextFrame = geometry.frame(in: .named("indexScrollView")) }
if screenBounds.height - frame.minY > 50 && contextFrame.minY > 0 && !isMoreLoading {
Task {
self.isMoreLoading = true
await self.favorModel.loadMoreFavorDramas(userId: userId)
self.isMoreLoading = false
} }
} }
} })
})
if self.isMoreLoading {
if self.isMoreLoading { ProgressView()
ProgressView() }
} }
.coordinateSpace(name: "indexScrollView")
}
.frame(width: 370)
} else {
VStack {
Text("你还没有")
Spacer()
} }
.coordinateSpace(name: "indexScrollView")
} }
.frame(width: 370)
} }
.ignoresSafeArea(edges: .bottom) .ignoresSafeArea(edges: .bottom)
.navigationBarBackButtonHidden()
.task { .task {
await self.favorModel.loadData(userId: self.userId) await self.favorModel.loadData(userId: self.userId)
} }

View File

@ -47,10 +47,8 @@ final class IndexModel {
struct IndexResponse: Codable { struct IndexResponse: Codable {
let update_dramas: [UpdateDramaGroup] let update_dramas: [UpdateDramaGroup]
let dramas: [DramaItem]
} }
var dramas: [DramaItem]
var selectedDate: String var selectedDate: String
// //
@ -60,7 +58,6 @@ final class IndexModel {
private var isLoaded = false private var isLoaded = false
init() { init() {
self.dramas = []
self.selectedDate = "" self.selectedDate = ""
} }
@ -75,7 +72,6 @@ final class IndexModel {
case .error(let code, let message): case .error(let code, let message):
print("index load data get error_code: \(code), message: \(message)") print("index load data get error_code: \(code), message: \(message)")
case .result(let result): case .result(let result):
self.dramas = result.dramas
self.updateDramaGroups = result.update_dramas self.updateDramaGroups = result.update_dramas
} }
self.isLoaded = true self.isLoaded = true
@ -320,10 +316,6 @@ extension IndexView {
.foregroundColor(Color(hex: "#999999")) .foregroundColor(Color(hex: "#999999"))
} }
ForEach(indexModel.dramas, id: \.id) { drama in
DramaCellView(dramaItem: drama)
}
// //
VStack(alignment: .center, spacing: 10) { VStack(alignment: .center, spacing: 10) {
ForEach(indexModel.updateDramaGroups, id: \.group_id) { group in ForEach(indexModel.updateDramaGroups, id: \.group_id) { group in
@ -391,82 +383,6 @@ extension IndexView {
} }
} }
//
struct DramaCellView: View {
let dramaItem: IndexModel.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"))
}
ScrollView(.horizontal, showsIndicators: false) {
LazyHStack(alignment: .center, spacing: 5) {
ForEach(dramaItem.episodes) { item in
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)
}
}
}
}
}
}
}
}
// //
struct DramaGroupView: View { struct DramaGroupView: View {
let group: IndexModel.UpdateDramaGroup let group: IndexModel.UpdateDramaGroup