feat: 添加设置功能和动态视图
- 新增设置功能模块,包含用户信息管理和设置选项。 - 实现动态视图,展示用户动态内容。 - 更新HomeView以支持设置页面的展示和动态视图的切换。 - 添加底部导航栏,增强用户体验。 - 更新相关视图和组件,确保一致的UI风格和交互体验。
This commit is contained in:
@@ -4,111 +4,70 @@ import ComposableArchitecture
|
||||
struct HomeView: View {
|
||||
let store: StoreOf<HomeFeature>
|
||||
@ObservedObject private var localizationManager = LocalizationManager.shared
|
||||
@State private var selectedTab: Tab = .feed
|
||||
|
||||
var body: some View {
|
||||
WithPerceptionTracking {
|
||||
GeometryReader { geometry in
|
||||
ZStack {
|
||||
// 背景图片 - 使用"bg"图片,全屏显示
|
||||
// 使用 "bg" 图片作为背景
|
||||
Image("bg")
|
||||
.resizable()
|
||||
.aspectRatio(contentMode: .fill)
|
||||
.frame(width: geometry.size.width, height: geometry.size.height)
|
||||
.clipped()
|
||||
.ignoresSafeArea(.all)
|
||||
|
||||
VStack(spacing: 0) {
|
||||
// Navigation Bar 标题区域
|
||||
Text("home.title".localized)
|
||||
.font(.custom("PingFang SC-Semibold", size: 16))
|
||||
.foregroundColor(.white)
|
||||
.frame(
|
||||
width: 158,
|
||||
height: 22,
|
||||
alignment: .center
|
||||
) // 参考代码中的尺寸
|
||||
.padding(.top, 8)
|
||||
.padding(.horizontal)
|
||||
|
||||
// 中间内容区域
|
||||
VStack(spacing: 32) {
|
||||
// 顶部导航区域
|
||||
HStack {
|
||||
Spacer()
|
||||
|
||||
// 用户信息区域
|
||||
VStack(spacing: 16) {
|
||||
// 优先显示 UserInfo 中的用户名,否则显示通用欢迎信息
|
||||
if let userInfo = store.userInfo, let userName = userInfo.username {
|
||||
Text("欢迎, \(userName)")
|
||||
.font(.title2)
|
||||
.foregroundColor(.white)
|
||||
} else {
|
||||
Text("欢迎")
|
||||
.font(.title2)
|
||||
.foregroundColor(.white)
|
||||
}
|
||||
|
||||
// 显示用户ID信息:优先 UserInfo,其次 AccountModel
|
||||
if let userInfo = store.userInfo, let userId = userInfo.userId {
|
||||
Text("ID: \(userId)")
|
||||
.font(.caption)
|
||||
.foregroundColor(.white.opacity(0.8))
|
||||
} else if let accountModel = store.accountModel, let uid = accountModel.uid {
|
||||
Text("UID: \(uid)")
|
||||
.font(.caption)
|
||||
.foregroundColor(.white.opacity(0.8))
|
||||
}
|
||||
|
||||
// 显示账户状态(如果有 AccountModel)
|
||||
if let accountModel = store.accountModel {
|
||||
VStack(spacing: 4) {
|
||||
if accountModel.hasValidSession {
|
||||
HStack {
|
||||
Image(systemName: "checkmark.circle.fill")
|
||||
.foregroundColor(.green)
|
||||
Text("已登录")
|
||||
.foregroundColor(.white.opacity(0.9))
|
||||
}
|
||||
.font(.caption)
|
||||
} else if accountModel.hasValidAuthentication {
|
||||
HStack {
|
||||
Image(systemName: "clock.circle.fill")
|
||||
.foregroundColor(.orange)
|
||||
Text("认证中")
|
||||
.foregroundColor(.white.opacity(0.9))
|
||||
}
|
||||
.font(.caption)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.padding()
|
||||
.background(Color.black.opacity(0.3))
|
||||
.cornerRadius(12)
|
||||
.padding(.horizontal, 32)
|
||||
|
||||
Spacer()
|
||||
|
||||
// 登出按钮
|
||||
// 右上角加号按钮
|
||||
Button(action: {
|
||||
store.send(.logoutTapped)
|
||||
// 加号按钮操作
|
||||
}) {
|
||||
HStack {
|
||||
Image(systemName: "arrow.right.square")
|
||||
Text("退出登录")
|
||||
}
|
||||
.font(.body)
|
||||
.foregroundColor(.white)
|
||||
.padding(.horizontal, 24)
|
||||
.padding(.vertical, 12)
|
||||
.background(Color.red.opacity(0.7))
|
||||
.cornerRadius(8)
|
||||
Image(systemName: "plus")
|
||||
.font(.system(size: 20, weight: .medium))
|
||||
.foregroundColor(.red)
|
||||
.frame(width: 36, height: 36)
|
||||
.background(
|
||||
Color.white.opacity(0.2)
|
||||
.cornerRadius(18)
|
||||
)
|
||||
}
|
||||
.padding(.bottom, 50)
|
||||
}
|
||||
.padding(.horizontal, 20)
|
||||
.padding(.top, 10)
|
||||
|
||||
// 主要内容区域
|
||||
ZStack {
|
||||
// 根据选中的 tab 显示不同的视图
|
||||
switch selectedTab {
|
||||
case .feed:
|
||||
FeedView()
|
||||
.transition(.opacity)
|
||||
case .me:
|
||||
MeView()
|
||||
.transition(.opacity)
|
||||
}
|
||||
}
|
||||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||
|
||||
// 底部导航栏
|
||||
BottomTabView(selectedTab: $selectedTab)
|
||||
}
|
||||
}
|
||||
}
|
||||
.onAppear {
|
||||
store.send(.onAppear)
|
||||
}
|
||||
.sheet(isPresented: Binding(
|
||||
get: { store.isSettingPresented },
|
||||
set: { _ in store.send(.settingDismissed) }
|
||||
)) {
|
||||
SettingView(store: store.scope(state: \.settingState, action: \.setting))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user