fix: 前端按钮防重复点击,避免重复请求(dnfs提交/删除、view刷新、验证码刷新)

This commit is contained in:
qing committed 2026-07-28 12:10:48 +08:00
1 parent 50f209e84a
commit bfd2d334fe
4 files changed
+30 -5

No files matched your search

+7
View File
@@ -155,6 +155,13 @@ button[type="button"], input[type="button"] { background: var(--accent-soft); co
flex-wrap: wrap; flex-wrap: wrap;
margin-top: 1.25rem; margin-top: 1.25rem;
} }
/* ===== 防重复点击:请求进行中按钮禁用态反馈 ===== */
button:disabled,
input[type="submit"]:disabled,
input[type="button"]:disabled {
opacity: 0.5;
cursor: not-allowed;
}
.form-check { .form-check {
display: flex; display: flex;
align-items: center; align-items: center;
+9 -4
View File
@@ -191,14 +191,15 @@ var minimap = document.getElementById("minimap");
var is_expand = true; var is_expand = true;
input_note_submit.addEventListener('click', function(event) { input_note_submit.addEventListener('click', function(event) {
if (input_note_submit.disabled) return; // 防重复点击
var title = input_note_title.value var title = input_note_title.value
var content = input_note_content.value var content = input_note_content.value
var pid = (stack.length == 0) ? 0 : stack[stack.length - 1]; var pid = (stack.length == 0) ? 0 : stack[stack.length - 1];
//alert(stack.length) //alert(stack.length)
//alert(pid) //alert(pid)
addNode(pid, title, content).then(result => { input_note_submit.disabled = true;
//alert(result.message); addNode(pid, title, content)
}) .finally(() => { input_note_submit.disabled = false; });
}) })
input_note_clear.addEventListener('click', function(event) { input_note_clear.addEventListener('click', function(event) {
@@ -207,13 +208,17 @@ input_note_clear.addEventListener('click', function(event) {
}) })
delete_note.addEventListener('click', (event) => { delete_note.addEventListener('click', (event) => {
if (delete_note.disabled) return; // 防重复点击
var id = (stack.length == 0) ? 0 : stack[stack.length - 1]; var id = (stack.length == 0) ? 0 : stack[stack.length - 1];
if (id == 0) { if (id == 0) {
alert('无法删除根节点'); alert('无法删除根节点');
console.log("节点未删除"); console.log("节点未删除");
} }
else { else {
deleteNode(id); delete_note.disabled = true;
// confirm 取消时 deleteNode 直接返回 undefined,统一用 Promise.resolve 兜底恢复按钮
Promise.resolve(deleteNode(id))
.finally(() => { delete_note.disabled = false; });
} }
}) })
+5
View File
@@ -14,8 +14,11 @@ const loginButton = document.getElementById('loginBtn');
/* ── 图形验证码(gateway 代理 captcha 服务:GET /captcha/image) ── */ /* ── 图形验证码(gateway 代理 captcha 服务:GET /captcha/image) ── */
let captchaToken = ''; let captchaToken = '';
let captchaLoading = false; // 防重复点击:加载中忽略再次触发
async function refreshCaptcha() { async function refreshCaptcha() {
if (captchaLoading) return;
captchaLoading = true;
captchaToken = ''; captchaToken = '';
try { try {
const res = await fetch('/captcha/image', { cache: 'no-store' }); const res = await fetch('/captcha/image', { cache: 'no-store' });
@@ -28,6 +31,8 @@ async function refreshCaptcha() {
} catch (e) { } catch (e) {
captchaImg.removeAttribute('src'); captchaImg.removeAttribute('src');
captchaImg.alt = '加载失败,点击重试'; captchaImg.alt = '加载失败,点击重试';
} finally {
captchaLoading = false;
} }
} }
captchaImg.addEventListener('click', refreshCaptcha); captchaImg.addEventListener('click', refreshCaptcha);
+9 -1
View File
@@ -127,7 +127,10 @@ function render() {
} }
// ===== 数据拉取(接口与参数与原版本一致) ===== // ===== 数据拉取(接口与参数与原版本一致) =====
let isLoading = false; // 防重复点击:请求进行中忽略再次触发
async function loadData() { async function loadData() {
if (isLoading) return;
isLoading = true;
loading.style.display = "block"; loading.style.display = "block";
fileList.innerHTML = ""; fileList.innerHTML = "";
empty.style.display = "none"; empty.style.display = "none";
@@ -145,6 +148,8 @@ async function loadData() {
} catch (e) { } catch (e) {
fileList.innerHTML = `<div class="error">❌ 加载失败: ${esc(e.message)}</div>`; fileList.innerHTML = `<div class="error">❌ 加载失败: ${esc(e.message)}</div>`;
loading.style.display = "none"; loading.style.display = "none";
} finally {
isLoading = false;
} }
} }
@@ -173,7 +178,10 @@ document.addEventListener("keydown", function (e) {
} }
}); });
btnRefresh.addEventListener("click", loadData); btnRefresh.addEventListener("click", function (e) {
e.preventDefault(); // <a href="#"> 默认会跳页顶,拦截
loadData();
});
// ===== 启动 ===== // ===== 启动 =====
renderBreadcrumb(); renderBreadcrumb();