From 61190328a4b24fe82b4c342bda1cacc8f9c6ec19 Mon Sep 17 00:00:00 2001 From: Zichao Lin Date: Sun, 5 Jul 2026 23:03:35 +0800 Subject: [PATCH] feat(dashboard): mobile 2-col stats, add relative time to recent activity --- app/routers/web.py | 3 +++ app/static/style.css | 5 +++-- app/templates/dashboard.html | 12 ++++++++++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/app/routers/web.py b/app/routers/web.py index e2ca411..d5ab954 100644 --- a/app/routers/web.py +++ b/app/routers/web.py @@ -171,11 +171,14 @@ def dashboard(request: Request, user: User = Depends(get_current_user_web), db: else: sent_pct = delivered_pct = received_pct = 0 + from datetime import datetime, timezone as _tz + return templates.TemplateResponse("dashboard.html", { "request": request, "user": user, "profiles": profiles, "total": total, "sent": sent, "delivered": delivered, "received": received, "countries": countries, "recent": recent, "sent_pct": sent_pct, "delivered_pct": delivered_pct, "received_pct": received_pct, + "now": datetime.now(_tz.utc), }) diff --git a/app/static/style.css b/app/static/style.css index 7131ca2..72265bd 100644 --- a/app/static/style.css +++ b/app/static/style.css @@ -229,10 +229,11 @@ code { background: var(--bg); padding: .15rem .4rem; border-radius: 4px; font-si .nav-links { gap: .75rem; } .nav-links a { font-size: .8rem; } .container { margin: 1rem auto; padding: 0 1rem; } - .dash-stats { flex-direction: column; } + .dash-stats { display: grid; grid-template-columns: 1fr 1fr; } .dash-stat-card { min-width: 0; } .dash-sections { grid-template-columns: 1fr; } - .recent-meta { display: none; } + .recent-meta > span:nth-child(-n+2) { display: none; } + .recent-meta .recent-time { display: inline; } .recent-item { gap: .5rem; padding: .5rem; } .section-header { flex-direction: column; gap: .75rem; } .section-header .btn { width: 100%; } diff --git a/app/templates/dashboard.html b/app/templates/dashboard.html index 7d03867..497a558 100644 --- a/app/templates/dashboard.html +++ b/app/templates/dashboard.html @@ -84,6 +84,18 @@ {% else %} ← {{ pc.sender_name or '-' }} {% endif %} + + {% if pc.status == 'sent' and pc.send_time %} + {% set delta = (now.date() - pc.send_time.date()).days %} + {% if delta == 0 %}今天{% elif delta == 1 %}昨天{% else %}{{ delta }}天前{% endif %} + {% elif pc.status == 'delivered' and pc.arrival_time %} + {% set delta = (now.date() - pc.arrival_time.date()).days %} + {% if delta == 0 %}今天{% elif delta == 1 %}昨天{% else %}{{ delta }}天前{% endif %} + {% elif pc.status == 'received' and pc.receive_time %} + {% set delta = (now.date() - pc.receive_time.date()).days %} + {% if delta == 0 %}今天{% elif delta == 1 %}昨天{% else %}{{ delta }}天前{% endif %} + {% endif %} + {% endfor %}