diff --git a/app/routers/web.py b/app/routers/web.py index 24bb6fb..95a45b8 100644 --- a/app/routers/web.py +++ b/app/routers/web.py @@ -397,6 +397,13 @@ def dashboard(request: Request, user: User = Depends(get_current_user_web), db: else: sent_pct = delivered_pct = received_pct = 0 + # country stats + country_counts: dict[str, int] = {} + for c in all_cards: + if c.country: + country_counts[c.country] = country_counts.get(c.country, 0) + 1 + country_stats = sorted(country_counts.items(), key=lambda x: -x[1]) + from datetime import datetime, timezone as _tz return templates.TemplateResponse("dashboard.html", { @@ -404,6 +411,7 @@ def dashboard(request: Request, user: User = Depends(get_current_user_web), db: "total": total, "sent": sent, "delivered": delivered, "received": received, "countries": countries, "recent": recent, "sent_pct": sent_pct, "delivered_pct": delivered_pct, "received_pct": received_pct, + "country_stats": country_stats, "now": datetime.now(_tz.utc), }) diff --git a/app/templates/dashboard.html b/app/templates/dashboard.html index 91c93d8..0bd3476 100644 --- a/app/templates/dashboard.html +++ b/app/templates/dashboard.html @@ -59,6 +59,13 @@ {% endif %} +{% if country_stats %} +
+

🌍 国家/地区分布

+ +
+{% endif %} +

最近动态

@@ -129,4 +136,29 @@

创建一个 Profile 开始管理你的明信片

{% endif %} +{% if country_stats %} + + +{% endif %} {% endblock %}