feat: show current duty students and shift countdown on activity wall

This commit is contained in:
2026-11-06 14:19:16 +08:00
parent 12bcd4a62c
commit 867443163a
9 changed files with 175 additions and 7 deletions
+14
View File
@@ -548,6 +548,20 @@ 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-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); }
#duty-names { font-weight: 600; font-size: 17px; overflow-wrap: anywhere; }
.duty-time { width: 100%; color: var(--muted); font-size: 12px; }
.duty-clock { text-align: right; flex: none; border-left: 1px solid #cbded1; padding-left: 24px; }
.duty-clock > span { display: block; color: var(--muted); font-size: 12px; }
.duty-clock strong { display: block; font-size: 25px; font-weight: 600; font-variant-numeric: tabular-nums; letter-spacing: .5px; }
@media (max-width: 520px) {
.duty-banner { align-items: stretch; padding: 18px; gap: 16px; flex-direction: column; }
.duty-clock { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; text-align: left; padding: 12px 0 0; border-left: 0; border-top: 1px solid #cbded1; }
.duty-clock strong { font-size: 26px; }
}
@media (prefers-reduced-motion: reduce) {
*, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
+6 -2
View File
@@ -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=8" />
<link rel="stylesheet" href="/assets/styles.css?v=9" />
</head>
<body>
<div id="app">
@@ -126,6 +126,10 @@
<button class="btn" id="feed-refresh">刷新</button>
</div>
</div>
<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>
</section>
<div id="feed-stats" class="stats-row"></div>
<div id="feed-list" class="card-list"></div>
<div id="feed-empty" class="empty hidden">还没有活动记录,点右上角「+ 记录活动」创建第一条吧。</div>
@@ -242,7 +246,7 @@
<div id="toast" class="toast hidden" role="status" aria-live="polite"></div>
<script src="/js/app.js?v=14"></script>
<script src="/js/app.js?v=15"></script>
</div>
</body>
</html>
+71 -2
View File
@@ -134,7 +134,7 @@
if (a.dataset.view === view) a.setAttribute("aria-current", "page");
else a.removeAttribute("aria-current");
});
if (view === "feed") loadFeed();
if (view === "feed") { loadFeed(); loadDutyStatus(); }
if (view === "mine") loadMine();
if (view === "members") loadMembers();
if (view === "profile") fillProfile();
@@ -519,7 +519,76 @@
$("#feed-q").addEventListener("input", debounce(() => { state.feed.q = $("#feed-q").value.trim(); loadFeed(); }, 350));
$("#feed-dept").addEventListener("change", () => { state.feed.department = $("#feed-dept").value; loadFeed(); });
$("#feed-scope").addEventListener("change", () => { state.feed.scope = $("#feed-scope").value; loadFeed(); });
$("#feed-refresh").addEventListener("click", loadFeed);
$("#feed-refresh").addEventListener("click", () => { loadFeed(); loadDutyStatus(); });
// 倒计时以服务端时间和浏览器单调时钟计算,不依赖用户电脑校时。
let dutySnapshot = null;
let dutySyncedAt = 0;
let dutyRetryAt = 0;
let dutyLoading = false;
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",
}).format(ms);
function renderDutyStatus() {
if (!dutySnapshot) return;
const now = dutySnapshot.server_now + performance.now() - dutySyncedAt;
const current = dutySnapshot.current;
const next = dutySnapshot.next;
const active = current && now < current.end_at;
const shift = active ? current : next;
const boundary = current ? current.end_at : next?.start_at;
const expired = boundary && now >= boundary;
$("#duty-banner").classList.toggle("on-duty", !!active);
$("#duty-clock").classList.toggle("hidden", !shift || !!expired);
if (expired) {
$("#duty-label").textContent = "值班安排";
$("#duty-names").textContent = "正在更新…";
$("#duty-time").textContent = "";
} else if (shift) {
$("#duty-label").textContent = active ? "当前值班" : "下一轮值班";
$("#duty-names").textContent = shift.names.join("、");
$("#duty-time").textContent = `${active ? shift.slot : dutyDate(shift.start_at, true)} · ${active ? dutyDate(shift.start_at) + "–" + dutyDate(shift.end_at) : "开始"}(北京时间)`;
$("#duty-countdown-label").textContent = active ? "本轮剩余" : "距离开始";
const seconds = Math.max(0, Math.ceil(((active ? shift.end_at : shift.start_at) - now) / 1000));
const days = Math.floor(seconds / 86400);
const clock = [Math.floor(seconds / 3600) % 24, Math.floor(seconds / 60) % 60, seconds % 60].map((n) => String(n).padStart(2, "0")).join(":");
$("#duty-countdown").textContent = (days ? `${days}天 ` : "") + clock;
} else {
$("#duty-label").textContent = "值班安排";
$("#duty-names").textContent = dutySnapshot.enabled ? "暂无值班安排" : "值班安排已暂停";
$("#duty-time").textContent = "";
}
if ((expired || performance.now() - dutySyncedAt >= 60000) && performance.now() >= dutyRetryAt) loadDutyStatus();
}
async function loadDutyStatus() {
if (dutyLoading || !state.me || state.view !== "feed") return;
dutyLoading = true;
dutyRetryAt = performance.now() + 10000;
try {
const data = await api("/duty/current");
dutySnapshot = data;
dutySyncedAt = performance.now();
renderDutyStatus();
} catch {
dutySnapshot = null;
$("#duty-banner").classList.remove("on-duty");
$("#duty-label").textContent = "值班安排";
$("#duty-names").textContent = "暂时无法加载";
$("#duty-time").textContent = "稍后自动重试";
$("#duty-clock").classList.add("hidden");
} finally {
dutyLoading = false;
}
}
setInterval(() => {
if (state.view !== "feed" || document.hidden) return;
if (!dutySnapshot && performance.now() >= dutyRetryAt) loadDutyStatus();
else renderDutyStatus();
}, 1000);
document.addEventListener("visibilitychange", () => { if (!document.hidden) loadDutyStatus(); });
// ------------------------------------------------------------- 我的记录
async function loadMine() {