
- 将SplashV2替换为SplashPage,优化应用启动流程。 - 在LoginModels中将用户ID参数更改为加密后的ID,增强安全性。 - 更新AppConfig中的API基础URL,确保与生产环境一致。 - 在CommonComponents中添加底部Tab栏图标映射逻辑,提升用户体验。 - 新增NineGridImagePicker组件,支持多图选择功能,优化CreateFeedPage的图片选择逻辑。 - 移除冗余的BottomTabView组件,简化视图结构,提升代码整洁性。 - 在MainPage中整合创建动态页面的逻辑,优化导航体验。 - 新增MePage视图,提供用户信息管理功能,增强应用的可用性。
184 lines
8.3 KiB
Swift
184 lines
8.3 KiB
Swift
import SwiftUI
|
||
|
||
// MARK: - BackgroundView
|
||
struct MomentListBackgroundView: View {
|
||
var body: some View {
|
||
Image("bg")
|
||
.resizable()
|
||
.aspectRatio(contentMode: .fill)
|
||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||
.clipped()
|
||
.ignoresSafeArea(.all)
|
||
}
|
||
}
|
||
|
||
// MARK: - MomentListHomePage
|
||
struct MomentListHomePage: View {
|
||
@StateObject private var viewModel = MomentListHomeViewModel()
|
||
let onCreateTapped: () -> Void
|
||
|
||
// MARK: - 图片预览状态
|
||
@State private var previewItem: PreviewItem? = nil
|
||
@State private var previewCurrentIndex: Int = 0
|
||
|
||
// MARK: - 创建动态发布页弹窗
|
||
// 迁移到上层(MainPage)统一管理,避免与 TabView 全屏弹窗冲突
|
||
|
||
var body: some View {
|
||
ZStack {
|
||
// 背景
|
||
MomentListBackgroundView()
|
||
|
||
VStack(alignment: .center, spacing: 0) {
|
||
// 顶部标题居中 + 右上角添加按钮(垂直居中对齐)
|
||
ZStack {
|
||
// 居中标题
|
||
Text(LocalizedString("feedList.title", comment: "Enjoy your Life Time"))
|
||
.font(.system(size: 22, weight: .semibold))
|
||
.foregroundColor(.white)
|
||
.frame(maxWidth: .infinity, alignment: .center)
|
||
|
||
// 右上角 “+” 按钮
|
||
HStack {
|
||
Spacer()
|
||
Button {
|
||
debugInfoSync("➕ MomentListHomePage: 点击添加按钮")
|
||
onCreateTapped()
|
||
} label: {
|
||
Image("add icon")
|
||
.resizable()
|
||
.aspectRatio(contentMode: .fit)
|
||
.frame(width: 40, height: 40)
|
||
}
|
||
.padding(.trailing, 16)
|
||
}
|
||
}
|
||
.frame(height: 56)
|
||
|
||
// 动态列表内容(Volume 与标语随列表滚动)
|
||
if !viewModel.moments.isEmpty {
|
||
ScrollView {
|
||
VStack(spacing: 0) {
|
||
// Volume 图标 + 标语(随列表滚动)
|
||
Image("Volume")
|
||
.frame(width: 56, height: 41)
|
||
.padding(.top, 16)
|
||
Text(LocalizedString("feedList.slogan",
|
||
comment: ""))
|
||
.font(.system(size: 16))
|
||
.multilineTextAlignment(.leading)
|
||
.foregroundColor(.white.opacity(0.9))
|
||
.padding(.horizontal, 30)
|
||
.padding(.bottom, 30)
|
||
|
||
LazyVStack(spacing: 16) {
|
||
ForEach(Array(viewModel.moments.enumerated()), id: \.element.dynamicId) { index, moment in
|
||
MomentListItem(
|
||
moment: moment,
|
||
onImageTap: { images, tappedIndex in
|
||
// 处理图片点击事件
|
||
previewCurrentIndex = tappedIndex
|
||
previewItem = PreviewItem(images: images, index: tappedIndex)
|
||
debugInfoSync("📸 MomentListHomePage: 图片被点击")
|
||
debugInfoSync(" 动态索引: \(index)")
|
||
debugInfoSync(" 图片索引: \(tappedIndex)")
|
||
debugInfoSync(" 图片数量: \(images.count)")
|
||
}
|
||
)
|
||
.padding(.leading, 16)
|
||
.padding(.trailing, 32)
|
||
.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, 160) // 为底部导航栏留出空间
|
||
}
|
||
}
|
||
.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 {
|
||
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()
|
||
}
|
||
.safeAreaPadding(.top, 8)
|
||
}
|
||
.onAppear {
|
||
viewModel.onAppear()
|
||
}
|
||
.onReceive(NotificationCenter.default.publisher(for: .init("CreateFeedPublished"))) { _ in
|
||
viewModel.refreshData()
|
||
}
|
||
// MARK: - 图片预览弹窗(使用 sheet 以避免与发布页全屏弹窗冲突)
|
||
.sheet(item: $previewItem) { item in
|
||
ImagePreviewPager(
|
||
images: item.images as [String],
|
||
currentIndex: $previewCurrentIndex
|
||
) {
|
||
previewItem = nil
|
||
debugInfoSync("📸 MomentListHomePage: 图片预览已关闭")
|
||
}
|
||
}
|
||
// 发布页由上层统一控制
|
||
}
|
||
}
|