feat: 更新.gitignore,删除需求文档,优化API调试信息
- 在.gitignore中添加忽略项以排除不必要的文件。 - 删除架构分析需求文档以简化项目文档。 - 在APIEndpoints.swift和LoginModels.swift中移除调试信息的异步调用,提升代码简洁性。 - 在EMailLoginFeature.swift和HomeFeature.swift中新增登录流程状态管理,优化用户体验。 - 在多个视图中调整状态管理和导航逻辑,确保一致性和可维护性。 - 更新Xcode项目配置以增强调试信息的输出格式。
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import SwiftUI
|
||||
import ComposableArchitecture
|
||||
import Combine
|
||||
|
||||
struct EMailLoginView: View {
|
||||
let store: StoreOf<EMailLoginFeature>
|
||||
@@ -9,7 +10,7 @@ struct EMailLoginView: View {
|
||||
@State private var email: String = ""
|
||||
@State private var verificationCode: String = ""
|
||||
@State private var codeCountdown: Int = 0
|
||||
@State private var timer: Timer?
|
||||
@State private var timerCancellable: AnyCancellable?
|
||||
|
||||
// 管理输入框焦点状态
|
||||
@FocusState private var focusedField: Field?
|
||||
@@ -41,8 +42,10 @@ struct EMailLoginView: View {
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
GeometryReader { geometry in
|
||||
ZStack {
|
||||
// WithViewStore(store, observe: { $0 }) { _ in
|
||||
GeometryReader { geometry in
|
||||
WithPerceptionTracking {
|
||||
ZStack {
|
||||
// 背景图片
|
||||
Image("bg")
|
||||
.resizable()
|
||||
@@ -200,36 +203,48 @@ struct EMailLoginView: View {
|
||||
|
||||
Spacer()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// }
|
||||
.onAppear {
|
||||
// 每次进入页面都重置状态
|
||||
store.send(.resetState)
|
||||
|
||||
email = ""
|
||||
verificationCode = ""
|
||||
codeCountdown = 0
|
||||
stopCountdown()
|
||||
|
||||
#if DEBUG
|
||||
email = "exzero@126.com"
|
||||
store.send(.emailChanged(email))
|
||||
#endif
|
||||
let _ = WithPerceptionTracking {
|
||||
// 每次进入页面都重置状态
|
||||
store.send(.resetState)
|
||||
|
||||
email = ""
|
||||
verificationCode = ""
|
||||
codeCountdown = 0
|
||||
stopCountdown()
|
||||
|
||||
#if DEBUG
|
||||
email = "exzero@126.com"
|
||||
store.send(.emailChanged(email))
|
||||
#endif
|
||||
}
|
||||
}
|
||||
.onDisappear {
|
||||
stopCountdown()
|
||||
let _ = WithPerceptionTracking {
|
||||
stopCountdown()
|
||||
}
|
||||
}
|
||||
.onChange(of: email) { newEmail in
|
||||
store.send(.emailChanged(newEmail))
|
||||
let _ = WithPerceptionTracking {
|
||||
store.send(.emailChanged(newEmail))
|
||||
}
|
||||
}
|
||||
.onChange(of: verificationCode) { newCode in
|
||||
store.send(.verificationCodeChanged(newCode))
|
||||
let _ = WithPerceptionTracking {
|
||||
store.send(.verificationCodeChanged(newCode))
|
||||
}
|
||||
}
|
||||
.onChange(of: store.isCodeLoading) { isCodeLoading in
|
||||
// 当API请求完成且成功时,自动将焦点切换到验证码输入框
|
||||
if !isCodeLoading && store.errorMessage == nil {
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
|
||||
focusedField = .verificationCode
|
||||
let _ = WithPerceptionTracking {
|
||||
// 当API请求完成且成功时,自动将焦点切换到验证码输入框
|
||||
if !isCodeLoading && store.errorMessage == nil {
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
|
||||
focusedField = .verificationCode
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -242,30 +257,31 @@ struct EMailLoginView: View {
|
||||
// 立即设置倒计时
|
||||
codeCountdown = 60
|
||||
|
||||
timer = Timer.scheduledTimer(withTimeInterval: 1.0, repeats: true) { _ in
|
||||
DispatchQueue.main.async {
|
||||
// 使用 SwiftUI 原生的 Timer.publish 方式
|
||||
timerCancellable = Timer.publish(every: 1.0, on: .main, in: .common)
|
||||
.autoconnect()
|
||||
.sink { _ in
|
||||
if codeCountdown > 0 {
|
||||
codeCountdown -= 1
|
||||
} else {
|
||||
stopCountdown()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func stopCountdown() {
|
||||
timer?.invalidate()
|
||||
timer = nil
|
||||
timerCancellable?.cancel()
|
||||
timerCancellable = nil
|
||||
}
|
||||
}
|
||||
|
||||
#Preview {
|
||||
EMailLoginView(
|
||||
store: Store(
|
||||
initialState: EMailLoginFeature.State()
|
||||
) {
|
||||
EMailLoginFeature()
|
||||
},
|
||||
onBack: {}
|
||||
)
|
||||
}
|
||||
//#Preview {
|
||||
// EMailLoginView(
|
||||
// store: Store(
|
||||
// initialState: EMailLoginFeature.State()
|
||||
// ) {
|
||||
// EMailLoginFeature()
|
||||
// },
|
||||
// onBack: {}
|
||||
// )
|
||||
//}
|
||||
|
Reference in New Issue
Block a user