using System; using System.Collections; using Chiva.Toolkit.Function.NoBorder; using UnityEngine; using UnityEngine.UI; using QFramework; using UnityEngine.SceneManagement; namespace QFramework { public class LoginPanelData : UIPanelData { } public partial class LoginPanel : UIPanel { /// /// 记录错误次数 /// private int m_RecordErrorCount = 0; /// /// 缓存账号信息 /// private string m_CacheAccountInfo = String.Empty; protected override void ProcessMsg(int eventId, QMsg msg) { } protected override void OnInit(IUIData uiData = null) { mData = uiData as LoginPanelData ?? new LoginPanelData(); // please add init code here m_RecordErrorCount = 0; Init(); } #region 内置函数 protected override void OnOpen(IUIData uiData = null) { WindowsSetting.Instance.SetBorderModel(true, 600, 353); Input_Name.text = Input_Password.text = string.Empty; } protected override void OnShow() { } protected override void OnHide() { WindowsSetting.Instance.SetBorderModel(true, 1920, 1080); } protected override void OnClose() { WindowsSetting.Instance.SetBorderModel(true, 1920, 1080); } #endregion private void Init() { MinBtn.onClick.AddListener(() => WindowsSetting.Instance.OnMinBtnClick()); CloseBtn.onClick.AddListener(() => WindowsSetting.Instance.ShutDownFunction()); LoginBtn.onClick.AddListener(() => { LoginDetection(); }); Input_Name.onValueChanged.AddListener((input) => { if (!string.IsNullOrEmpty(input) && PlayerPrefs.HasKey(input)) { Input_Password.text = PlayerPrefs.GetString(input); Toggle_Rember.isOn = true; } }); } void Update() { if (Input.GetKeyDown(KeyCode.Tab)) { if (Input_Name.isFocused) { Input_Password.Select(); } else if (Input_Password.isFocused) { Input_Name.Select(); } } } /// /// 登录检测 /// private void LoginDetection() { if (!string.IsNullOrEmpty(Input_Name.text) && !string.IsNullOrEmpty(Input_Password.text)) { UserProxy userProxy = DAL.Instance.Get(); if (userProxy != null) { StudentLoginResponse loginResponse = userProxy.UserLogin(Input_Name.text, Input_Password.text.Encrypt("chivatech")); if (loginResponse.Result) { m_CacheAccountInfo = Input_Name.text; m_RecordErrorCount = 0; if (Toggle_Rember.isOn) { PlayerPrefs.SetString(Input_Name.text, Input_Password.text); } else { if (PlayerPrefs.HasKey(Input_Name.text)) { PlayerPrefs.DeleteKey(Input_Name.text); } } UIKit.ClosePanel(); // 记载场景 SceneManager.LoadSceneAsync("Select"); } else { StopAllCoroutines(); if (m_CacheAccountInfo.Equals(Input_Name.text)) { m_RecordErrorCount++; } else { m_CacheAccountInfo = Input_Name.text; m_RecordErrorCount = 1; } if (m_RecordErrorCount >= 3) { StartCoroutine(ShowPopText("如果忘记账号或密码,请联系管理员")); } else { StartCoroutine(ShowPopText(loginResponse.Message)); } } } else { StartCoroutine(ShowPopText("账号存在问题,请联系管理员")); } } else { StartCoroutine(ShowPopText("账号或密码不能为空")); } } IEnumerator ShowPopText(string message) { PromptTxt.text = message; yield return new WaitForSeconds(2f); PromptTxt.text = ""; } } }