import SwiftUI // MARK: - Main View struct MainPage: View { @StateObject private var viewModel = MainViewModel() let onLogout: () -> Void @State private var isPresentingCreatePage: Bool = false var body: some View { NavigationStack(path: $viewModel.navigationPath) { GeometryReader { geometry in ZStack { // 背景图片 LoginBackgroundView() // 主内容:使用 TabView 常驻子树 TabView(selection: $viewModel.selectedTab) { MomentListHomePage(onCreateTapped: { isPresentingCreatePage = true }) .tag(MainViewModel.Tab.feed) MePage(onLogout: onLogout) .tag(MainViewModel.Tab.me) } .tabViewStyle(.page(indexDisplayMode: .never)) .frame(maxWidth: .infinity, maxHeight: .infinity) VStack { Spacer() // 底部导航栏(组件化) BottomTabBar(viewModel: viewModel) .frame(height: 80) .padding(.horizontal, 24) .padding(.bottom) } }.ignoresSafeArea(.all) } .toolbar(.hidden) } .onAppear { viewModel.onLogout = onLogout viewModel.onAddButtonTapped = { // TODO: 处理添加按钮点击事件 debugInfoSync("➕ 添加按钮被点击") } viewModel.onAppear() } .fullScreenCover(isPresented: $isPresentingCreatePage) { CreateFeedPage { isPresentingCreatePage = false } } .onChange(of: viewModel.isLoggedOut) { _, isLoggedOut in if isLoggedOut { onLogout() } } } }