@using Common.Validation @using HushianWebApp.Service @inject AuthService AuthService @inject VerificationService verificationService;
نیاز برای ارتباط با کارشناسان وارد شود
@if (ID == 0) {
} else {
}
@code { private bool visible = false; [Parameter] public EventCallback OnMultipleOfThree { get; set; } public string Username { get; set; } public int ID { get; set; } = 0; private string _code = string.Empty; public string Code { get { return _code; } set { _code=value; if (value.Length == 4) ver().ConfigureAwait(true); } } //----------------- // private string code1, code2, code3, code4; private ElementReference input1, input2, input3, input4; string validateStyleUser = ""; private bool isButtonDisabled = true; private int countdown = 60; private System.Timers.Timer? timer; } @functions { async Task Login() { if (Username.Replace("-", "").CheckMobile()) { visible = true; ID = await AuthService.login(new Common.Models.Auth.UserSide.AuthRequestFromUserSide() { Mobile = Username.Replace("-", "") }); validateStyleUser = ""; await verifiTimer(); visible = false; } else { validateStyleUser = " border: 2px solid red; border-radius: 4px;"; } } async Task verifiTimer() { //---------- isButtonDisabled = true; countdown = 60; timer = new System.Timers.Timer(1000); // هر 1 ثانیه timer.Elapsed += OnTimerElapsed; timer.AutoReset = true; timer.Enabled = true; //---------- } private void OnTimerElapsed(object? sender, System.Timers.ElapsedEventArgs e) { if (countdown > 0) { countdown--; InvokeAsync(StateHasChanged); // بروزرسانی UI } if (countdown == 0) { isButtonDisabled = false; timer?.Stop(); timer?.Dispose(); StateHasChanged(); } } async Task ver() { visible = true; if (await AuthService.Verificationlogin(ID, Code)) await OnMultipleOfThree.InvokeAsync(); visible = false; } // private async Task MoveNext(ChangeEventArgs e) // { // if (e.Value?.ToString()?.Length == 1) // { // if (input1.Context == null) return; // if (string.IsNullOrEmpty(code1)) // await input2.FocusAsync(); // else if (string.IsNullOrEmpty(code2)) // await input3.FocusAsync(); // else if (string.IsNullOrEmpty(code3)) // await input4.FocusAsync(); // else if (string.IsNullOrEmpty(code4)) // { // Code = $"{code1}{code2}{code3}{code4}"; // } // } // } // private async Task OnLastInput(ChangeEventArgs e) // { // code4 = e.Value?.ToString(); // if (!string.IsNullOrEmpty(code4) && code4.Length == 1) // { // Code = $"{code1}{code2}{code3}{code4}"; // await ver(); // } // } }