fix register view
This commit is contained in:
parent
85756fb6ee
commit
00a722f407
@ -7,6 +7,7 @@
|
||||
|
||||
import Foundation
|
||||
import Observation
|
||||
import SwiftUI
|
||||
|
||||
@Observable
|
||||
class RegisterModel {
|
||||
@ -18,6 +19,7 @@ class RegisterModel {
|
||||
}
|
||||
|
||||
var stage: Stage = .requestVerifyCode(username: nil)
|
||||
var transitionEdge: Edge = .trailing // 默认从右进入
|
||||
|
||||
private let baseParams: [String: Any] = [
|
||||
"client_id": SystemConfig.getClientId(),
|
||||
|
||||
@ -27,8 +27,10 @@ struct RegisterRootView: View {
|
||||
RegisterSetPasswordView(username: username)
|
||||
}
|
||||
}
|
||||
.transition(.asymmetric(insertion: .move(edge: .trailing).combined(with: .opacity),
|
||||
removal: .move(edge: .leading).combined(with: .opacity)))
|
||||
.transition(.asymmetric(
|
||||
insertion: .move(edge: registerModel.transitionEdge).combined(with: .opacity),
|
||||
removal: .move(edge: registerModel.transitionEdge == .trailing ? .leading : .trailing).combined(with: .opacity)
|
||||
))
|
||||
}
|
||||
.environment(registerModel)
|
||||
.frame(width: 400, height: 450)
|
||||
@ -90,14 +92,9 @@ struct RegisterRequestVerifyCodeView: View {
|
||||
Button(action: {
|
||||
self.requestVerifyCode()
|
||||
}) {
|
||||
if isProcessing {
|
||||
ProgressView()
|
||||
.controlSize(.small)
|
||||
} else {
|
||||
Text("获取验证码")
|
||||
.fontWeight(.medium)
|
||||
.frame(maxWidth: .infinity)
|
||||
}
|
||||
Text("获取验证码")
|
||||
.fontWeight(.medium)
|
||||
.frame(maxWidth: .infinity)
|
||||
}
|
||||
.buttonStyle(.borderedProminent)
|
||||
.controlSize(.large)
|
||||
@ -125,10 +122,10 @@ struct RegisterRequestVerifyCodeView: View {
|
||||
switch SDLUtil.identifyContact(username) {
|
||||
case .email, .phone:
|
||||
do {
|
||||
let result = try await self.registerModel.requestVerifyCode(username: username)
|
||||
print("send verify code result: \(result)")
|
||||
withAnimation(.spring()) {
|
||||
_ = try await self.registerModel.requestVerifyCode(username: username)
|
||||
withAnimation(.spring(duration: 0.6, bounce: 0.2)) {
|
||||
self.registerModel.stage = .submitVerifyCode(username: username)
|
||||
self.registerModel.transitionEdge = .trailing
|
||||
}
|
||||
} catch {
|
||||
self.showAlert = true
|
||||
@ -159,6 +156,11 @@ struct RegisterSubmitVerifyCodeView: View {
|
||||
@State private var isEnabled: Bool = false
|
||||
@State private var remainingSeconds = 60
|
||||
@State private var timer: Timer? = nil
|
||||
|
||||
// 判断验证码是否正确
|
||||
var validInputCode: Bool {
|
||||
return !self.code.isEmpty && self.code.count == 4 && self.code.allSatisfy {$0.isNumber}
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
VStack(spacing: 24) {
|
||||
@ -186,21 +188,18 @@ struct RegisterSubmitVerifyCodeView: View {
|
||||
Button(action: {
|
||||
self.submitVerifyCode()
|
||||
}) {
|
||||
if isProcessing {
|
||||
ProgressView()
|
||||
.controlSize(.small)
|
||||
} else {
|
||||
Text("验证并设置密码")
|
||||
.fontWeight(.medium)
|
||||
.frame(maxWidth: .infinity)
|
||||
}
|
||||
Text("验证并设置密码")
|
||||
.fontWeight(.medium)
|
||||
.frame(maxWidth: .infinity)
|
||||
}
|
||||
.buttonStyle(.borderedProminent)
|
||||
.controlSize(.large)
|
||||
.disabled(!self.validInputCode)
|
||||
|
||||
Button("返回上一步") {
|
||||
withAnimation {
|
||||
registerModel.stage = .requestVerifyCode(username: self.username)
|
||||
withAnimation(.spring(duration: 0.6, bounce: 0.2)) {
|
||||
self.registerModel.stage = .requestVerifyCode(username: self.username)
|
||||
self.registerModel.transitionEdge = .leading
|
||||
}
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
@ -248,25 +247,11 @@ struct RegisterSubmitVerifyCodeView: View {
|
||||
private func submitVerifyCode() {
|
||||
self.isProcessing = true
|
||||
Task { @MainActor in
|
||||
if self.code.isEmpty {
|
||||
self.showAlert = true
|
||||
self.errorMessage = "请输入验证码"
|
||||
self.isProcessing = false
|
||||
return
|
||||
}
|
||||
|
||||
if self.code.count != 4 {
|
||||
self.showAlert = true
|
||||
self.errorMessage = "验证码错误"
|
||||
self.isProcessing = false
|
||||
return
|
||||
}
|
||||
|
||||
do {
|
||||
let result = try await self.registerModel.submitVerifyCode(username: username, verifyCode: self.code)
|
||||
print("submit verify code result: \(result)")
|
||||
withAnimation(.spring()) {
|
||||
registerModel.stage = .setPassword(username: username)
|
||||
_ = try await self.registerModel.submitVerifyCode(username: username, verifyCode: self.code)
|
||||
withAnimation(.spring(duration: 0.6, bounce: 0.2)) {
|
||||
self.registerModel.stage = .setPassword(username: username)
|
||||
self.registerModel.transitionEdge = .trailing
|
||||
}
|
||||
} catch {
|
||||
self.showAlert = true
|
||||
|
||||
@ -43,7 +43,7 @@ struct punchnetApp: App {
|
||||
var body: some Scene {
|
||||
WindowGroup(id: "mainWindow") {
|
||||
// RootView()
|
||||
ResetPasswordRootView()
|
||||
RegisterRootView()
|
||||
.navigationTitle("")
|
||||
.environment(self.appContext)
|
||||
.environment(self.userContext)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user