
- 在.gitignore中添加忽略项以排除不必要的文件。 - 删除架构分析需求文档以简化项目文档。 - 在APIEndpoints.swift和LoginModels.swift中移除调试信息的异步调用,提升代码简洁性。 - 在EMailLoginFeature.swift和HomeFeature.swift中新增登录流程状态管理,优化用户体验。 - 在多个视图中调整状态管理和导航逻辑,确保一致性和可维护性。 - 更新Xcode项目配置以增强调试信息的输出格式。
138 lines
5.1 KiB
Swift
138 lines
5.1 KiB
Swift
import SwiftUI
|
||
|
||
struct MeView: View {
|
||
@State private var showLogoutConfirmation = false
|
||
let onLogout: () -> Void // 新增:登出回调
|
||
|
||
var body: some View {
|
||
GeometryReader { geometry in
|
||
ScrollView {
|
||
VStack(spacing: 20) {
|
||
// 顶部标题
|
||
HStack {
|
||
Spacer()
|
||
Text("我的")
|
||
.font(.system(size: 22, weight: .semibold))
|
||
.foregroundColor(.white)
|
||
Spacer()
|
||
}
|
||
.padding(.top, geometry.safeAreaInsets.top + 20)
|
||
|
||
// 用户头像区域
|
||
VStack(spacing: 16) {
|
||
Circle()
|
||
.fill(Color.white.opacity(0.2))
|
||
.frame(width: 80, height: 80)
|
||
.overlay(
|
||
Image(systemName: "person.fill")
|
||
.font(.system(size: 40))
|
||
.foregroundColor(.white)
|
||
)
|
||
|
||
Text("用户昵称")
|
||
.font(.system(size: 18, weight: .medium))
|
||
.foregroundColor(.white)
|
||
|
||
Text("ID: 123456789")
|
||
.font(.system(size: 14))
|
||
.foregroundColor(.white.opacity(0.7))
|
||
}
|
||
.padding(.top, 30)
|
||
|
||
// 功能菜单
|
||
VStack(spacing: 12) {
|
||
MenuItemView(icon: "gearshape", title: "设置", action: {})
|
||
MenuItemView(icon: "person.circle", title: "个人信息", action: {})
|
||
MenuItemView(icon: "heart", title: "我的收藏", action: {})
|
||
MenuItemView(icon: "clock", title: "浏览历史", action: {})
|
||
MenuItemView(icon: "questionmark.circle", title: "帮助与反馈", action: {})
|
||
}
|
||
.padding(.horizontal, 20)
|
||
.padding(.top, 40)
|
||
|
||
// 退出登录按钮
|
||
Button(action: {
|
||
showLogoutConfirmation = true
|
||
}) {
|
||
HStack {
|
||
Image(systemName: "rectangle.portrait.and.arrow.right")
|
||
.font(.system(size: 16))
|
||
Text("退出登录")
|
||
.font(.system(size: 16, weight: .medium))
|
||
}
|
||
.foregroundColor(.red)
|
||
.frame(maxWidth: .infinity)
|
||
.frame(height: 50)
|
||
.background(
|
||
Color.white.opacity(0.1)
|
||
.cornerRadius(12)
|
||
)
|
||
}
|
||
.padding(.horizontal, 20)
|
||
.padding(.top, 30)
|
||
|
||
// 底部安全区域 - 为底部导航栏和安全区域留出空间
|
||
Color.clear.frame(height: geometry.safeAreaInsets.bottom + 100)
|
||
}
|
||
}
|
||
}
|
||
.ignoresSafeArea(.container, edges: .top)
|
||
.alert("确认退出", isPresented: $showLogoutConfirmation) {
|
||
Button("取消", role: .cancel) { }
|
||
Button("退出", role: .destructive) {
|
||
Task { await performLogout() }
|
||
}
|
||
} message: {
|
||
Text("确定要退出登录吗?")
|
||
}
|
||
}
|
||
|
||
// MARK: - 退出登录方法
|
||
private func performLogout() async {
|
||
debugInfoSync("🔓 开始执行退出登录...")
|
||
// 清除所有认证数据(包括 keychain 中的内容)
|
||
await UserInfoManager.clearAllAuthenticationData()
|
||
// 调用登出回调,通知父级切换视图
|
||
onLogout()
|
||
debugInfoSync("✅ 退出登录完成")
|
||
}
|
||
}
|
||
|
||
// MARK: - 菜单项组件
|
||
struct MenuItemView: View {
|
||
let icon: String
|
||
let title: String
|
||
let action: () -> Void
|
||
|
||
var body: some View {
|
||
Button(action: action) {
|
||
HStack(spacing: 16) {
|
||
Image(systemName: icon)
|
||
.font(.system(size: 20))
|
||
.foregroundColor(.white)
|
||
.frame(width: 24)
|
||
|
||
Text(title)
|
||
.font(.system(size: 16))
|
||
.foregroundColor(.white)
|
||
.frame(maxWidth: .infinity, alignment: .leading)
|
||
|
||
Image(systemName: "chevron.right")
|
||
.font(.system(size: 14))
|
||
.foregroundColor(.white.opacity(0.6))
|
||
}
|
||
.padding(.horizontal, 20)
|
||
.frame(height: 56)
|
||
.background(
|
||
Color.white.opacity(0.1)
|
||
.cornerRadius(12)
|
||
)
|
||
}
|
||
.buttonStyle(PlainButtonStyle())
|
||
}
|
||
}
|
||
|
||
#Preview {
|
||
MeView(onLogout: {})
|
||
}
|