简单的UI调整

This commit is contained in:
anlicheng 2025-07-29 12:20:37 +08:00
parent d3cf14fc08
commit 88a82545ee
6 changed files with 60 additions and 33 deletions

View File

@ -14,7 +14,7 @@ final class AppNavigation: ObservableObject {
enum Destination: Hashable {
case detail(id: Int)
case followList
case followList(num: Int)
case search
}

View File

@ -45,16 +45,17 @@ final class FollowListModel {
self.dramas = []
}
func loadData(userId: String) async {
func loadData(userId: String) async -> Int {
let response = await API.getUserFollowList(userId: userId, as: FavorResponse.self)
switch response {
case .error(let code, let message):
print("index load data get error_code: \(code), message: \(message)")
return 0
case .result(let result):
self.preloadImages(dramas: result.dramas)
await MainActor.run {
self.dramas = result.dramas
}
return result.dramas.count
}
}

View File

@ -12,6 +12,7 @@ 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) {
@ -20,6 +21,10 @@ struct FollowListView: View {
.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) {
@ -30,6 +35,25 @@ struct FollowListView: View {
}
}
} else {
ProgressView()
}
}
.frame(width: 370)
.task {
self.num = await self.followModel.loadData(userId: self.userId)
}
}
}
.ignoresSafeArea(edges: .bottom)
.navigationTitle("番剧补完计划")
}
}
extension FollowListView {
struct EmptyFollowListView: View {
var body: some View {
VStack {
Spacer()
Text("这里什么都没有")
@ -39,18 +63,6 @@ struct FollowListView: View {
}
}
}
.frame(width: 370)
}
.ignoresSafeArea(edges: .bottom)
.navigationTitle("番剧补完计划")
.task {
await self.followModel.loadData(userId: self.userId)
}
}
}
extension FollowListView {
//
struct DramaCellView: View {
@ -140,5 +152,5 @@ extension FollowListView {
}
#Preview {
FollowListView()
FollowListView(num: 0)
}

View File

@ -24,6 +24,9 @@ struct IndexMainView: View {
@State private var selectGroupId: String = ""
@State private var showDateNavPopover: Bool = false
//
@State private var noMoreNewest: Bool = false
//
@State private var headerRefreshing: Bool = false
@State private var footerRefreshing: Bool = false
@ -53,7 +56,7 @@ struct IndexMainView: View {
.contentShape(Rectangle())
.highPriorityGesture(
TapGesture().onEnded {
appNavigation.append(dest: .followList)
appNavigation.append(dest: .followList(num: Int(indexModel.follow_num) ?? 0))
}
)
.zIndex(1)
@ -68,6 +71,12 @@ struct IndexMainView: View {
ScrollView(.vertical, showsIndicators: false) {
ScrollViewOffsetReader(offset: $scrollOffset)
if noMoreNewest {
Text("没有了")
.foregroundColor(.black)
.autoDismiss(after: 1.5)
}
MixGroupLabelView(fixedDramaGroup: indexModel.fixedDramaGroup) {
if let groupId = indexModel.fixedDramaGroup?.group_id {
selectGroupId = groupId
@ -100,6 +109,7 @@ struct IndexMainView: View {
ProgressView()
} else {
Text("没有了")
.foregroundColor(.black)
.autoDismiss(after: 1.5)
}
}
@ -117,11 +127,13 @@ struct IndexMainView: View {
//
self.headerRefreshing = true
self.noMoreNewest = false
Task { @MainActor in
await self.indexModel.loadPrevUpdateDramasTask(userId: self.userId) { anchorGroupElement in
await self.indexModel.loadPrevUpdateDramasTask(userId: self.userId) { hasData in
DispatchQueue.main.async {
self.headerRefreshing = false
self.noMoreNewest = !hasData
}
}
}

View File

@ -261,13 +261,11 @@ final class IndexModel {
}
}
func loadPrevUpdateDramasTask(userId: String, callback: (GroupElement?) -> Void) async {
func loadPrevUpdateDramasTask(userId: String, callback: (Bool) -> Void) async {
guard !self.isMoreLoading else {
return
}
let anchorGroupElement = dramaGroupElements.first
// id
let dramaIds = self.getDramaIds(self.updateDramaGroups)
// id
@ -283,10 +281,14 @@ final class IndexModel {
self.fixedDramaGroup = self.updateDramaGroups.first
self.dramaGroupElements = transformUpdateDramaGroups(groups: self.updateDramaGroups)
//
callback(anchorGroupElement)
displayDramaGroups(self.updateDramaGroups, label: "after")
//
callback(true)
} else {
callback(false)
}
} else {
callback(false)
}
self.isMoreLoading = false
}

View File

@ -50,8 +50,8 @@ struct dimensionhubApp: App {
switch dest {
case .detail(id: let id):
DetailView(id: id)
case .followList:
FollowListView()
case .followList(num: let num):
FollowListView(num: num)
case .search:
SearchView()
}