简单的UI调整
This commit is contained in:
parent
d3cf14fc08
commit
88a82545ee
@ -14,7 +14,7 @@ final class AppNavigation: ObservableObject {
|
||||
|
||||
enum Destination: Hashable {
|
||||
case detail(id: Int)
|
||||
case followList
|
||||
case followList(num: Int)
|
||||
case search
|
||||
}
|
||||
|
||||
|
||||
@ -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
|
||||
}
|
||||
self.dramas = result.dramas
|
||||
|
||||
return result.dramas.count
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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,38 +21,49 @@ struct FollowListView: View {
|
||||
.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(dramaModel: FollowDramaModel(drama: drama))
|
||||
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 {
|
||||
VStack {
|
||||
Spacer()
|
||||
Text("这里什么都没有")
|
||||
.font(.system(size: 16))
|
||||
.foregroundColor(.black)
|
||||
Spacer()
|
||||
} else {
|
||||
ProgressView()
|
||||
}
|
||||
}
|
||||
.frame(width: 370)
|
||||
.task {
|
||||
self.num = await self.followModel.loadData(userId: self.userId)
|
||||
}
|
||||
}
|
||||
.frame(width: 370)
|
||||
}
|
||||
.ignoresSafeArea(edges: .bottom)
|
||||
.navigationTitle("番剧补完计划")
|
||||
.task {
|
||||
await self.followModel.loadData(userId: self.userId)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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
|
||||
@ -140,5 +152,5 @@ extension FollowListView {
|
||||
}
|
||||
|
||||
#Preview {
|
||||
FollowListView()
|
||||
FollowListView(num: 0)
|
||||
}
|
||||
|
||||
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
@ -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()
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user