重置密码

This commit is contained in:
anlicheng 2026-03-09 22:40:49 +08:00
parent b12695d5bd
commit d74f58ad0e
3 changed files with 11 additions and 34 deletions

View File

@ -8,39 +8,10 @@
import SwiftUI
import Observation
enum AuthScreen {
case login
case resetPassword
case register
}
struct LoginRootView: View {
@Environment(AppContext.self) var appContext: AppContext
@State private var authScreen = AuthScreen.login
var body: some View {
Group {
switch self.authScreen {
case .login:
LoginView(authScreen: $authScreen)
case .resetPassword:
ResetPasswordRootView()
case .register:
EmptyView()
}
}
.onChange(of: self.authScreen) {
print("app auth screen changed")
}
}
}
//
struct LoginView: View {
@Environment(UserContext.self) var userContext: UserContext
@State private var authMethod: AuthMethod = .account
@Binding var authScreen: AuthScreen
enum AuthMethod {
case token
@ -90,7 +61,7 @@ struct LoginView: View {
case .token:
LoginTokenView()
case .account:
LoginAccountView(authScreen: $authScreen)
LoginAccountView()
}
}
@ -101,7 +72,6 @@ struct LoginView: View {
}
struct LoginTokenView: View {
@Environment(UserContext.self) var userContext: UserContext
@State private var token: String = ""
@ -174,9 +144,10 @@ struct LoginTokenView: View {
}
struct LoginAccountView: View {
@Environment(\.openWindow) private var openWindow
@Environment(UserContext.self) var userContext: UserContext
@Environment(AppContext.self) var appContext: AppContext
@Binding var authScreen: AuthScreen
@State private var username: String = ""
@State private var password: String = ""
@ -224,7 +195,7 @@ struct LoginAccountView: View {
, alignment: .topLeading)
Button {
self.authScreen = .resetPassword
openWindow(id: "resetPassword")
} label: {
Text("忘记密码?")
.underline(true, color: .blue)

View File

@ -15,7 +15,7 @@ struct RootView: View {
if userContext.isLogined {
NetworkView()
} else {
LoginRootView()
LoginView()
}
}
}

View File

@ -90,6 +90,12 @@ struct punchnetApp: App {
}
.defaultSize(width: 800, height: 500)
Window("重置密码", id: "resetPassword") {
ResetPasswordRootView()
.environment(self.userContext)
}
.defaultSize(width: 800, height: 500)
MenuBarExtra("punchnet", image: "logo_32") {
VStack {
Button(action: {