| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177 |
- 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
- {
- /// <summary>
- /// 记录错误次数
- /// </summary>
- private int m_RecordErrorCount = 0;
- /// <summary>
- /// 缓存账号信息
- /// </summary>
- 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();
- }
- }
- }
- /// <summary>
- /// 登录检测
- /// </summary>
- private void LoginDetection()
- {
- if (!string.IsNullOrEmpty(Input_Name.text) && !string.IsNullOrEmpty(Input_Password.text))
- {
- UserProxy userProxy = DAL.Instance.Get<UserProxy>();
- 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<LoginPanel>();
- // 记载场景
- 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 = "";
- }
- }
- }
|