fix: 前端按钮防重复点击,避免重复请求(dnfs提交/删除、view刷新、验证码刷新)
This commit is contained in:
1 parent
50f209e84a
commit
bfd2d334fe
4 files changed
+30
-5
No files matched your search
@@ -155,6 +155,13 @@ button[type="button"], input[type="button"] { background: var(--accent-soft); co
|
||||
flex-wrap: wrap;
|
||||
margin-top: 1.25rem;
|
||||
}
|
||||
/* ===== 防重复点击:请求进行中按钮禁用态反馈 ===== */
|
||||
button:disabled,
|
||||
input[type="submit"]:disabled,
|
||||
input[type="button"]:disabled {
|
||||
opacity: 0.5;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
.form-check {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
|
||||
@@ -191,14 +191,15 @@ var minimap = document.getElementById("minimap");
|
||||
var is_expand = true;
|
||||
|
||||
input_note_submit.addEventListener('click', function(event) {
|
||||
if (input_note_submit.disabled) return; // 防重复点击
|
||||
var title = input_note_title.value
|
||||
var content = input_note_content.value
|
||||
var pid = (stack.length == 0) ? 0 : stack[stack.length - 1];
|
||||
//alert(stack.length)
|
||||
//alert(pid)
|
||||
addNode(pid, title, content).then(result => {
|
||||
//alert(result.message);
|
||||
})
|
||||
input_note_submit.disabled = true;
|
||||
addNode(pid, title, content)
|
||||
.finally(() => { input_note_submit.disabled = false; });
|
||||
})
|
||||
|
||||
input_note_clear.addEventListener('click', function(event) {
|
||||
@@ -207,13 +208,17 @@ input_note_clear.addEventListener('click', function(event) {
|
||||
})
|
||||
|
||||
delete_note.addEventListener('click', (event) => {
|
||||
if (delete_note.disabled) return; // 防重复点击
|
||||
var id = (stack.length == 0) ? 0 : stack[stack.length - 1];
|
||||
if (id == 0) {
|
||||
alert('无法删除根节点');
|
||||
console.log("节点未删除");
|
||||
}
|
||||
else {
|
||||
deleteNode(id);
|
||||
delete_note.disabled = true;
|
||||
// confirm 取消时 deleteNode 直接返回 undefined,统一用 Promise.resolve 兜底恢复按钮
|
||||
Promise.resolve(deleteNode(id))
|
||||
.finally(() => { delete_note.disabled = false; });
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
@@ -14,8 +14,11 @@ const loginButton = document.getElementById('loginBtn');
|
||||
|
||||
/* ── 图形验证码(gateway 代理 captcha 服务:GET /captcha/image) ── */
|
||||
let captchaToken = '';
|
||||
let captchaLoading = false; // 防重复点击:加载中忽略再次触发
|
||||
|
||||
async function refreshCaptcha() {
|
||||
if (captchaLoading) return;
|
||||
captchaLoading = true;
|
||||
captchaToken = '';
|
||||
try {
|
||||
const res = await fetch('/captcha/image', { cache: 'no-store' });
|
||||
@@ -28,6 +31,8 @@ async function refreshCaptcha() {
|
||||
} catch (e) {
|
||||
captchaImg.removeAttribute('src');
|
||||
captchaImg.alt = '加载失败,点击重试';
|
||||
} finally {
|
||||
captchaLoading = false;
|
||||
}
|
||||
}
|
||||
captchaImg.addEventListener('click', refreshCaptcha);
|
||||
|
||||
@@ -127,7 +127,10 @@ function render() {
|
||||
}
|
||||
|
||||
// ===== 数据拉取(接口与参数与原版本一致) =====
|
||||
let isLoading = false; // 防重复点击:请求进行中忽略再次触发
|
||||
async function loadData() {
|
||||
if (isLoading) return;
|
||||
isLoading = true;
|
||||
loading.style.display = "block";
|
||||
fileList.innerHTML = "";
|
||||
empty.style.display = "none";
|
||||
@@ -145,6 +148,8 @@ async function loadData() {
|
||||
} catch (e) {
|
||||
fileList.innerHTML = `<div class="error">❌ 加载失败: ${esc(e.message)}</div>`;
|
||||
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();
|
||||
|
||||
Reference in new issue
Block a user