This commit is contained in:
anlicheng 2026-03-20 11:52:11 +08:00
parent a284e3faa0
commit 0f98a356b7
2 changed files with 23 additions and 6 deletions

View File

@ -250,7 +250,7 @@ struct RegisterSubmitVerifyCodeView: View {
self.isProcessing = true self.isProcessing = true
Task { @MainActor in Task { @MainActor in
do { do {
let result = try await self.registerModel.submitVerifyCode(sessionId: sessionId, verifyCode: Int(self.code) ?? 0) _ = try await self.registerModel.submitVerifyCode(sessionId: sessionId, verifyCode: Int(self.code) ?? 0)
withAnimation(.spring(duration: 0.6, bounce: 0.2)) { withAnimation(.spring(duration: 0.6, bounce: 0.2)) {
self.registerModel.stage = .setPassword(sessionId: sessionId) self.registerModel.stage = .setPassword(sessionId: sessionId)
self.registerModel.transitionEdge = .trailing self.registerModel.transitionEdge = .trailing
@ -273,8 +273,9 @@ struct RegisterSetPasswordView: View {
@State private var isProcessing = false @State private var isProcessing = false
// //
@State private var errorMessage: String? @State private var showAlert: Bool = false
@State private var errorMessage: String = ""
// //
var passwordError: String? { var passwordError: String? {
if password.isEmpty || confirm.isEmpty { if password.isEmpty || confirm.isEmpty {
@ -326,15 +327,21 @@ struct RegisterSetPasswordView: View {
Spacer() Spacer()
} }
.padding(40) .padding(40)
.alert(isPresented: $showAlert) {
Alert(title: Text("提示"), message: Text(self.errorMessage))
}
} }
private func handleRegister() { private func handleRegister() {
self.isProcessing = true self.isProcessing = true
Task { @MainActor in Task { @MainActor in
do { do {
let result = try await self.registerModel.register(sessionId: sessionId, password: self.password) _ = try await self.registerModel.register(sessionId: sessionId, password: self.password)
self.showAlert = true
self.errorMessage = "注册成功"
} catch { } catch {
self.errorMessage = error.localizedDescription self.showAlert = true
self.errorMessage = "注册失败,重稍后重试"
} }
self.isProcessing = false self.isProcessing = false
} }

View File

@ -207,6 +207,10 @@ struct ResetPasswordView: View {
@State private var confirm = "" @State private var confirm = ""
@State private var isProcessing = false @State private var isProcessing = false
//
@State private var showAlert = false
@State private var errorMessage = ""
// //
var isInputValid: Bool { var isInputValid: Bool {
!password.isEmpty && password == confirm && password.count >= 8 !password.isEmpty && password == confirm && password.count >= 8
@ -261,6 +265,9 @@ struct ResetPasswordView: View {
Spacer() Spacer()
} }
.padding(40) .padding(40)
.alert(isPresented: $showAlert) {
Alert(title: Text("提示"), message: Text(self.errorMessage))
}
} }
private func handleReset() { private func handleReset() {
@ -270,8 +277,11 @@ struct ResetPasswordView: View {
let result = try await resetPasswordModel.resetPassword(sessionId: sessionId, newPassword: password) let result = try await resetPasswordModel.resetPassword(sessionId: sessionId, newPassword: password)
print("密码重置成功: \(result)") print("密码重置成功: \(result)")
// //
self.showAlert = true
self.errorMessage = "重置成功,重新登陆"
} catch { } catch {
print("重置失败: \(error)") self.showAlert = true
self.errorMessage = "重置失败, 请稍后重试"
} }
self.isProcessing = false self.isProcessing = false
} }