
- 更新邮箱登录相关功能,新增邮箱验证码获取和登录API端点。 - 添加AccountModel以管理用户认证信息,支持会话票据的存储和更新。 - 实现密码恢复功能,支持通过邮箱获取验证码和重置密码。 - 增加本地化支持,更新相关字符串以适应新功能。 - 引入ValidationHelper以验证邮箱和密码格式,确保用户输入的有效性。 - 更新视图以支持邮箱登录和密码恢复的用户交互。
180 lines
7.7 KiB
Swift
180 lines
7.7 KiB
Swift
import SwiftUI
|
||
import ComposableArchitecture
|
||
|
||
// PreferenceKey 用于传递图片高度
|
||
struct ImageHeightPreferenceKey: PreferenceKey {
|
||
static var defaultValue: CGFloat = 0
|
||
static func reduce(value: inout CGFloat, nextValue: () -> CGFloat) {
|
||
value = max(value, nextValue())
|
||
}
|
||
}
|
||
|
||
struct LoginView: View {
|
||
let store: StoreOf<LoginFeature>
|
||
@State private var topImageHeight: CGFloat = 120 // 默认值
|
||
@ObservedObject private var localizationManager = LocalizationManager.shared
|
||
@State private var showLanguageSettings = false
|
||
@State private var isAgreedToTerms = true
|
||
@State private var showUserAgreement = false
|
||
@State private var showPrivacyPolicy = false
|
||
@State private var showIDLogin = false // 使用SwiftUI的@State管理导航
|
||
@State private var showEmailLogin = false // 新增:邮箱登录导航状态
|
||
|
||
var body: some View {
|
||
NavigationView {
|
||
GeometryReader { geometry in
|
||
ZStack {
|
||
// 使用与 splash 相同的背景图片
|
||
Image("bg")
|
||
.resizable()
|
||
.aspectRatio(contentMode: .fill)
|
||
.ignoresSafeArea(.all)
|
||
VStack(spacing: 0) {
|
||
// 上半部分的"top"图片
|
||
ZStack {
|
||
Image("top")
|
||
.resizable()
|
||
.aspectRatio(contentMode: .fit)
|
||
.frame(maxWidth: .infinity)
|
||
.padding(.top, -100)
|
||
.background(
|
||
GeometryReader { topImageGeometry in
|
||
Color.clear.preference(key: ImageHeightPreferenceKey.self, value: topImageGeometry.size.height)
|
||
}
|
||
)
|
||
// E-PARTI 文本,底部对齐"top"图片底部,间距20
|
||
HStack {
|
||
Text("login.app_title".localized)
|
||
.font(FontManager.adaptedFont(.bayonRegular, designSize: 56, for: geometry.size.width))
|
||
.foregroundColor(.white)
|
||
.padding(.leading, 20)
|
||
Spacer()
|
||
}
|
||
.padding(.top, max(0, topImageHeight - 100)) // top图片高度 - 140
|
||
|
||
// 语言切换按钮(右上角)- 仅在 Debug 环境下显示
|
||
#if DEBUG
|
||
VStack {
|
||
HStack {
|
||
Spacer()
|
||
Button(action: {
|
||
showLanguageSettings = true
|
||
}) {
|
||
Image(systemName: "globe")
|
||
.frame(width: 40, height: 40)
|
||
.font(.system(size: 20))
|
||
.foregroundColor(.white)
|
||
.background(Color.black.opacity(0.3))
|
||
.clipShape(Circle())
|
||
}
|
||
.padding(.trailing, 16)
|
||
}
|
||
Spacer()
|
||
}
|
||
#endif
|
||
|
||
VStack(spacing: 24) {
|
||
// ID Login 按钮
|
||
LoginButton(
|
||
iconName: "person.circle.fill",
|
||
iconColor: .green,
|
||
title: "login.id_login".localized
|
||
) {
|
||
showIDLogin = true // 直接设置SwiftUI状态
|
||
}
|
||
// Email Login 按钮
|
||
LoginButton(
|
||
iconName: "envelope.fill",
|
||
iconColor: .blue,
|
||
title: "login.email_login".localized
|
||
) {
|
||
showEmailLogin = true // 显示邮箱登录界面
|
||
}
|
||
}.padding(.top, max(0, topImageHeight+140))
|
||
}
|
||
.onPreferenceChange(ImageHeightPreferenceKey.self) { imageHeight in
|
||
topImageHeight = imageHeight
|
||
}
|
||
|
||
// 间距,使登录按钮区域顶部距离"top"图片底部40pt
|
||
Spacer()
|
||
.frame(height: 120)
|
||
|
||
// 用户协议组件
|
||
UserAgreementView(
|
||
isAgreed: $isAgreedToTerms,
|
||
onUserServiceTapped: {
|
||
showUserAgreement = true
|
||
},
|
||
onPrivacyPolicyTapped: {
|
||
showPrivacyPolicy = true
|
||
}
|
||
)
|
||
.padding(.horizontal, 28)
|
||
.padding(.bottom, 140)
|
||
}
|
||
|
||
// 隐藏的NavigationLink - 使用纯SwiftUI方式
|
||
NavigationLink(
|
||
destination: IDLoginView(
|
||
store: store.scope(
|
||
state: \.idLoginState,
|
||
action: \.idLogin
|
||
),
|
||
onBack: {
|
||
showIDLogin = false // 直接设置SwiftUI状态
|
||
}
|
||
)
|
||
.navigationBarHidden(true),
|
||
isActive: $showIDLogin // 使用SwiftUI的绑定
|
||
) {
|
||
EmptyView()
|
||
}
|
||
.hidden()
|
||
|
||
// 新增:邮箱登录的NavigationLink
|
||
NavigationLink(
|
||
destination: EMailLoginView(
|
||
store: store.scope(
|
||
state: \.emailLoginState,
|
||
action: \.emailLogin
|
||
),
|
||
onBack: {
|
||
showEmailLogin = false // 直接设置SwiftUI状态
|
||
}
|
||
)
|
||
.navigationBarHidden(true),
|
||
isActive: $showEmailLogin // 使用SwiftUI的绑定
|
||
) {
|
||
EmptyView()
|
||
}
|
||
.hidden()
|
||
}
|
||
}
|
||
.navigationBarHidden(true)
|
||
}
|
||
.navigationViewStyle(StackNavigationViewStyle())
|
||
.sheet(isPresented: $showLanguageSettings) {
|
||
LanguageSettingsView(isPresented: $showLanguageSettings)
|
||
}
|
||
.webView(
|
||
isPresented: $showUserAgreement,
|
||
url: APIConfiguration.webURL(for: .userAgreement)
|
||
)
|
||
.webView(
|
||
isPresented: $showPrivacyPolicy,
|
||
url: APIConfiguration.webURL(for: .privacyPolicy)
|
||
)
|
||
}
|
||
}
|
||
|
||
#Preview {
|
||
LoginView(
|
||
store: Store(
|
||
initialState: LoginFeature.State()
|
||
) {
|
||
LoginFeature()
|
||
}
|
||
)
|
||
}
|