Files
e-party-iOS/yana/MVVM/MainPage.swift
edwinQQQ de4428e8a1 feat: 新增设置页面及相关功能实现
- 创建SettingPage视图,包含用户信息管理、头像设置、昵称编辑等功能。
- 实现SettingViewModel,处理设置页面的业务逻辑,包括头像上传、昵称更新等。
- 添加相机和相册选择功能,支持头像更换。
- 更新MainPage和MainViewModel,添加导航逻辑以支持设置页面的访问。
- 完善本地化支持,确保多语言兼容性。
- 新增相关测试建议,确保功能完整性和用户体验。
2025-08-06 18:51:37 +08:00

157 lines
4.8 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: - 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: {})
//}