feat: 完善MomentListHomePage功能及视图优化
- 在MomentListHomePage中实现完整的动态列表显示,支持下拉刷新和上拉加载更多功能。 - 使用LazyVStack优化列表渲染性能,确保流畅的用户体验。 - 增强MomentListHomeViewModel,添加分页相关属性和方法,优化数据加载逻辑。 - 更新API请求逻辑,支持动态加载和状态管理,提升用户交互体验。 - 添加详细的调试信息和测试建议,确保功能完整性和代码质量。
This commit is contained in:
@@ -45,21 +45,79 @@ struct MomentListHomePage: View {
|
||||
|
||||
// 动态列表内容
|
||||
if !viewModel.moments.isEmpty {
|
||||
// 显示第一个数据来测试效果
|
||||
MomentListItem(moment: viewModel.moments[0])
|
||||
.padding(.horizontal, 16)
|
||||
.padding(.bottom, 20)
|
||||
ScrollView {
|
||||
LazyVStack(spacing: 16) {
|
||||
ForEach(Array(viewModel.moments.enumerated()), id: \.element.dynamicId) { index, moment in
|
||||
MomentListItem(moment: moment)
|
||||
.padding(.horizontal, 16)
|
||||
.onAppear {
|
||||
// 当显示倒数第三个项目时,开始加载更多
|
||||
if index == viewModel.moments.count - 3 {
|
||||
viewModel.loadMoreData()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 加载更多状态指示器
|
||||
if viewModel.isLoadingMore {
|
||||
HStack {
|
||||
ProgressView()
|
||||
.progressViewStyle(CircularProgressViewStyle(tint: .white))
|
||||
.scaleEffect(0.8)
|
||||
Text("加载更多...")
|
||||
.font(.system(size: 14))
|
||||
.foregroundColor(.white.opacity(0.8))
|
||||
}
|
||||
.padding(.vertical, 20)
|
||||
}
|
||||
|
||||
// 没有更多数据提示
|
||||
if !viewModel.hasMore && !viewModel.moments.isEmpty {
|
||||
Text("没有更多数据了")
|
||||
.font(.system(size: 14))
|
||||
.foregroundColor(.white.opacity(0.6))
|
||||
.padding(.vertical, 20)
|
||||
}
|
||||
}
|
||||
.padding(.bottom, 100) // 为底部导航栏留出空间
|
||||
}
|
||||
.refreshable {
|
||||
// 下拉刷新
|
||||
viewModel.refreshData()
|
||||
}
|
||||
.onAppear {
|
||||
// 调试信息
|
||||
debugInfoSync("📱 MomentListHomePage: 显示动态列表")
|
||||
debugInfoSync(" 动态数量: \(viewModel.moments.count)")
|
||||
debugInfoSync(" 是否有更多: \(viewModel.hasMore)")
|
||||
debugInfoSync(" 是否正在加载更多: \(viewModel.isLoadingMore)")
|
||||
}
|
||||
} else if viewModel.isLoading {
|
||||
ProgressView()
|
||||
.progressViewStyle(CircularProgressViewStyle(tint: .white))
|
||||
.padding(.top, 20)
|
||||
} else if let error = viewModel.error {
|
||||
Text(error)
|
||||
.font(.system(size: 14))
|
||||
.foregroundColor(.red)
|
||||
.multilineTextAlignment(.center)
|
||||
.padding(.horizontal, 20)
|
||||
.padding(.top, 20)
|
||||
VStack(spacing: 16) {
|
||||
Text(error)
|
||||
.font(.system(size: 14))
|
||||
.foregroundColor(.red)
|
||||
.multilineTextAlignment(.center)
|
||||
.padding(.horizontal, 20)
|
||||
|
||||
// 重试按钮
|
||||
Button(action: {
|
||||
viewModel.refreshData()
|
||||
}) {
|
||||
Text("重试")
|
||||
.font(.system(size: 14, weight: .medium))
|
||||
.foregroundColor(.white)
|
||||
.padding(.horizontal, 20)
|
||||
.padding(.vertical, 8)
|
||||
.background(Color.white.opacity(0.2))
|
||||
.cornerRadius(8)
|
||||
}
|
||||
}
|
||||
.padding(.top, 20)
|
||||
}
|
||||
|
||||
Spacer()
|
||||
|
Reference in New Issue
Block a user