From a476856ce1718b2f77746a2f493d2def41b1b5ef Mon Sep 17 00:00:00 2001 From: HuoWenBo <1684240320@qq.com> Date: Sat, 18 Nov 2023 12:49:26 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=E4=BF=AE=E5=A4=8D=E9=AA=8C?= =?UTF-8?q?=E8=AF=81=E7=A0=81=E5=88=B7=E6=96=B0BUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- templates/system/login.html | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/templates/system/login.html b/templates/system/login.html index bef6b6d..70b88b6 100644 --- a/templates/system/login.html +++ b/templates/system/login.html @@ -43,6 +43,29 @@ let popup = layui.popup; let captchaPath = "{{ url_for('system.passport.get_captcha') }}"; + /** + * 刷新验证码函数 + */ + const refreshCaptchaImage = (function () { + let captchaImage = document.getElementById("captchaImage") + return function () { + captchaImage.src = captchaPath + "?" + Math.random() + } + })() + + /** + * 立即刷新验证码并且每隔 30秒 刷新 + */ + const initCaptchaImageTimer = (function () { + let captchaImageTimer = null + return function () { + captchaImageTimer = setInterval(function () { + refreshCaptchaImage() + }, 30 * 1000); + refreshCaptchaImage() + } + })() + form.on('submit(login)', function (data) { let loader = layer.load(); let btn = button.load({elem: '.login'}); @@ -59,7 +82,7 @@ }) } else { popup.failure(result.msg, function () { - document.getElementById("captchaImage").src = captchaPath + "?" + Math.random(); + initCaptchaImageTimer() }); } }) @@ -67,13 +90,9 @@ }); return false; }); - $("#captchaImage").click(function () { - document.getElementById("captchaImage").src = captchaPath + "?" + Math.random(); + initCaptchaImageTimer() }); - setInterval(function () { - document.getElementById("captchaImage").src = captchaPath + "?" + Math.random(); - }, 30 * 1000); })