!119 修复登录页面验证码刷新问题

Merge pull request !119 from Huo-WenBo/master
This commit is contained in:
不胜舟
2023-11-22 05:57:33 +00:00
committed by Gitee
3 changed files with 29 additions and 7 deletions
+2 -1
View File
@@ -2,7 +2,8 @@ import datetime
import os import os
from flask import Flask, request from flask import Flask, request
from flask_sqlalchemy import SQLAlchemy, BaseQuery from flask_sqlalchemy import SQLAlchemy
from flask_sqlalchemy.query import Query as BaseQuery
from flask_marshmallow import Marshmallow from flask_marshmallow import Marshmallow
from marshmallow import fields from marshmallow import fields
from marshmallow.validate import ( from marshmallow.validate import (
BIN
View File
Binary file not shown.
+27 -6
View File
@@ -43,6 +43,31 @@
let popup = layui.popup; let popup = layui.popup;
let captchaPath = "{{ url_for('system.passport.get_captcha') }}"; 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 () {
clearInterval(captchaImageTimer)
captchaImageTimer = setInterval(function () {
refreshCaptchaImage()
}, 30 * 1000);
refreshCaptchaImage()
}
})()
initCaptchaImageTimer()
form.on('submit(login)', function (data) { form.on('submit(login)', function (data) {
let loader = layer.load(); let loader = layer.load();
let btn = button.load({elem: '.login'}); let btn = button.load({elem: '.login'});
@@ -59,7 +84,7 @@
}) })
} else { } else {
popup.failure(result.msg, function () { popup.failure(result.msg, function () {
document.getElementById("captchaImage").src = captchaPath + "?" + Math.random(); initCaptchaImageTimer()
}); });
} }
}) })
@@ -67,13 +92,9 @@
}); });
return false; return false;
}); });
$("#captchaImage").click(function () { $("#captchaImage").click(function () {
document.getElementById("captchaImage").src = captchaPath + "?" + Math.random(); initCaptchaImageTimer()
}); });
setInterval(function () {
document.getElementById("captchaImage").src = captchaPath + "?" + Math.random();
}, 30 * 1000);
}) })
</script> </script>
<script> <script>