Files
e-party-iOS/yana/MVVM/View/MomentListHomePage.swift
edwinQQQ 6b960f53b4 feat: 更新Splash视图及登录模型逻辑
- 将SplashV2替换为SplashPage,优化应用启动流程。
- 在LoginModels中将用户ID参数更改为加密后的ID,增强安全性。
- 更新AppConfig中的API基础URL,确保与生产环境一致。
- 在CommonComponents中添加底部Tab栏图标映射逻辑,提升用户体验。
- 新增NineGridImagePicker组件,支持多图选择功能,优化CreateFeedPage的图片选择逻辑。
- 移除冗余的BottomTabView组件,简化视图结构,提升代码整洁性。
- 在MainPage中整合创建动态页面的逻辑,优化导航体验。
- 新增MePage视图,提供用户信息管理功能,增强应用的可用性。
2025-09-26 10:53:00 +08:00

184 lines
8.3 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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: 图片预览已关闭")
}
}
//
}
}