feat: 增强邮箱登录功能和密码恢复流程
- 更新邮箱登录相关功能,新增邮箱验证码获取和登录API端点。 - 添加AccountModel以管理用户认证信息,支持会话票据的存储和更新。 - 实现密码恢复功能,支持通过邮箱获取验证码和重置密码。 - 增加本地化支持,更新相关字符串以适应新功能。 - 引入ValidationHelper以验证邮箱和密码格式,确保用户输入的有效性。 - 更新视图以支持邮箱登录和密码恢复的用户交互。
This commit is contained in:
124
yana/Views/HomeView.swift
Normal file
124
yana/Views/HomeView.swift
Normal file
@@ -0,0 +1,124 @@
|
||||
import SwiftUI
|
||||
import ComposableArchitecture
|
||||
|
||||
struct HomeView: View {
|
||||
let store: StoreOf<HomeFeature>
|
||||
@ObservedObject private var localizationManager = LocalizationManager.shared
|
||||
|
||||
var body: some View {
|
||||
WithPerceptionTracking {
|
||||
GeometryReader { geometry in
|
||||
ZStack {
|
||||
// 背景图片 - 使用"bg"图片,全屏显示
|
||||
Image("bg")
|
||||
.resizable()
|
||||
.aspectRatio(contentMode: .fill)
|
||||
.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) {
|
||||
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)
|
||||
}
|
||||
.padding(.bottom, 50)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.onAppear {
|
||||
store.send(.onAppear)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#Preview {
|
||||
HomeView(
|
||||
store: Store(
|
||||
initialState: HomeFeature.State()
|
||||
) {
|
||||
HomeFeature()
|
||||
}
|
||||
)
|
||||
}
|
Reference in New Issue
Block a user