You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
iot/projects/IoT.Shared/Views/Account/_Script.cshtml

56 lines
1.6 KiB

@inject IConfiguration cfg
@{
var total = cfg.GetValue<int>("CaptchaSeconds");
var sec = total;
var session = this.Context.Session;
var model = session.Get<CodeCaptchaModel>(CodeCaptchaModel.Key);
if (model != null)
{
sec = (int)(model.ExpireDateUtc - DateTime.UtcNow).TotalSeconds;
}
}
<script>
var total = @total;
var sec = @sec;
var timer;
function StartTimer(sec) {
if (sec > 0) {
$('#send-code').attr("disabled", "disabled").attr("value", "重发" + sec + "秒");
timer = setTimeout('StartTimer("' + (sec - 1) + '")', 1000);
}
else {
$('#send-code').removeAttr("disabled").attr("value", "发送验证码");
EndTimer();
}
}
function EndTimer() {
clearTimeout(timer);
}
$(function () {
if (sec > 0 && sec < total) {
StartTimer(sec);
}
});
$(function () {
$('#send-code').click(function () {
$(this).attr("disabled", "disabled");
if (!valid()) {
$(this).removeAttr("disabled");
return;
}
var url = getUrl();
$.getJSON(url, function (json) {
if (json.success) {
StartTimer(json.data);
}
else {
alert(json.data);
$(this).removeAttr("disabled");
}
}).fail(function () {
$(this).removeAttr("disabled")
});
return false;
});
});
</script>