迁移站长登录验证码脚本

This commit is contained in:
2026-04-25 13:33:15 +08:00
parent c3229f870a
commit 7900145ba9
3 changed files with 42 additions and 9 deletions
+39
View File
@@ -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();
+2 -9
View File
@@ -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>