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