From d74f58ad0ed7e2c70f6e51f3de7871f1dcf6a776 Mon Sep 17 00:00:00 2001 From: anlicheng <244108715@qq.com> Date: Mon, 9 Mar 2026 22:40:49 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E7=BD=AE=E5=AF=86=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- punchnet/Views/Login/LoginView.swift | 37 +++------------------------- punchnet/Views/RootView.swift | 2 +- punchnet/punchnetApp.swift | 6 +++++ 3 files changed, 11 insertions(+), 34 deletions(-) diff --git a/punchnet/Views/Login/LoginView.swift b/punchnet/Views/Login/LoginView.swift index e4bd44c..a7c1dc5 100644 --- a/punchnet/Views/Login/LoginView.swift +++ b/punchnet/Views/Login/LoginView.swift @@ -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) diff --git a/punchnet/Views/RootView.swift b/punchnet/Views/RootView.swift index ed3a4bc..882448f 100644 --- a/punchnet/Views/RootView.swift +++ b/punchnet/Views/RootView.swift @@ -15,7 +15,7 @@ struct RootView: View { if userContext.isLogined { NetworkView() } else { - LoginRootView() + LoginView() } } } diff --git a/punchnet/punchnetApp.swift b/punchnet/punchnetApp.swift index 725edd0..e664144 100644 --- a/punchnet/punchnetApp.swift +++ b/punchnet/punchnetApp.swift @@ -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: {