update
This commit is contained in:
parent
f9fa280dee
commit
13ef520c9a
34
main.py
34
main.py
@ -1496,6 +1496,39 @@ HTML_TEMPLATE = """
|
||||
}
|
||||
}
|
||||
|
||||
// 为所有模态框添加统一的键盘快捷键支持(Enter 保存,ESC 关闭)
|
||||
function setupModalKeyboard() {
|
||||
document.addEventListener('keydown', function(event) {
|
||||
// 获取当前可见的模态框(display === 'flex')
|
||||
const visibleModal = document.querySelector('.modal[style*="display: flex"]');
|
||||
if (!visibleModal) return;
|
||||
|
||||
// 阻止事件冒泡,避免意外提交表单(如果有外层表单)
|
||||
if (event.key === 'Enter' || event.key === 'Escape') {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
}
|
||||
|
||||
if (event.key === 'Enter') {
|
||||
// 触发当前模态框内的保存按钮点击
|
||||
const saveBtn = visibleModal.querySelector('.btn-primary'); // 保存按钮通常使用 .btn-primary
|
||||
if (saveBtn && typeof saveBtn.onclick === 'function') {
|
||||
saveBtn.click();
|
||||
} else {
|
||||
// 兼容:通过 id 或特定类查找保存按钮(各模态框实际保存按钮是 .btn-primary)
|
||||
// 已有结构符合,无需额外处理
|
||||
}
|
||||
}
|
||||
else if (event.key === 'Escape') {
|
||||
// 触发当前模态框内的取消/关闭按钮点击
|
||||
const cancelBtn = visibleModal.querySelector('.modal-buttons .btn-outline');
|
||||
if (cancelBtn && typeof cancelBtn.onclick === 'function') {
|
||||
cancelBtn.click();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async function restoreLogin() {
|
||||
const stored = localStorage.getItem('score_user');
|
||||
if (!stored) return false;
|
||||
@ -1569,6 +1602,7 @@ HTML_TEMPLATE = """
|
||||
const loginHandler = function(e) { if(e.key === 'Enter') loginAsAdmin(); };
|
||||
if(adminPasswordInput) adminPasswordInput.addEventListener('keypress', loginHandler);
|
||||
if(adminUsernameInput) adminUsernameInput.addEventListener('keypress', loginHandler);
|
||||
setupModalKeyboard();
|
||||
}
|
||||
|
||||
async function loadTitles() { const res = await fetch('/api/settings/titles'); const data = await res.json(); document.getElementById('mainTitle').innerText = data.main_title; document.getElementById('subTitle').innerText = data.sub_title; }
|
||||
|
||||
Loading…
Reference in New Issue
Block a user