feat: track duty email confirmations and add throttled account email tests
This commit is contained in:
Vendored
+8
-1
@@ -548,7 +548,7 @@ button:focus-visible, a:focus-visible, [tabindex]:focus-visible { outline: 3px s
|
||||
.code-row { gap: 6px; }
|
||||
.code-row .btn { padding-inline: 10px; }
|
||||
}
|
||||
.duty-banner { display: flex; align-items: center; justify-content: space-between; gap: 24px; padding: 20px 24px; margin-bottom: 24px; background: var(--primary-soft); border: 1px solid #d5e5da; border-radius: var(--radius); }
|
||||
.duty-banner { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 24px; padding: 20px 24px; margin-bottom: 24px; background: var(--primary-soft); border: 1px solid #d5e5da; border-radius: var(--radius); }
|
||||
.duty-info { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; min-width: 0; }
|
||||
.duty-label { display: inline-flex; align-items: center; gap: 7px; color: var(--primary); font-size: 13px; }
|
||||
.on-duty .duty-label::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--primary); }
|
||||
@@ -565,3 +565,10 @@ button:focus-visible, a:focus-visible, [tabindex]:focus-visible { outline: 3px s
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
*, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
|
||||
}
|
||||
|
||||
.duty-reminders { flex-basis: 100%; min-width: 0; }
|
||||
.duty-reminders:empty { display: none; }
|
||||
.duty-reminder-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding-top: 12px; margin-top: 4px; border-top: 1px solid #cbded1; }
|
||||
.duty-reminder-row > div { min-width: 0; overflow-wrap: anywhere; }
|
||||
.duty-reminder-row .muted { display: block; margin-top: 5px; }
|
||||
.duty-reminder-row .btn { flex: none; min-height: 40px; }
|
||||
|
||||
Vendored
+9
-2
@@ -5,7 +5,7 @@
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>WorkLog · 活动记录</title>
|
||||
<meta name="theme-color" content="#f5f7f5" />
|
||||
<link rel="stylesheet" href="/assets/styles.css?v=9" />
|
||||
<link rel="stylesheet" href="/assets/styles.css?v=10" />
|
||||
</head>
|
||||
<body>
|
||||
<div id="app">
|
||||
@@ -129,6 +129,7 @@
|
||||
<section id="duty-banner" class="duty-banner" aria-label="值班提示">
|
||||
<div class="duty-info" role="status"><span class="duty-label" id="duty-label">值班安排</span><strong id="duty-names">正在加载…</strong><span class="duty-time" id="duty-time"></span></div>
|
||||
<div class="duty-clock hidden" id="duty-clock"><span id="duty-countdown-label">本轮剩余</span><strong id="duty-countdown" role="timer" aria-live="off"></strong></div>
|
||||
<div id="duty-reminders" class="duty-reminders"></div>
|
||||
</section>
|
||||
<div id="feed-stats" class="stats-row"></div>
|
||||
<div id="feed-list" class="card-list"></div>
|
||||
@@ -222,6 +223,12 @@
|
||||
<label>绑定邮箱<div class="muted" id="pf-email" style="margin-top:4px"></div></label>
|
||||
<button class="btn primary" id="pf-save">保存资料</button>
|
||||
</div>
|
||||
<div class="card form-card">
|
||||
<h3>测试邮件连通性</h3>
|
||||
<p class="muted">向当前账号绑定的邮箱发送测试邮件,同一邮箱每 2 分钟可测试一次。</p>
|
||||
<button class="btn" id="pf-test-email" type="button">发送测试邮件</button>
|
||||
<p id="pf-test-email-status" class="muted" role="status"></p>
|
||||
</div>
|
||||
<div class="card form-card">
|
||||
<h3>登录方式</h3>
|
||||
<p class="muted">支持邮箱密码或邮箱验证码登录。忘记密码时可通过邮箱验证码重设;修改密码后,其他设备上的登录状态会退出。</p>
|
||||
@@ -246,7 +253,7 @@
|
||||
|
||||
<div id="toast" class="toast hidden" role="status" aria-live="polite"></div>
|
||||
|
||||
<script src="/js/app.js?v=15"></script>
|
||||
<script src="/js/app.js?v=16"></script>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Vendored
+39
@@ -526,6 +526,7 @@
|
||||
let dutySyncedAt = 0;
|
||||
let dutyRetryAt = 0;
|
||||
let dutyLoading = false;
|
||||
let dutyRemindersKey = "";
|
||||
const dutyDate = (ms, includeDate = false) => new Intl.DateTimeFormat("zh-CN", {
|
||||
timeZone: "Asia/Shanghai", ...(includeDate ? { month: "numeric", day: "numeric", weekday: "short" } : {}),
|
||||
hour: "2-digit", minute: "2-digit", hourCycle: "h23",
|
||||
@@ -540,6 +541,14 @@
|
||||
const shift = active ? current : next;
|
||||
const boundary = current ? current.end_at : next?.start_at;
|
||||
const expired = boundary && now >= boundary;
|
||||
const reminderKey = JSON.stringify(expired ? null : [shift?.start_at, shift?.reminders]);
|
||||
if (reminderKey !== dutyRemindersKey) {
|
||||
dutyRemindersKey = reminderKey;
|
||||
$("#duty-reminders").innerHTML = !shift || expired ? "" : (shift.reminders || []).map((r) => `
|
||||
<div class="duty-reminder-row"><div><b>${esc(r.name)}</b> <span class="tag ${r.confirmed_at ? 'attended' : 'full'}">${r.confirmed_at ? '已确认' : '未确认'}</span>
|
||||
<span class="muted">${r.last_sent_at ? `已提醒 ${dutyDate(r.last_sent_at, true)}` : '尚未成功发送'} · ${r.attempts}/3 次${r.confirmed_at ? ` · 确认于 ${dutyDate(r.confirmed_at, true)}` : ''}${r.matched ? '' : ' · 未匹配邮箱'}</span></div>
|
||||
${!r.confirmed_at ? `<button type="button" class="btn sm" data-duty-remind="${esc(r.name)}" data-start="${shift.start_at}" ${r.can_remind ? '' : 'disabled'}>${r.attempts >= 3 ? '已达3次上限' : '邮件提醒'}</button>` : ''}</div>`).join("");
|
||||
}
|
||||
$("#duty-banner").classList.toggle("on-duty", !!active);
|
||||
$("#duty-clock").classList.toggle("hidden", !shift || !!expired);
|
||||
if (expired) {
|
||||
@@ -574,6 +583,8 @@
|
||||
renderDutyStatus();
|
||||
} catch {
|
||||
dutySnapshot = null;
|
||||
dutyRemindersKey = "";
|
||||
$("#duty-reminders").innerHTML = "";
|
||||
$("#duty-banner").classList.remove("on-duty");
|
||||
$("#duty-label").textContent = "值班安排";
|
||||
$("#duty-names").textContent = "暂时无法加载";
|
||||
@@ -589,6 +600,34 @@
|
||||
else renderDutyStatus();
|
||||
}, 1000);
|
||||
document.addEventListener("visibilitychange", () => { if (!document.hidden) loadDutyStatus(); });
|
||||
$("#duty-reminders").addEventListener("click", async (event) => {
|
||||
const button = event.target.closest("[data-duty-remind]");
|
||||
if (!button || button.disabled) return;
|
||||
button.disabled = true;
|
||||
try {
|
||||
await api("/duty/remind", { method: "POST", body: { name: button.dataset.dutyRemind, start_at: Number(button.dataset.start) } });
|
||||
toast("值班提醒已发送");
|
||||
} catch (error) { toast(error.message, true); }
|
||||
finally { await loadDutyStatus(); }
|
||||
});
|
||||
|
||||
const testEmailCooldowns = new Map();
|
||||
function updateTestEmailButton() {
|
||||
const until = testEmailCooldowns.get(state.me?.email?.toLowerCase()) || 0;
|
||||
const left = Math.max(0, Math.ceil((until - Date.now()) / 1000));
|
||||
$("#pf-test-email").disabled = left > 0;
|
||||
$("#pf-test-email").textContent = left ? `${left} 秒后可再次测试` : "发送测试邮件";
|
||||
}
|
||||
$("#pf-test-email").addEventListener("click", async () => {
|
||||
testEmailCooldowns.set(state.me.email.toLowerCase(), Date.now() + 120000);
|
||||
updateTestEmailButton();
|
||||
$("#pf-test-email-status").textContent = "正在发送…";
|
||||
try {
|
||||
await api("/auth/test-email", { method: "POST" });
|
||||
$("#pf-test-email-status").textContent = "测试邮件已发送,请查看绑定邮箱及垃圾邮件文件夹。";
|
||||
} catch (error) { $("#pf-test-email-status").textContent = error.message; }
|
||||
});
|
||||
setInterval(updateTestEmailButton, 1000);
|
||||
|
||||
// ------------------------------------------------------------- 我的记录
|
||||
async function loadMine() {
|
||||
|
||||
Reference in New Issue
Block a user