
- 创建SettingPage视图,包含用户信息管理、头像设置、昵称编辑等功能。 - 实现SettingViewModel,处理设置页面的业务逻辑,包括头像上传、昵称更新等。 - 添加相机和相册选择功能,支持头像更换。 - 更新MainPage和MainViewModel,添加导航逻辑以支持设置页面的访问。 - 完善本地化支持,确保多语言兼容性。 - 新增相关测试建议,确保功能完整性和用户体验。
157 lines
4.8 KiB
Swift
157 lines
4.8 KiB
Swift
import SwiftUI
|
||
|
||
// MARK: - Main View
|
||
|
||
struct MainPage: View {
|
||
@StateObject private var viewModel = MainViewModel()
|
||
let onLogout: () -> Void
|
||
|
||
var body: some View {
|
||
NavigationStack(path: $viewModel.navigationPath) {
|
||
GeometryReader { geometry in
|
||
ZStack {
|
||
// 背景图片
|
||
LoginBackgroundView()
|
||
// 主内容
|
||
mainContentView(geometry: geometry)
|
||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||
|
||
VStack {
|
||
HStack {
|
||
Spacer()
|
||
// 右上角按钮
|
||
topRightButton
|
||
}
|
||
Spacer()
|
||
// 底部导航栏
|
||
bottomTabView
|
||
.frame(height: 80)
|
||
.padding(.horizontal, 24)
|
||
.padding(.bottom, 100)
|
||
}
|
||
}
|
||
}
|
||
.navigationDestination(for: String.self) { destination in
|
||
switch destination {
|
||
case "setting":
|
||
SettingPage(
|
||
onBack: {
|
||
viewModel.navigationPath.removeLast()
|
||
},
|
||
onLogout: {
|
||
viewModel.onLogoutTapped()
|
||
}
|
||
)
|
||
.navigationBarHidden(true)
|
||
default:
|
||
EmptyView()
|
||
}
|
||
}
|
||
}
|
||
.onAppear {
|
||
viewModel.onLogout = onLogout
|
||
viewModel.onAddButtonTapped = {
|
||
// TODO: 处理添加按钮点击事件
|
||
debugInfoSync("➕ 添加按钮被点击")
|
||
}
|
||
viewModel.onAppear()
|
||
}
|
||
.onChange(of: viewModel.isLoggedOut) { _, isLoggedOut in
|
||
if isLoggedOut {
|
||
onLogout()
|
||
}
|
||
}
|
||
}
|
||
|
||
// MARK: - UI Components
|
||
|
||
private func mainContentView(geometry: GeometryProxy) -> some View {
|
||
Group {
|
||
switch viewModel.selectedTab {
|
||
case .feed:
|
||
MomentListHomePage()
|
||
case .me:
|
||
TempMePage()
|
||
}
|
||
}
|
||
}
|
||
|
||
private var bottomTabView: some View {
|
||
HStack(spacing: 0) {
|
||
ForEach(MainViewModel.Tab.allCases, id: \.self) { tab in
|
||
Button(action: {
|
||
viewModel.onTabChanged(tab)
|
||
}) {
|
||
VStack(spacing: 4) {
|
||
Image(systemName: tab.iconName)
|
||
.font(.system(size: 24))
|
||
.foregroundColor(viewModel.selectedTab == tab ? .white : .white.opacity(0.6))
|
||
|
||
Text(tab.title)
|
||
.font(.system(size: 12))
|
||
.foregroundColor(viewModel.selectedTab == tab ? .white : .white.opacity(0.6))
|
||
}
|
||
}
|
||
.frame(maxWidth: .infinity)
|
||
.padding(.vertical, 12)
|
||
}
|
||
}
|
||
.background(
|
||
Rectangle()
|
||
.fill(Color.black.opacity(0.3))
|
||
.background(.ultraThinMaterial)
|
||
)
|
||
.safeAreaInset(edge: .bottom) {
|
||
Color.clear.frame(height: 0)
|
||
}
|
||
}
|
||
|
||
// MARK: - 右上角按钮
|
||
private var topRightButton: some View {
|
||
Button(action: {
|
||
viewModel.onTopRightButtonTapped()
|
||
}) {
|
||
Group {
|
||
switch viewModel.selectedTab {
|
||
case .feed:
|
||
Image("add icon")
|
||
.resizable()
|
||
.aspectRatio(contentMode: .fit)
|
||
.frame(width: 40, height: 40)
|
||
case .me:
|
||
Image(systemName: "gearshape")
|
||
.font(.system(size: 24, weight: .medium))
|
||
.foregroundColor(.white)
|
||
.frame(width: 40, height: 40)
|
||
.background(Color.black.opacity(0.3))
|
||
.clipShape(Circle())
|
||
}
|
||
}
|
||
}
|
||
.padding(.trailing, 16)
|
||
.padding(.top, 8)
|
||
}
|
||
}
|
||
|
||
|
||
|
||
// MARK: - MeView (简化版本)
|
||
|
||
struct TempMePage: View {
|
||
var body: some View {
|
||
VStack {
|
||
Text("Me View")
|
||
.font(.title)
|
||
.foregroundColor(.white)
|
||
|
||
Text("This is a simplified MeView")
|
||
.font(.body)
|
||
.foregroundColor(.white.opacity(0.8))
|
||
}
|
||
}
|
||
}
|
||
|
||
//#Preview {
|
||
// MainPage(onLogout: {})
|
||
//}
|