123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235 |
- using LitJson;
- using SC.XR.Unity;
- using ShadowStudio.Mgr;
- using Studio.Scripts.HttpMessage;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Text.RegularExpressions;
- using UnityEngine;
- using UnityEngine.SceneManagement;
- using UnityEngine.UI;
- using XRTool.UI;
- using XRTool.Util;
- using XRTool.WorldUI;
- namespace ShadowStudio.UI
- {
- [RequireComponent(typeof(WorldDlg))]
- public class VerifyLoginDlg : UnitySingleton<VerifyLoginDlg>
- {
- private SCInputField phoneNumInputField;
- private SCInputField verifyInputField;
- private Button loginBtn;
- private Button sendBtn;
- private TextMesh sendText;
- private Text userRemind;
- private Text vcodeRemind;
- private Button userPassLoginBtn;
- private Button SNLoginBtn;
- private bool isSend;
- private int time;
- private float asecond;
- // private string receiveCode;
- private int num;
- // public bool isLock;
- WorldDlg dlg;
- // Start is called before the first frame update
- void Start()
- {
- dlg = GetComponent<WorldDlg>();
- phoneNumInputField = dlg.GetChild<SCInputField>("UIRoot/PhoneNumInputField");
- phoneNumInputField.onEndEdit.AddListener(InputPhoneNumEnd);
- phoneNumInputField.onValueChanged.AddListener(PhoneNumValueChanged);
- verifyInputField = dlg.GetChild<SCInputField>("UIRoot/VerifyInputField");
- verifyInputField.onValueChanged.AddListener(VerifyValueChanged);
- loginBtn = dlg.GetChild<Button>("FullUIRoot/LoginBtn");
- sendBtn = dlg.GetChild<Button>("UIRoot/SendBtn");
- loginBtn.onClick.AddListener(OnClickLogin);
- sendBtn.onClick.AddListener(OnClickSend);
- sendText = dlg.GetChild<TextMesh>("UIRoot/SendBtn/UIRoot/TextMesh");
- userRemind = dlg.GetChild<Text>("UIRoot/ErrorRemind/UserRemind");
- vcodeRemind = dlg.GetChild<Text>("UIRoot/ErrorRemind/VcodeRemind");
- userPassLoginBtn = dlg.GetChild<Button>("UIRoot/UserPassLoginBtn");
- SNLoginBtn = dlg.GetChild<Button>("UIRoot/SNLoginBtn");
- userPassLoginBtn.onClick.AddListener(OnClickUserLogin);
- SNLoginBtn.onClick.AddListener(OnClickSNLogin);
- //登录错误码返回
- LoginProxy.Instance.LoginErrorAction += LoginErrorHandler;
- //手机验证码
- LoginProxy.Instance.PhoneCodeAction += PhoneSMSCodeHandler;
- Init();
- }
-
- protected override void OnDestroy()
- {
- if (LoginProxy.Instance)
- {
- LoginProxy.Instance.LoginErrorAction -= LoginErrorHandler;
- LoginProxy.Instance.PhoneCodeAction -= PhoneSMSCodeHandler;
- }
- }
- // Update is called once per frame
- void Update()
- {
- if (isSend)
- {
- //倒计时
- sendText.text = LanguageMgr.Instance.GetMessage("1023").Message + "(" + time.ToString() + ")";
- asecond += Time.deltaTime;
- if (asecond >= 1)
- {
- time--;
- asecond = 0;
- }
- if (time < 0)
- {
- isSend = false;
- sendText.text = LanguageMgr.Instance.GetMessage("1022").Message;
- sendBtn.enabled = true;
- }
- }
- }
- private void Init()
- {
- isSend = false;
- sendText.text = LanguageMgr.Instance.GetMessage("1022").Message;
- sendBtn.enabled = true;
- }
- private void PhoneNumValueChanged(string phoneNum)
- {
- userRemind.gameObject.SetActive(false);
- }
- private void InputPhoneNumEnd(string phoneNum)
- {
- if (phoneNum == "")
- {
- userRemind.gameObject.SetActive(true);
- userRemind.text = LanguageMgr.Instance.GetMessage("1020").Message;
- }
- else
- {
- //Regex regNum = new Regex(@"^(13[0-9]|14[5|7]|15[0|1|2|3|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9])\d{8}$");
- Regex regNum = new Regex(@"^\d{11}$");
- bool ismatchNum = regNum.IsMatch(phoneNum);
- if (!ismatchNum)
- {
- userRemind.gameObject.SetActive(true);
- userRemind.text = LanguageMgr.Instance.GetMessage("1021").Message;
- }
- }
- }
- private void OnClickSend()
- {
- if (phoneNumInputField.text == "")
- {
- userRemind.gameObject.SetActive(true);
- userRemind.text = LanguageMgr.Instance.GetMessage("1020").Message;
- }
- else if (userRemind.gameObject.activeSelf == true)
- {
- return;
- }
- else
- {
- isSend = true;
- time = int.Parse(LanguageMgr.Instance.GetMessage("1024").Message);
- sendBtn.enabled = false;
- //ct 2021.5.17
- LoginProxy.Instance.RequestPhoneVerificationCode(phoneNumInputField.text.Trim());
- //NetWorkHeaders.SendVerifycode(phoneNumInputField.text, SendOk, SendFail);
- }
- }
- private void OnClickLogin()
- {
- if (phoneNumInputField.text == "" || verifyInputField.text == "")
- {
- if (phoneNumInputField.text == "")
- {
- userRemind.gameObject.SetActive(true);
- userRemind.text = LanguageMgr.Instance.GetMessage("1020").Message;
- }
- else if (verifyInputField.text == "")
- {
- vcodeRemind.gameObject.SetActive(true);
- vcodeRemind.text = LanguageMgr.Instance.GetMessage("1015").Message;
- }
- }
- else if (userRemind.gameObject.activeSelf == true || vcodeRemind.gameObject.activeSelf == true)
- {
- return;
- }
- else
- {
- loginBtn.enabled = false;
- Invoke("ReLoginBtn", 1f);
- //ct 2021.5.17
- LoginProxy.Instance.RequestPhoneLogin(phoneNumInputField.text.Trim(), verifyInputField.text.Trim());
- }
- }
- private void ReLoginBtn()
- {
- loginBtn.enabled = true;
- }
- private void VerifyValueChanged(string verifyNum)
- {
- vcodeRemind.gameObject.SetActive(false);
- }
- private void OnClickSNLogin()
- {
- SNLoginBtn.enabled = false;
- Invoke("ReSNLoginBtn", 1f);
- //ct 2021.5.17
- LoginProxy.Instance.RequestSNLogin();
- }
- private void ReSNLoginBtn()
- {
- SNLoginBtn.enabled = true;
- }
- private void OnClickUserLogin()
- {
- LoginViewMgr.Instance.ShowView(LoginViewMgr.LOGINDLG);
- }
- private void LoginErrorHandler(MessageType messageType, int code, string codeMessage)
- {
- if (messageType == MessageType.PhoneLoginType)
- {
- switch (code.ToString())
- {
- case "6006"://账号已登录
- CommonMethod.ShowLoginAbnormalPop();
- break;
- case "5051":// 验证码次数达到当日上限
- vcodeRemind.gameObject.SetActive(true);
- vcodeRemind.text = LanguageMgr.Instance.GetMessage("T1108").Message;
- break;
- default:
- vcodeRemind.gameObject.SetActive(true);
- vcodeRemind.text = codeMessage;
- break;
- }
- }
- }
- private void PhoneSMSCodeHandler(int codeNum)
- {
- if (LoginProxy.Instance.PHONE_CODE_NUM - codeNum<=10)
- {
- vcodeRemind.gameObject.SetActive(true);
- vcodeRemind.text =string.Format(LanguageMgr.Instance.GetMessage("1026").Message, LoginProxy.Instance.PHONE_CODE_NUM - codeNum);
- }
- }
- }
- }
|