using UnityEngine; using UnityEngine.UI; using Kill.Managers; using Kill.Utils; using Kill.Network; namespace Kill.UI.Pages { public class LoginPasswordPanel : LoginSubPageBase { public InputField passwordInput; public Text errorText; public Button loginBtn; public Button forgotPasswordBtn; public Button toRegisterBtn; protected override void OnInitialize() { if (loginBtn != null) loginBtn.onClick.AddListener(OnLoginClick); if (forgotPasswordBtn != null) forgotPasswordBtn.onClick.AddListener(OnForgotPassword); if (toRegisterBtn != null) toRegisterBtn.onClick.AddListener(() => ShowPage(LoginPageCtrl.SubPageType.Register)); } protected override void OnShow() { // 清空密码和错误 if (passwordInput != null) passwordInput.text = ""; if (errorText != null) errorText.text = ""; } private void OnLoginClick() { string password = passwordInput != null ? passwordInput.text : ""; if (string.IsNullOrEmpty(password)) { errorText.text = LanguageManager.Instance.GetLanguage("100040"); return; } string email = LoginPageCtrl.Instance.GetCurrentEmail(); // 使用自定义错误版本,在输入框下方显示错误 LoginPageCtrl.Instance.Login(email, password, onSuccess: (data) => { // 登录成功 Debug.Log("登录成功,准备跳转主页"); // UIManager.Instance.OpenPage(UIManager.PageName.HomePage); }, onError: (code, message) => { // 在输入框下方显示错误 errorText.text = LanguageManager.Instance.GetLanguage("100040"); } ); } private void OnForgotPassword() { // 跳转到验证码页,设置为重置密码场景 var verifyPanel = GetSubPage(LoginPageCtrl.SubPageType.VerificationCode) as VerificationCodePanel; if (verifyPanel != null) { verifyPanel.SetSceneType(VerificationCodePanel.CodeSceneType.ResetPassword); } ShowPage(LoginPageCtrl.SubPageType.VerificationCode); } } }