diff --git a/app/routers/web.py b/app/routers/web.py index e97328c..45c2f62 100644 --- a/app/routers/web.py +++ b/app/routers/web.py @@ -102,17 +102,20 @@ def root(user: User = Depends(get_current_user_web)): @router.get("/dashboard", response_class=HTMLResponse) def dashboard(request: Request, user: User = Depends(get_current_user_web), db: Session = Depends(get_db)): profiles = db.query(Profile).filter(Profile.user_id == user.id).all() - # stats per profile stats = {} + extras = {} for p in profiles: - cards = db.query(Postcard).filter(Postcard.profile_id == p.id).all() + cards = db.query(Postcard).filter(Postcard.profile_id == p.id).order_by(Postcard.created_at.desc()).all() stats[p.id] = { "total": len(cards), "sent": sum(1 for c in cards if c.status == "sent"), "delivered": sum(1 for c in cards if c.status == "delivered"), "received": sum(1 for c in cards if c.status == "received"), } - return templates.TemplateResponse("dashboard.html", {"request": request, "user": user, "profiles": profiles, "stats": stats}) + countries = sorted({c.country for c in cards if c.country}) + recent = cards[:3] + extras[p.id] = {"countries": countries, "recent": recent} + return templates.TemplateResponse("dashboard.html", {"request": request, "user": user, "profiles": profiles, "stats": stats, "extras": extras}) # ---------- Profiles ---------- diff --git a/app/static/style.css b/app/static/style.css index 180a2e1..581dd06 100644 --- a/app/static/style.css +++ b/app/static/style.css @@ -104,6 +104,11 @@ code { background: var(--bg); padding: .15rem .4rem; border-radius: 4px; font-si .dc-sent { color: var(--sent); } .dc-delivered { color: var(--delivered); } .dc-received { color: var(--received); } +.dc-tags { display: flex; flex-wrap: wrap; gap: .35rem; margin-top: .75rem; } +.dc-tag { display: inline-block; padding: .15rem .5rem; background: var(--bg); border: 1px solid var(--border); border-radius: 999px; font-size: .7rem; color: var(--text-muted); font-weight: 500; } +.dc-recent { display: flex; align-items: center; gap: .4rem; margin-top: .6rem; font-size: .75rem; color: var(--text-muted); } +.dc-recent-label { flex-shrink: 0; } +.dc-recent-item { padding: .1rem .4rem; background: var(--bg); border-radius: 4px; font-family: monospace; font-size: .7rem; } /* Postcard grid */ .postcard-card { display: flex; gap: 1rem; background: var(--card-bg); border: 1px solid var(--border); border-radius: 8px; padding: .75rem; transition: box-shadow .15s; } diff --git a/app/templates/dashboard.html b/app/templates/dashboard.html index 2b0a5f8..bf371e7 100644 --- a/app/templates/dashboard.html +++ b/app/templates/dashboard.html @@ -7,6 +7,7 @@ {% if profiles %}
{% for p in profiles %} + {% set ex = extras[p.id] %}
📮 @@ -30,6 +31,21 @@ 收到
+ {% if ex.countries %} +
+ {% for c in ex.countries %} + {{ c }} + {% endfor %} +
+ {% endif %} + {% if ex.recent %} +
+ 最近 + {% for c in ex.recent %} + {{ c.card_number }} + {% endfor %} +
+ {% endif %}
{% endfor %}