VerifyLoginDlg.cs 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. using LitJson;
  2. using SC.XR.Unity;
  3. using ShadowStudio.Mgr;
  4. using Studio.Scripts.HttpMessage;
  5. using System;
  6. using System.Collections;
  7. using System.Collections.Generic;
  8. using System.Text.RegularExpressions;
  9. using UnityEngine;
  10. using UnityEngine.SceneManagement;
  11. using UnityEngine.UI;
  12. using XRTool.UI;
  13. using XRTool.Util;
  14. using XRTool.WorldUI;
  15. namespace ShadowStudio.UI
  16. {
  17. [RequireComponent(typeof(WorldDlg))]
  18. public class VerifyLoginDlg : UnitySingleton<VerifyLoginDlg>
  19. {
  20. private SCInputField phoneNumInputField;
  21. private SCInputField verifyInputField;
  22. private Button loginBtn;
  23. private Button sendBtn;
  24. private TextMesh sendText;
  25. private Text userRemind;
  26. private Text vcodeRemind;
  27. private Button userPassLoginBtn;
  28. private Button SNLoginBtn;
  29. private bool isSend;
  30. private int time;
  31. private float asecond;
  32. // private string receiveCode;
  33. private int num;
  34. // public bool isLock;
  35. WorldDlg dlg;
  36. // Start is called before the first frame update
  37. void Start()
  38. {
  39. dlg = GetComponent<WorldDlg>();
  40. phoneNumInputField = dlg.GetChild<SCInputField>("UIRoot/PhoneNumInputField");
  41. phoneNumInputField.onEndEdit.AddListener(InputPhoneNumEnd);
  42. phoneNumInputField.onValueChanged.AddListener(PhoneNumValueChanged);
  43. verifyInputField = dlg.GetChild<SCInputField>("UIRoot/VerifyInputField");
  44. verifyInputField.onValueChanged.AddListener(VerifyValueChanged);
  45. loginBtn = dlg.GetChild<Button>("FullUIRoot/LoginBtn");
  46. sendBtn = dlg.GetChild<Button>("UIRoot/SendBtn");
  47. loginBtn.onClick.AddListener(OnClickLogin);
  48. sendBtn.onClick.AddListener(OnClickSend);
  49. sendText = dlg.GetChild<TextMesh>("UIRoot/SendBtn/UIRoot/TextMesh");
  50. userRemind = dlg.GetChild<Text>("UIRoot/ErrorRemind/UserRemind");
  51. vcodeRemind = dlg.GetChild<Text>("UIRoot/ErrorRemind/VcodeRemind");
  52. userPassLoginBtn = dlg.GetChild<Button>("UIRoot/UserPassLoginBtn");
  53. SNLoginBtn = dlg.GetChild<Button>("UIRoot/SNLoginBtn");
  54. userPassLoginBtn.onClick.AddListener(OnClickUserLogin);
  55. SNLoginBtn.onClick.AddListener(OnClickSNLogin);
  56. //登录错误码返回
  57. LoginProxy.Instance.LoginErrorAction += LoginErrorHandler;
  58. //手机验证码
  59. LoginProxy.Instance.PhoneCodeAction += PhoneSMSCodeHandler;
  60. Init();
  61. }
  62. protected override void OnDestroy()
  63. {
  64. if (LoginProxy.Instance)
  65. {
  66. LoginProxy.Instance.LoginErrorAction -= LoginErrorHandler;
  67. LoginProxy.Instance.PhoneCodeAction -= PhoneSMSCodeHandler;
  68. }
  69. }
  70. // Update is called once per frame
  71. void Update()
  72. {
  73. if (isSend)
  74. {
  75. //倒计时
  76. sendText.text = LanguageMgr.Instance.GetMessage("1023").Message + "(" + time.ToString() + ")";
  77. asecond += Time.deltaTime;
  78. if (asecond >= 1)
  79. {
  80. time--;
  81. asecond = 0;
  82. }
  83. if (time < 0)
  84. {
  85. isSend = false;
  86. sendText.text = LanguageMgr.Instance.GetMessage("1022").Message;
  87. sendBtn.enabled = true;
  88. }
  89. }
  90. }
  91. private void Init()
  92. {
  93. isSend = false;
  94. sendText.text = LanguageMgr.Instance.GetMessage("1022").Message;
  95. sendBtn.enabled = true;
  96. }
  97. private void PhoneNumValueChanged(string phoneNum)
  98. {
  99. userRemind.gameObject.SetActive(false);
  100. }
  101. private void InputPhoneNumEnd(string phoneNum)
  102. {
  103. if (phoneNum == "")
  104. {
  105. userRemind.gameObject.SetActive(true);
  106. userRemind.text = LanguageMgr.Instance.GetMessage("1020").Message;
  107. }
  108. else
  109. {
  110. //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}$");
  111. Regex regNum = new Regex(@"^\d{11}$");
  112. bool ismatchNum = regNum.IsMatch(phoneNum);
  113. if (!ismatchNum)
  114. {
  115. userRemind.gameObject.SetActive(true);
  116. userRemind.text = LanguageMgr.Instance.GetMessage("1021").Message;
  117. }
  118. }
  119. }
  120. private void OnClickSend()
  121. {
  122. if (phoneNumInputField.text == "")
  123. {
  124. userRemind.gameObject.SetActive(true);
  125. userRemind.text = LanguageMgr.Instance.GetMessage("1020").Message;
  126. }
  127. else if (userRemind.gameObject.activeSelf == true)
  128. {
  129. return;
  130. }
  131. else
  132. {
  133. isSend = true;
  134. time = int.Parse(LanguageMgr.Instance.GetMessage("1024").Message);
  135. sendBtn.enabled = false;
  136. //ct 2021.5.17
  137. LoginProxy.Instance.RequestPhoneVerificationCode(phoneNumInputField.text.Trim());
  138. //NetWorkHeaders.SendVerifycode(phoneNumInputField.text, SendOk, SendFail);
  139. }
  140. }
  141. private void OnClickLogin()
  142. {
  143. if (phoneNumInputField.text == "" || verifyInputField.text == "")
  144. {
  145. if (phoneNumInputField.text == "")
  146. {
  147. userRemind.gameObject.SetActive(true);
  148. userRemind.text = LanguageMgr.Instance.GetMessage("1020").Message;
  149. }
  150. else if (verifyInputField.text == "")
  151. {
  152. vcodeRemind.gameObject.SetActive(true);
  153. vcodeRemind.text = LanguageMgr.Instance.GetMessage("1015").Message;
  154. }
  155. }
  156. else if (userRemind.gameObject.activeSelf == true || vcodeRemind.gameObject.activeSelf == true)
  157. {
  158. return;
  159. }
  160. else
  161. {
  162. loginBtn.enabled = false;
  163. Invoke("ReLoginBtn", 1f);
  164. //ct 2021.5.17
  165. LoginProxy.Instance.RequestPhoneLogin(phoneNumInputField.text.Trim(), verifyInputField.text.Trim());
  166. }
  167. }
  168. private void ReLoginBtn()
  169. {
  170. loginBtn.enabled = true;
  171. }
  172. private void VerifyValueChanged(string verifyNum)
  173. {
  174. vcodeRemind.gameObject.SetActive(false);
  175. }
  176. private void OnClickSNLogin()
  177. {
  178. SNLoginBtn.enabled = false;
  179. Invoke("ReSNLoginBtn", 1f);
  180. //ct 2021.5.17
  181. LoginProxy.Instance.RequestSNLogin();
  182. }
  183. private void ReSNLoginBtn()
  184. {
  185. SNLoginBtn.enabled = true;
  186. }
  187. private void OnClickUserLogin()
  188. {
  189. LoginViewMgr.Instance.ShowView(LoginViewMgr.LOGINDLG);
  190. }
  191. private void LoginErrorHandler(MessageType messageType, int code, string codeMessage)
  192. {
  193. if (messageType == MessageType.PhoneLoginType)
  194. {
  195. switch (code.ToString())
  196. {
  197. case "6006"://账号已登录
  198. CommonMethod.ShowLoginAbnormalPop();
  199. break;
  200. case "5051":// 验证码次数达到当日上限
  201. vcodeRemind.gameObject.SetActive(true);
  202. vcodeRemind.text = LanguageMgr.Instance.GetMessage("T1108").Message;
  203. break;
  204. default:
  205. vcodeRemind.gameObject.SetActive(true);
  206. vcodeRemind.text = codeMessage;
  207. break;
  208. }
  209. }
  210. }
  211. private void PhoneSMSCodeHandler(int codeNum)
  212. {
  213. if (LoginProxy.Instance.PHONE_CODE_NUM - codeNum<=10)
  214. {
  215. vcodeRemind.gameObject.SetActive(true);
  216. vcodeRemind.text =string.Format(LanguageMgr.Instance.GetMessage("1026").Message, LoginProxy.Instance.PHONE_CODE_NUM - codeNum);
  217. }
  218. }
  219. }
  220. }