迁移站长登录验证码脚本
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
// 站长登录页交互入口,集中管理验证码刷新,避免在 Blade 中暴露全局函数。
|
||||
|
||||
let adminLoginControlsBound = false;
|
||||
|
||||
/**
|
||||
* 为验证码图片追加随机参数,强制浏览器重新请求图片。
|
||||
*
|
||||
* @param {HTMLImageElement} captchaImage
|
||||
* @returns {void}
|
||||
*/
|
||||
function refreshCaptchaImage(captchaImage) {
|
||||
const refreshUrl = captchaImage.getAttribute("data-captcha-refresh-url") ?? "/captcha/default";
|
||||
captchaImage.src = `${refreshUrl}?${Math.random()}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* 绑定站长登录页验证码刷新事件。
|
||||
*
|
||||
* @returns {void}
|
||||
*/
|
||||
function bindAdminLoginControls() {
|
||||
if (adminLoginControlsBound || typeof document === "undefined") {
|
||||
return;
|
||||
}
|
||||
|
||||
adminLoginControlsBound = true;
|
||||
|
||||
document.addEventListener("click", (event) => {
|
||||
if (!(event.target instanceof HTMLImageElement)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.target.hasAttribute("data-captcha-refresh-url")) {
|
||||
refreshCaptchaImage(event.target);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
bindAdminLoginControls();
|
||||
@@ -522,7 +522,7 @@
|
||||
<div class="captcha-row">
|
||||
<input id="captcha" name="captcha" type="text" placeholder="输入验证码" required>
|
||||
<img src="/captcha/default?{{ mt_rand() }}" alt="站长登录验证码" id="captcha-img" class="captcha-image"
|
||||
onclick="refreshCaptcha()" title="点击刷新验证码">
|
||||
data-captcha-refresh-url="/captcha/default" title="点击刷新验证码">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -552,14 +552,7 @@
|
||||
</section>
|
||||
</main>
|
||||
|
||||
<script>
|
||||
/**
|
||||
* 刷新验证码图片,避免浏览器缓存旧图。
|
||||
*/
|
||||
function refreshCaptcha() {
|
||||
document.getElementById('captcha-img').src = '/captcha/default?' + Math.random();
|
||||
}
|
||||
</script>
|
||||
@vite('resources/js/admin-login.js')
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user