ZhaoHuiPasswordView.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. using UI.Login;
  2. using FairyGUI;
  3. using UnityEngine;
  4. using System.ComponentModel;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Text.RegularExpressions;
  8. using ET;
  9. namespace GFGGame
  10. {
  11. public class ZhaoHuiPasswordView : BaseWindow
  12. {
  13. private UI_ZhaoHuiPasswordUI _ui;
  14. public override void Dispose()
  15. {
  16. if (_ui != null)
  17. {
  18. _ui.Dispose();
  19. _ui = null;
  20. }
  21. base.Dispose();
  22. }
  23. protected override void OnInit()
  24. {
  25. base.OnInit();
  26. packageName = UI_ZhaoHuiPasswordUI.PACKAGE_NAME;
  27. _ui = UI_ZhaoHuiPasswordUI.Create();
  28. this.viewCom = _ui.target;
  29. this.viewCom.Center();
  30. this.modal = true;
  31. _ui.m_btnSendCode.onClick.Add(() =>
  32. {
  33. if (!Regex.IsMatch(_ui.m_txtPhone.text.Trim(), // 匹配所有中国大陆手机号(11 位,包括物联网和卫星电话)
  34. @"^(?:\+86)?1(?:3\d{3}|4[5-9]\d{2}|5[0-35-9]\d{2}|6[2567]\d{2}|7[0-8]\d{2}|8\d{3}|9[0-35-9]\d{2})\d{6}$"))
  35. {
  36. PromptController.Instance.ShowFloatTextPrompt("输入的手机号格式有误");
  37. return;
  38. }
  39. _ui.m_btnSendCode.enabled = false;
  40. //在此发送验证码
  41. SecurityHelper.GetMobileVerificationCode(_ui.m_txtPhone.text, SendCodeType.ChangePassword)
  42. .Coroutine();
  43. float endTime = Time.time + 60;
  44. Timers.inst.Add(1, 0, timerCallback, endTime);
  45. timerCallback(endTime);
  46. });
  47. _ui.m_btnSubmit.onClick.Add(OnClickBtnSubmit);
  48. }
  49. private async void OnClickBtnSubmit()
  50. {
  51. if (!Regex.IsMatch(_ui.m_txtPhone.text.Trim(), // 匹配所有中国大陆手机号(11 位,包括物联网和卫星电话)
  52. @"^(?:\+86)?1(?:3\d{3}|4[5-9]\d{2}|5[0-35-9]\d{2}|6[2567]\d{2}|7[0-8]\d{2}|8\d{3}|9[0-35-9]\d{2})\d{6}$"))
  53. {
  54. PromptController.Instance.ShowFloatTextPrompt("输入的手机号格式有误");
  55. return;
  56. }
  57. string code = _ui.m_txtCode.text.Trim();
  58. string phoneNumber = _ui.m_txtPhone.text.Trim();
  59. string account = _ui.m_txtAccount.text.Trim();
  60. string password = _ui.m_txtPasword.text.Trim();
  61. string password2 = _ui.m_txtPaswrod2.text.Trim();
  62. if (password != password2)
  63. {
  64. PromptController.Instance.ShowFloatTextPrompt("两次输入的密码不一致");
  65. }
  66. A2C_UpPassword res = await SecurityHelper.UpPassword(code, phoneNumber, account, password);
  67. if (res is { Error: ErrorCode.ERR_Success })
  68. {
  69. LoginController.Login(account, password).Coroutine();
  70. Hide();
  71. }
  72. else
  73. {
  74. ErrorCodeController.Handler(res.Error);
  75. }
  76. }
  77. private void timerCallback(object param)
  78. {
  79. float endTime = (float)param;
  80. float remainTime = endTime - Time.time;
  81. if (remainTime <= 0)
  82. {
  83. _ui.m_btnSendCode.text = "发送验证码";
  84. _ui.m_btnSendCode.enabled = true;
  85. Timers.inst.Remove(timerCallback);
  86. }
  87. else
  88. {
  89. _ui.m_btnSendCode.text = (int)remainTime + "s后重发";
  90. }
  91. }
  92. protected override void OnShown()
  93. {
  94. base.OnShown();
  95. _ui.m_txtAccount.editable = true;
  96. if (viewData != null)
  97. {
  98. _ui.m_txtAccount.text = (string)viewData;
  99. _ui.m_txtAccount.editable = false;
  100. }
  101. }
  102. protected override void OnHide()
  103. {
  104. base.OnHide();
  105. Timers.inst.Remove(timerCallback);
  106. }
  107. protected override void AddEventListener()
  108. {
  109. base.AddEventListener();
  110. }
  111. protected override void RemoveEventListener()
  112. {
  113. base.RemoveEventListener();
  114. }
  115. }
  116. }