Files
mailova/app/templates/dashboard.html

163 lines
6.3 KiB
HTML

{% extends "base.html" %}
{% block title %}总览 - 星笺{% endblock %}
{% block content %}
<div class="section-header">
<h1>👋 欢迎,{{ user.username }}</h1>
</div>
{% if profiles %}
<div class="dash-stats">
<div class="dash-stat-card">
<div class="dash-stat-icon">📮</div>
<div class="dash-stat-body">
<span class="dash-stat-value">{{ total }}</span>
<span class="dash-stat-label">全部明信片</span>
</div>
</div>
<div class="dash-stat-card">
<div class="dash-stat-icon">📤</div>
<div class="dash-stat-body">
<span class="dash-stat-value dash-sent">{{ sent }}</span>
<span class="dash-stat-label">已寄出</span>
</div>
</div>
<div class="dash-stat-card">
<div class="dash-stat-icon">📬</div>
<div class="dash-stat-body">
<span class="dash-stat-value dash-delivered">{{ delivered }}</span>
<span class="dash-stat-label">已送达</span>
</div>
</div>
<div class="dash-stat-card">
<div class="dash-stat-icon">💌</div>
<div class="dash-stat-body">
<span class="dash-stat-value dash-received">{{ received }}</span>
<span class="dash-stat-label">已收到</span>
</div>
</div>
<div class="dash-stat-card">
<div class="dash-stat-icon">🌍</div>
<div class="dash-stat-body">
<span class="dash-stat-value">{{ countries }}</span>
<span class="dash-stat-label">国家/地区</span>
</div>
</div>
</div>
{% if total > 0 %}
<div class="dash-progress">
<div class="progress-bar">
<div class="progress-seg progress-sent" style="width:{{ sent_pct }}%"></div>
<div class="progress-seg progress-delivered" style="width:{{ delivered_pct }}%"></div>
<div class="progress-seg progress-received" style="width:{{ received_pct }}%"></div>
</div>
<div class="progress-legend">
<span><i class="dot dot-sent"></i>已寄出 {{ sent_pct }}%</span>
<span><i class="dot dot-delivered"></i>已送达 {{ delivered_pct }}%</span>
<span><i class="dot dot-received"></i>已收到 {{ received_pct }}%</span>
</div>
</div>
{% endif %}
{% if country_stats %}
<script src="https://cdn.jsdelivr.net/npm/chart.js@4"></script>
<div style="background:var(--card-bg);border:1px solid var(--border);border-radius:10px;padding:1.25rem;margin-bottom:1.5rem">
<h2 style="margin-bottom:.75rem">🌍 国家/地区分布</h2>
<canvas id="country-chart" height="100"></canvas>
</div>
<script>
new Chart(document.getElementById('country-chart'), {
type: 'bar',
data: {
labels: [{% for code, _ in country_stats %}'{{ code|flag }} {{ code }}',{% endfor %}],
datasets: [{
data: [{% for _, count in country_stats %}{{ count }},{% endfor %}],
backgroundColor: '#3b82f6',
borderRadius: 4,
maxBarThickness: 40
}]
},
options: {
responsive: true,
plugins: { legend: { display: false } },
scales: {
y: { beginAtZero: true, ticks: { stepSize: 1 } },
x: { grid: { display: false } }
}
}
});
</script>
{% endif %}
<div class="dash-sections">
<div class="dash-section">
<h2>最近动态</h2>
{% if recent %}
<div class="recent-list">
{% for pc in recent %}
<a href="/postcards/{{ pc.id }}" class="recent-item">
<div class="recent-img">
{% if pc.image_front %}
<img src="{{ pc.image_front }}" alt="" loading="lazy">
{% else %}
<span>📷</span>
{% endif %}
</div>
<div class="recent-info">
<strong>{{ pc.card_number }}</strong>
<span class="badge badge-{{ pc.status }}">{{ {'sent':'已寄出','delivered':'已送达','received':'已收到'}.get(pc.status) }}</span>
</div>
<div class="recent-meta">
{% if pc.status in ('sent','delivered') %}
<span>{{ pc.country|flag }} {{ pc.country or '' }}</span>
<span>→ {{ pc.recipient_name or '-' }}</span>
{% else %}
<span>← {{ pc.sender_name or '-' }}</span>
{% endif %}
<span class="recent-time">
{% 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 %}
</span>
</div>
</a>
{% endfor %}
</div>
{% else %}
<p class="empty">暂无明信片</p>
{% endif %}
</div>
<div class="dash-section">
<h2>Profile</h2>
<div class="dash-profiles">
{% for p in profiles %}
<a href="/profiles/{{ p.id }}/postcards" class="dash-profile-link">
<span class="dash-profile-name">{{ p.nickname }}</span>
<span class="dash-profile-arrow"></span>
</a>
{% endfor %}
<a href="/profiles" class="dash-profile-link dash-profile-more">
<span class="dash-profile-name">管理全部</span>
<span class="dash-profile-arrow"></span>
</a>
</div>
</div>
</div>
{% else %}
<div class="empty-state">
<div class="empty-icon">📮</div>
<p>欢迎使用星笺!</p>
<p class="empty-sub">创建一个 <a href="/profiles">Profile</a> 开始管理你的明信片</p>
</div>
{% endif %}
{% endblock %}