| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- using System.Text.RegularExpressions;
- using JCUnityLib;
- public class HRB_LoginView : ViewBase
- {
- GameObject loginInUser;
- GameObject loginInPWD;
- GameObject loginInCaptcha;
- GameObject btnLogin;
- GameObject btnRegister;
- int captcha_Login = -222222222;
- void Awake()
- {
- GameObject.Find("TempCanvas").transform.Find("AgreementPopup").gameObject.SetActive(true);
- }
- void Start()
- {
- loginInUser = transform.Find("InUser").gameObject;
- loginInPWD = transform.Find("InPWD").gameObject;
- loginInCaptcha = transform.Find("InCaptcha").gameObject;
- btnLogin = transform.Find("BtnLogin").gameObject;
- btnRegister = transform.Find("BtnRegister").gameObject;
- btnLogin.GetComponent<Button>().onClick.AddListener(LoginNormal);
- btnRegister.GetComponent<Button>().onClick.AddListener(ToRegisterView);
- InitInputLimit();
- ChnageCaptcha();
- }
- void Update() {
- #if UNITY_EDITOR
- if (Input.GetKeyDown(KeyCode.F1)) {
- GetInputField(loginInUser).text = "lvjincheng";
- GetInputField(loginInPWD).text = "19980301";
- GetInputField(loginInCaptcha).text = captcha_Login.ToString();
- LoginNormal();
- }
- #endif
- }
- void InitInputLimit() {
- GameObject[] inputNodes = {loginInUser, loginInPWD};
- foreach (var inputNode in inputNodes) {
- InputField inputField = GetInputField(inputNode);
- inputField.onValueChanged.AddListener(delegate(string text) {
- Match match = new Regex("[^A-Za-z0-9]").Match(text);
- if (match.Success) {
- inputField.text = text.Replace(match.Value, "");
- }
- });
- }
- }
- InputField GetInputField(GameObject inputNode) {
- return inputNode.transform.Find("InputField").GetComponent<InputField>();
- }
- void ChnageCaptcha() {
- StartCoroutine(CaptchaController.Instance.GetCaptcha(
- loginInCaptcha.transform.Find("CodeImage").GetComponent<Image>(),
- (code) => { captcha_Login = code; }
- ));
- }
- JCUnityLib.Throttler throttlerLoginNormal = new JCUnityLib.Throttler(2000);
- void LoginNormal() {
- InputField user = GetInputField(loginInUser);
- if (user.text.Trim().Length == 0) {
- PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByCNKey("请输入账号"));
- return;
- }
- InputField pwd = GetInputField(loginInPWD);
- if (pwd.text.Trim().Length == 0) {
- PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByCNKey("请输入密码"));
- return;
- }
- InputField captcha = GetInputField(loginInCaptcha);
- if (!captcha.text.Equals(captcha_Login.ToString())) {
- PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByCNKey("验证码错误"));
- return;
- }
- if (!AgreenmentOption.ins.IsAgreementChecked()) {
- PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByCNKey("请阅读并同意App协议"));
- return;
- }
- if (throttlerLoginNormal.CanPass() == false) {
- PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByCNKey("操作过于频繁"));
- return;
- }
- StartCoroutine(LoginController.Instance.LoginNormal(
- user.text, pwd.text, (res) => {
- if (res.code == 0) {
- string loginToken = (string)res.data;
- CommonConfig.businessServerWsURL = loginToken.Split('&')[2];
- PlayerPrefs.SetString(LoginMgr.LoginTokenKey, loginToken);
- HRB_ViewMgr.Instance.DestroyView<HRB_LoginView>();
- HRB_ViewMgr.Instance.ShowView<HRB_HomeView>();
- } else {
- PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByCNKey(res.msg));
- }
- }
- ));
- }
- public void ToRegisterView()
- {
- HRB_ViewMgr.Instance.ShowView<HRB_RegisterView>();
- }
- public override void OnNotifyView(string eventName, object[] args)
- {
- if (eventName == "FillLoginInput" && args.Length == 2)
- {
- GetInputField(loginInUser).text = (string)args[0];
- GetInputField(loginInPWD).text = (string)args[1];
- }
- }
- }
|