feat: senha dinamica (dia+mes) + confirm no limpar com try-catch
Build Fechamento de Caixa / build (macos-14, app) (push) Has been cancelled
Build Fechamento de Caixa / build (ubuntu-22.04, deb) (push) Has been cancelled
Build Fechamento de Caixa / build (windows-2022, msi) (push) Has been cancelled

This commit is contained in:
root
2026-07-02 15:37:06 +00:00
parent 8b24a06496
commit 7154901ce3
+19 -4
View File
@@ -543,7 +543,8 @@
<div class="cfg-section"> <div class="cfg-section">
<div class="cfg-section-title">🔐 Senha Admin (editar dias anteriores)</div> <div class="cfg-section-title">🔐 Senha Admin (editar dias anteriores)</div>
<div style="display:flex;gap:6px;margin-top:4px"> <div style="display:flex;gap:6px;margin-top:4px">
<input type="password" id="cfg-admin-password" style="flex:1;padding:6px;border:1px solid #ddd;border-radius:4px;font-size:13px" placeholder="Deixe em branco se não quiser senha"> <input type="password" id="cfg-admin-password" style="flex:1;padding:6px;border:1px solid #ddd;border-radius:4px;font-size:13px" placeholder="Senha fixa (ou deixe em branco)">
<input type="password" id="cfg-dynamic-password" style="flex:1;padding:6px;border:1px solid #ddd;border-radius:4px;font-size:13px" placeholder="Dinâmica: 10+dia+mes (ex: 1217)">
</div> </div>
</div> </div>
</div> </div>
@@ -1233,6 +1234,7 @@ function loadConfig() {
} }
function saveConfig() { function saveConfig() {
config.admin_password = document.getElementById('cfg-admin-password').value.trim(); config.admin_password = document.getElementById('cfg-admin-password').value.trim();
config.dynamic_password = document.getElementById('cfg-dynamic-password').value.trim();
try { localStorage.setItem(CFG_KEY, JSON.stringify(config)); } catch(e) {} try { localStorage.setItem(CFG_KEY, JSON.stringify(config)); } catch(e) {}
buildDatalists(); buildDatalists();
} }
@@ -1246,6 +1248,7 @@ function openConfig() {
renderCfgList('clientes', 'cfg-clientes-list'); renderCfgList('clientes', 'cfg-clientes-list');
renderCfgList('vales_nomes', 'cfg-vales-list'); renderCfgList('vales_nomes', 'cfg-vales-list');
document.getElementById('cfg-admin-password').value = config.admin_password || ''; document.getElementById('cfg-admin-password').value = config.admin_password || '';
document.getElementById('cfg-dynamic-password').value = config.dynamic_password || '';
} }
function closeConfig() { document.getElementById('modal-config').classList.remove('open'); } function closeConfig() { document.getElementById('modal-config').classList.remove('open'); }
function renderCfgList(key, containerId) { function renderCfgList(key, containerId) {
@@ -2102,7 +2105,9 @@ document.getElementById('btn-recibo').addEventListener('click', async () => {
}); });
document.getElementById('btn-limpar').addEventListener('click', () => { document.getElementById('btn-limpar').addEventListener('click', () => {
try {
if (!confirm('Tem certeza? Irá apagar todas as informações para iniciar uma nova.')) return; if (!confirm('Tem certeza? Irá apagar todas as informações para iniciar uma nova.')) return;
} catch(e) { return; }
localStorage.removeItem(LS_KEY); localStorage.removeItem(LS_KEY);
estado = { estado = {
uuid: crypto.randomUUID ? crypto.randomUUID() : Date.now().toString(), uuid: crypto.randomUUID ? crypto.randomUUID() : Date.now().toString(),
@@ -2645,16 +2650,26 @@ window.toggleEditConsulta = async function() {
closeRelatorioModal(); closeRelatorioModal();
}; };
// Pede senha admin — retorna Promise<boolean> // Calcula senha dinâmica do dia: dia e mês como 2 dígitos cada, concatenados
// ex: 17/12 → "1712"
function getDynamicPw() {
const d = new Date();
const day = String(d.getDate()).padStart(2, '0');
const month = String(d.getMonth() + 1).padStart(2, '0');
return day + month;
}
function askPassword() { function askPassword() {
return new Promise(resolve => { return new Promise(resolve => {
const pw = config.admin_password; const fixedPw = config.admin_password;
const dynPw = getDynamicPw();
const overlay = document.createElement('div'); const overlay = document.createElement('div');
overlay.style.cssText = 'position:fixed;top:0;left:0;right:0;bottom:0;background:rgba(0,0,0,0.5);z-index:999999;display:flex;align-items:center;justify-content:center;'; overlay.style.cssText = 'position:fixed;top:0;left:0;right:0;bottom:0;background:rgba(0,0,0,0.5);z-index:999999;display:flex;align-items:center;justify-content:center;';
overlay.id = 'pw-modal'; overlay.id = 'pw-modal';
overlay.innerHTML = ` overlay.innerHTML = `
<div style="background:#fff;border-radius:10px;padding:24px;width:300px;text-align:center"> <div style="background:#fff;border-radius:10px;padding:24px;width:300px;text-align:center">
<div style="font-size:18px;margin-bottom:16px">🔐 Senha Admin</div> <div style="font-size:18px;margin-bottom:16px">🔐 Senha Admin</div>
<div style="font-size:11px;color:#888;margin-bottom:12px">Dinâmica hoje: <strong>${getDynamicPw()}</strong></div>
<input type="password" id="pw-input" placeholder="Digite a senha..." style="width:100%;padding:10px;font-size:14px;border:1px solid #ccc;border-radius:6px;box-sizing:border-box;margin-bottom:12px" /> <input type="password" id="pw-input" placeholder="Digite a senha..." style="width:100%;padding:10px;font-size:14px;border:1px solid #ccc;border-radius:6px;box-sizing:border-box;margin-bottom:12px" />
<div id="pw-error" style="color:#c0272d;font-size:12px;margin-bottom:8px;display:none">Senha incorreta</div> <div id="pw-error" style="color:#c0272d;font-size:12px;margin-bottom:8px;display:none">Senha incorreta</div>
<div style="display:flex;gap:8px;justify-content:center"> <div style="display:flex;gap:8px;justify-content:center">
@@ -2673,7 +2688,7 @@ function askPassword() {
inp.addEventListener('keydown', e => { if (e.key === 'Enter') document.getElementById('pw-ok-btn').click(); }); inp.addEventListener('keydown', e => { if (e.key === 'Enter') document.getElementById('pw-ok-btn').click(); });
document.getElementById('pw-ok-btn').addEventListener('click', () => { document.getElementById('pw-ok-btn').addEventListener('click', () => {
const val = document.getElementById('pw-input').value; const val = document.getElementById('pw-input').value;
if (val === pw) { if (val === fixedPw || val === dynPw) {
document.getElementById('pw-modal').remove(); document.getElementById('pw-modal').remove();
resolve(true); resolve(true);
} else { } else {