diff --git a/internal/web/static/app.js b/internal/web/static/app.js index ac03c1d..27b31f8 100644 --- a/internal/web/static/app.js +++ b/internal/web/static/app.js @@ -145,12 +145,33 @@ } if (clocks.length) { tick(); setInterval(tick, 1000); } - /* 小键盘:输入手机尾号 */ + /* 小键盘:输入手机尾号 + 关键点:鼠标按下时阻止默认行为,否则按钮会先抢走输入框焦点; + 每次按键后再把焦点和光标送回输入框末尾。 */ Array.prototype.forEach.call(document.querySelectorAll('[data-keypad]'), function (pad) { - var form = pad.closest('form'); - if (!form) return; - var input = form.querySelector('input[name="tail"]'); - if (!input) return; + // 键盘是表单的兄弟节点(不在
内),所以先找输入框,再用 input.form 反查表单 + var scope = pad.closest('.drawer-block') || pad.parentElement || document; + var input = scope.querySelector('input[name="tail"]'); + if (!input) { return; } + var form = input.form; + if (!form) { return; } + + function keepFocus() { + try { input.focus({ preventScroll: true }); } catch (err) { input.focus(); } + var end = input.value.length; + try { input.setSelectionRange(end, end); } catch (err) { /* number 类型时忽略 */ } + } + + // mousedown 会触发“按钮获得焦点”,先拦下来;pointerdown 再兜底一次 + pad.addEventListener('mousedown', function (e) { + e.preventDefault(); + keepFocus(); + }); + pad.addEventListener('pointerdown', function () { + // 这里不能 preventDefault:会连带取消后面的 click 事件 + keepFocus(); + }); + pad.addEventListener('click', function (e) { var btn = e.target.closest('button[data-key]'); if (!btn) return; @@ -161,10 +182,11 @@ if (input.value) { if (form.requestSubmit) { form.requestSubmit(); } else { form.submit(); } } - } else { - if (input.value.length < 8) { input.value += key; } + return; + } else if (input.value.length < 8) { + input.value += key; } - input.focus(); + keepFocus(); }); }); diff --git a/main.go b/main.go index 1bf049e..8c78e7b 100644 --- a/main.go +++ b/main.go @@ -26,7 +26,7 @@ import ( "daili/internal/web" ) -const version = "1.6.0" +const version = "1.6.1" func main() { cfgFlag := flag.String("config", "", "配置文件路径(默认:exe 同级的 "+config.FileName+")")