using Yw; using Yw.WinFrmUI; using Timer = System.Windows.Forms.Timer; namespace PBS.Desktop { public partial class SmsLoginCtrl : DevExpress.XtraEditors.XtraUserControl, ILogin { public SmsLoginCtrl() { InitializeComponent(); this.layoutControl1.SetupLayoutControl(); } /// /// 登录开始事件 /// public event Action LoginStartEvent; /// /// 登录取消事件 /// public event Action LoginCancelEvent; /// /// 登录完成事件 /// public event Action LoginEndEvet; private bool _isInitialized = false;//初始化 private const string _template = "hzkw_sms_template";//微信登录模板 private const string _software = "HStation_XHS_DESKTOP";//软件编码 /// /// 初始化 /// public void Initial() { if (_isInitialized) { return; } _isInitialized = true; } //发送验证码 private async void btnSendCode_Click(object sender, EventArgs e) { this.dxErrorProvider1.ClearErrors(); var mobile = this.txtMobileNumber.Text.Trim(); if (!Yw.Service.Auth.MobileNumberHelper.Verify(mobile)) { this.dxErrorProvider1.SetError(this.txtMobileNumber, "请输入正确手机号码"); return; } var bol = await BLLFactory.Instance.SendCode(_template, mobile, _software); if (bol) { this.labSendCode.Enabled = false; StartCountdown(); } else { this.dxErrorProvider1.SetError(this.txtMobileNumber, "发送失败"); this.labSendCode.Enabled = true; } } private void StartCountdown() { int countdown = 60; Timer timer = new Timer(); timer.Interval = 1000; // 1秒 timer.Tick += (s, e) => { countdown--; if (countdown > 0) { this.labSendCode.Text = $"{countdown}秒后重新发送"; } else { timer.Stop(); this.labSendCode.Text = "发送验证码"; this.labSendCode.Enabled = true; } }; timer.Start(); } //取消登录 private void btnCancel_Click(object sender, EventArgs e) { this.LoginCancelEvent?.Invoke(); } //登录 private async void btnLogin_Click(object sender, EventArgs e) { this.dxErrorProvider1.ClearErrors(); var mobile = this.txtMobileNumber.Text.Trim(); if (!Yw.Service.Auth.MobileNumberHelper.Verify(mobile)) { this.dxErrorProvider1.SetError(this.txtMobileNumber, "请输入正确手机号码"); return; } var validCode = this.txtCode.Text.Trim(); if (string.IsNullOrEmpty(validCode)) { this.dxErrorProvider1.SetError(this.txtCode, "请输入验证码"); return; } this.LoginStartEvent?.Invoke(); var result = await BLLFactory.Instance.LoginSoftwareStandardBySmsAccount(_template, mobile, _software, validCode, null); this.LoginEndEvet?.Invoke(result); } } }