前后端数据流对齐:
后端改动:
GET /api/v1/accounts 现在返回分页格式 {items, total, page, size, total_pages, status_counts},默认每页 12 个
批量操作用 size=500 一次拉全部
前端改动:
base.html — 加了移动端汉堡菜单、全局响应式样式、pagination disabled 状态
dashboard.html — 账号卡片分页,统计数据从 API 的 status_counts 取,移动端单列布局
account_detail.html — 签到记录改成上下两行布局(topic+状态 / 消息+时间),分页用统一的上一页/下一页样式,移动端适配
分页逻辑统一:前后端都用 page/total_pages 字段,pagination 组件显示当前页 ±2 页码。
This commit is contained in:
@@ -4,200 +4,113 @@
|
||||
|
||||
{% block extra_css %}
|
||||
<style>
|
||||
.dash-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 28px;
|
||||
}
|
||||
.dash-header h1 {
|
||||
font-size: 26px;
|
||||
font-weight: 700;
|
||||
color: #1e293b;
|
||||
}
|
||||
.dash-actions { display: flex; gap: 10px; }
|
||||
|
||||
/* 统计卡片 */
|
||||
.stats-row {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
|
||||
gap: 16px;
|
||||
margin-bottom: 28px;
|
||||
}
|
||||
.dash-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
|
||||
.dash-header h1 { font-size: 22px; font-weight: 700; color: #1e293b; }
|
||||
.stats-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 20px; }
|
||||
.stat-card {
|
||||
background: rgba(255,255,255,0.9);
|
||||
backdrop-filter: blur(8px);
|
||||
border-radius: 20px;
|
||||
padding: 22px 24px;
|
||||
border: 1px solid rgba(255,255,255,0.6);
|
||||
box-shadow: 0 1px 3px rgba(0,0,0,0.04), 0 4px 16px rgba(0,0,0,0.04);
|
||||
}
|
||||
.stat-card .stat-icon { font-size: 28px; margin-bottom: 8px; }
|
||||
.stat-card .stat-value { font-size: 28px; font-weight: 700; color: #1e293b; }
|
||||
.stat-card .stat-label { font-size: 13px; color: #94a3b8; font-weight: 500; margin-top: 2px; }
|
||||
|
||||
/* 账号卡片网格 */
|
||||
.account-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
|
||||
gap: 18px;
|
||||
background: rgba(255,255,255,0.9); backdrop-filter: blur(8px);
|
||||
border-radius: 16px; padding: 16px; border: 1px solid rgba(255,255,255,0.6);
|
||||
box-shadow: 0 1px 3px rgba(0,0,0,0.04);
|
||||
}
|
||||
.stat-card .stat-icon { font-size: 22px; margin-bottom: 4px; }
|
||||
.stat-card .stat-value { font-size: 24px; font-weight: 700; color: #1e293b; }
|
||||
.stat-card .stat-label { font-size: 12px; color: #94a3b8; font-weight: 500; }
|
||||
.account-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
|
||||
.account-card {
|
||||
background: rgba(255,255,255,0.92);
|
||||
backdrop-filter: blur(8px);
|
||||
border-radius: 20px;
|
||||
padding: 24px;
|
||||
border: 1px solid rgba(255,255,255,0.6);
|
||||
box-shadow: 0 1px 3px rgba(0,0,0,0.04), 0 4px 16px rgba(0,0,0,0.04);
|
||||
cursor: pointer;
|
||||
transition: all 0.25s ease;
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
}
|
||||
.account-card::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
top: 0; left: 0; right: 0;
|
||||
height: 4px;
|
||||
border-radius: 20px 20px 0 0;
|
||||
background: rgba(255,255,255,0.92); backdrop-filter: blur(8px);
|
||||
border-radius: 16px; padding: 18px; border: 1px solid rgba(255,255,255,0.6);
|
||||
box-shadow: 0 1px 3px rgba(0,0,0,0.04); cursor: pointer;
|
||||
transition: all 0.2s; position: relative; overflow: hidden;
|
||||
}
|
||||
.account-card::before { content: ''; position: absolute; top: 0; left: 0; right: 0; height: 3px; border-radius: 16px 16px 0 0; }
|
||||
.account-card.status-active::before { background: linear-gradient(90deg, #10b981, #34d399); }
|
||||
.account-card.status-pending::before { background: linear-gradient(90deg, #f59e0b, #fbbf24); }
|
||||
.account-card.status-invalid_cookie::before { background: linear-gradient(90deg, #ef4444, #f87171); }
|
||||
.account-card.status-banned::before { background: linear-gradient(90deg, #6b7280, #9ca3af); }
|
||||
|
||||
.account-card:hover {
|
||||
transform: translateY(-4px);
|
||||
box-shadow: 0 8px 30px rgba(99,102,241,0.12);
|
||||
}
|
||||
.account-card-top {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: flex-start;
|
||||
margin-bottom: 14px;
|
||||
}
|
||||
.account-card:hover { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(99,102,241,0.1); }
|
||||
.account-card-top { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 10px; }
|
||||
.account-avatar {
|
||||
width: 48px; height: 48px;
|
||||
border-radius: 16px;
|
||||
width: 40px; height: 40px; border-radius: 12px;
|
||||
background: linear-gradient(135deg, #6366f1, #a855f7);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
color: white;
|
||||
font-size: 20px;
|
||||
font-weight: 700;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.account-name {
|
||||
font-size: 16px;
|
||||
font-weight: 700;
|
||||
color: #1e293b;
|
||||
margin-bottom: 4px;
|
||||
word-break: break-all;
|
||||
}
|
||||
.account-remark {
|
||||
font-size: 13px;
|
||||
color: #94a3b8;
|
||||
margin-bottom: 14px;
|
||||
display: flex; align-items: center; justify-content: center;
|
||||
color: white; font-size: 16px; font-weight: 700; flex-shrink: 0;
|
||||
}
|
||||
.account-name { font-size: 15px; font-weight: 700; color: #1e293b; word-break: break-all; }
|
||||
.account-remark { font-size: 12px; color: #94a3b8; margin-top: 2px; }
|
||||
.account-meta {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding-top: 14px;
|
||||
border-top: 1px solid #f1f5f9;
|
||||
display: flex; justify-content: space-between; align-items: center;
|
||||
padding-top: 10px; border-top: 1px solid #f1f5f9;
|
||||
}
|
||||
.account-date { font-size: 12px; color: #cbd5e1; }
|
||||
|
||||
/* 删除按钮 */
|
||||
.account-date { font-size: 11px; color: #cbd5e1; }
|
||||
.account-del-btn {
|
||||
width: 32px; height: 32px;
|
||||
border-radius: 10px;
|
||||
border: 1.5px solid #fecaca;
|
||||
background: #fff;
|
||||
color: #ef4444;
|
||||
font-size: 14px;
|
||||
cursor: pointer;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
transition: all 0.2s;
|
||||
flex-shrink: 0;
|
||||
width: 28px; height: 28px; border-radius: 8px; border: 1.5px solid #fecaca;
|
||||
background: #fff; color: #ef4444; font-size: 12px; cursor: pointer;
|
||||
display: flex; align-items: center; justify-content: center;
|
||||
}
|
||||
.account-del-btn:hover {
|
||||
background: #fef2f2;
|
||||
border-color: #f87171;
|
||||
.account-del-btn:hover { background: #fef2f2; }
|
||||
.batch-bar {
|
||||
background: rgba(255,255,255,0.9); border-radius: 14px; padding: 12px 16px;
|
||||
margin-bottom: 14px; border: 1px solid rgba(255,255,255,0.6);
|
||||
display: flex; justify-content: space-between; align-items: center; gap: 10px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
/* 空状态 */
|
||||
.batch-bar .info { font-size: 13px; color: #64748b; }
|
||||
.empty-state {
|
||||
text-align: center;
|
||||
padding: 80px 20px;
|
||||
background: rgba(255,255,255,0.7);
|
||||
border-radius: 24px;
|
||||
border: 2px dashed #e2e8f0;
|
||||
text-align: center; padding: 60px 20px; background: rgba(255,255,255,0.7);
|
||||
border-radius: 20px; border: 2px dashed #e2e8f0;
|
||||
}
|
||||
.empty-state .empty-icon { font-size: 56px; margin-bottom: 16px; }
|
||||
.empty-state p { color: #94a3b8; margin-bottom: 24px; font-size: 16px; }
|
||||
|
||||
/* Cookie 批量验证 */
|
||||
.batch-verify-bar {
|
||||
background: rgba(255,255,255,0.9);
|
||||
backdrop-filter: blur(8px);
|
||||
border-radius: 20px;
|
||||
padding: 16px 24px;
|
||||
margin-bottom: 20px;
|
||||
border: 1px solid rgba(255,255,255,0.6);
|
||||
box-shadow: 0 1px 3px rgba(0,0,0,0.04);
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
.empty-state .empty-icon { font-size: 48px; margin-bottom: 12px; }
|
||||
.empty-state p { color: #94a3b8; margin-bottom: 20px; font-size: 15px; }
|
||||
@media (max-width: 768px) {
|
||||
.stats-row { grid-template-columns: repeat(3, 1fr); gap: 8px; }
|
||||
.stat-card { padding: 12px; }
|
||||
.stat-card .stat-value { font-size: 20px; }
|
||||
.stat-card .stat-label { font-size: 11px; }
|
||||
.account-grid { grid-template-columns: 1fr; }
|
||||
.batch-bar { flex-direction: column; align-items: stretch; text-align: center; }
|
||||
.batch-bar .info { margin-bottom: 8px; }
|
||||
.dash-header { flex-direction: column; gap: 10px; align-items: flex-start; }
|
||||
}
|
||||
.batch-verify-bar .info { font-size: 14px; color: #64748b; }
|
||||
.batch-verify-bar .info strong { color: #1e293b; }
|
||||
</style>
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="dash-header">
|
||||
<h1>👋 控制台</h1>
|
||||
<div class="dash-actions">
|
||||
<a href="{{ url_for('add_account') }}" class="btn btn-primary">+ 添加账号</a>
|
||||
</div>
|
||||
<a href="{{ url_for('add_account') }}" class="btn btn-primary">+ 添加账号</a>
|
||||
</div>
|
||||
|
||||
{% if accounts %}
|
||||
<!-- 统计概览 -->
|
||||
{% set sc = pagination.get('status_counts', {}) %}
|
||||
{% set total_accounts = pagination.get('total', 0) %}
|
||||
{% set active_count = sc.get('active', 0) %}
|
||||
{% set need_attention = sc.get('pending', 0) + sc.get('invalid_cookie', 0) %}
|
||||
|
||||
{% if total_accounts > 0 %}
|
||||
<div class="stats-row">
|
||||
<div class="stat-card">
|
||||
<div class="stat-icon">📊</div>
|
||||
<div class="stat-value">{{ accounts|length }}</div>
|
||||
<div class="stat-value">{{ total_accounts }}</div>
|
||||
<div class="stat-label">账号总数</div>
|
||||
</div>
|
||||
<div class="stat-card">
|
||||
<div class="stat-icon">✅</div>
|
||||
<div class="stat-value">{{ accounts|selectattr('status','equalto','active')|list|length }}</div>
|
||||
<div class="stat-value">{{ active_count }}</div>
|
||||
<div class="stat-label">正常运行</div>
|
||||
</div>
|
||||
<div class="stat-card">
|
||||
<div class="stat-icon">⚠️</div>
|
||||
<div class="stat-value">{{ accounts|selectattr('status','equalto','pending')|list|length + accounts|selectattr('status','equalto','invalid_cookie')|list|length }}</div>
|
||||
<div class="stat-value">{{ need_attention }}</div>
|
||||
<div class="stat-label">需要关注</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 批量操作栏 -->
|
||||
<div class="batch-verify-bar">
|
||||
<div class="info">
|
||||
💡 系统每天 <strong>23:50</strong> 自动批量验证 Cookie,也可手动触发
|
||||
</div>
|
||||
<div style="display:flex; gap:10px;">
|
||||
<button class="btn btn-secondary" id="batch-verify-btn" onclick="batchVerify()">🔍 批量验证 Cookie</button>
|
||||
<div class="batch-bar">
|
||||
<div class="info">💡 可手动触发批量操作</div>
|
||||
<div style="display:flex; gap:8px; flex-wrap:wrap;">
|
||||
<button class="btn btn-secondary" id="batch-verify-btn" onclick="batchVerify()">🔍 批量验证</button>
|
||||
<button class="btn btn-primary" id="batch-signin-btn" onclick="batchSignin()">🚀 全部签到</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 账号卡片 -->
|
||||
<div class="account-grid">
|
||||
{% for account in accounts %}
|
||||
<div class="account-card status-{{ account.status }}" onclick="window.location.href='{{ url_for('account_detail', account_id=account.id) }}'">
|
||||
@@ -210,87 +123,88 @@
|
||||
</div>
|
||||
<div class="account-meta">
|
||||
<div>
|
||||
{% if account.status == 'active' %}
|
||||
<span class="badge badge-success">正常</span>
|
||||
{% elif account.status == 'pending' %}
|
||||
<span class="badge badge-warning">待验证</span>
|
||||
{% elif account.status == 'invalid_cookie' %}
|
||||
<span class="badge badge-danger">Cookie 失效</span>
|
||||
{% elif account.status == 'banned' %}
|
||||
<span class="badge badge-danger">已封禁</span>
|
||||
{% if account.status == 'active' %}<span class="badge badge-success">正常</span>
|
||||
{% elif account.status == 'pending' %}<span class="badge badge-warning">待验证</span>
|
||||
{% elif account.status == 'invalid_cookie' %}<span class="badge badge-danger">Cookie 失效</span>
|
||||
{% elif account.status == 'banned' %}<span class="badge badge-danger">已封禁</span>
|
||||
{% endif %}
|
||||
</div>
|
||||
<div style="display:flex; align-items:center; gap:10px;">
|
||||
<div style="display:flex; align-items:center; gap:8px;">
|
||||
<span class="account-date">{{ account.created_at[:10] }}</span>
|
||||
<button class="account-del-btn" title="删除账号" onclick="event.stopPropagation(); deleteAccount('{{ account.id }}', '{{ account.remark or account.weibo_user_id }}');">🗑</button>
|
||||
<button class="account-del-btn" title="删除" onclick="event.stopPropagation(); deleteAccount('{{ account.id }}', '{{ account.remark or account.weibo_user_id }}');">🗑</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
||||
{% if pagination.get('total_pages', 0) > 1 %}
|
||||
<div class="pagination">
|
||||
{% set p = pagination.page %}
|
||||
{% set tp = pagination.total_pages %}
|
||||
{% if p > 1 %}
|
||||
<a href="?page={{ p - 1 }}">‹ 上一页</a>
|
||||
{% else %}
|
||||
<span class="disabled">‹ 上一页</span>
|
||||
{% endif %}
|
||||
|
||||
{% for i in range(max(1, p - 2), min(tp, p + 2) + 1) %}
|
||||
{% if i == p %}<span class="active">{{ i }}</span>
|
||||
{% else %}<a href="?page={{ i }}">{{ i }}</a>{% endif %}
|
||||
{% endfor %}
|
||||
|
||||
{% if p < tp %}
|
||||
<a href="?page={{ p + 1 }}">下一页 ›</a>
|
||||
{% else %}
|
||||
<span class="disabled">下一页 ›</span>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% else %}
|
||||
<div class="empty-state">
|
||||
<div class="empty-icon">📱</div>
|
||||
<p>暂无账号,扫码添加你的微博账号开始自动签到</p>
|
||||
<a href="{{ url_for('add_account') }}" class="btn btn-primary" style="font-size:16px; padding:14px 32px;">添加第一个账号</a>
|
||||
<a href="{{ url_for('add_account') }}" class="btn btn-primary" style="padding:12px 28px;">添加第一个账号</a>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<script>
|
||||
async function deleteAccount(accountId, name) {
|
||||
if (!confirm(`确定要删除账号「${name}」吗?此操作不可恢复。`)) return;
|
||||
try {
|
||||
const form = document.createElement('form');
|
||||
form.method = 'POST';
|
||||
form.action = `/accounts/${accountId}/delete`;
|
||||
document.body.appendChild(form);
|
||||
form.submit();
|
||||
} catch(e) {
|
||||
alert('删除失败: ' + e.message);
|
||||
}
|
||||
async function deleteAccount(id, name) {
|
||||
if (!confirm(`确定要删除账号「${name}」吗?`)) return;
|
||||
const form = document.createElement('form');
|
||||
form.method = 'POST';
|
||||
form.action = `/accounts/${id}/delete`;
|
||||
document.body.appendChild(form);
|
||||
form.submit();
|
||||
}
|
||||
|
||||
async function batchVerify() {
|
||||
const btn = document.getElementById('batch-verify-btn');
|
||||
btn.disabled = true;
|
||||
btn.textContent = '⏳ 验证中...';
|
||||
btn.disabled = true; btn.textContent = '⏳ 验证中...';
|
||||
try {
|
||||
const resp = await fetch('/api/batch/verify', {method: 'POST'});
|
||||
const data = await resp.json();
|
||||
if (data.success) {
|
||||
const r = data.data;
|
||||
alert(`验证完成:${r.valid} 个有效,${r.invalid} 个失效,${r.errors} 个出错`);
|
||||
} else {
|
||||
alert('验证失败: ' + (data.message || '未知错误'));
|
||||
}
|
||||
} catch(e) {
|
||||
alert('请求失败: ' + e.message);
|
||||
}
|
||||
btn.disabled = false;
|
||||
btn.textContent = '🔍 批量验证 Cookie';
|
||||
alert(`验证完成:${r.valid} 有效,${r.invalid} 失效,${r.errors} 出错`);
|
||||
} else { alert('验证失败: ' + (data.message || '未知错误')); }
|
||||
} catch(e) { alert('请求失败: ' + e.message); }
|
||||
btn.disabled = false; btn.textContent = '🔍 批量验证';
|
||||
location.reload();
|
||||
}
|
||||
|
||||
async function batchSignin() {
|
||||
const btn = document.getElementById('batch-signin-btn');
|
||||
if (!confirm('确定要对所有正常账号执行签到吗?')) return;
|
||||
btn.disabled = true;
|
||||
btn.textContent = '⏳ 签到中...';
|
||||
btn.disabled = true; btn.textContent = '⏳ 签到中...';
|
||||
try {
|
||||
const resp = await fetch('/api/batch/signin', {method: 'POST'});
|
||||
const data = await resp.json();
|
||||
if (data.success) {
|
||||
const r = data.data;
|
||||
alert(`签到完成:${r.total_accounts} 个账号,${r.total_signed} 成功,${r.total_already} 已签,${r.total_failed} 失败`);
|
||||
} else {
|
||||
alert('签到失败: ' + (data.message || '未知错误'));
|
||||
}
|
||||
} catch(e) {
|
||||
alert('请求失败: ' + e.message);
|
||||
}
|
||||
btn.disabled = false;
|
||||
btn.textContent = '🚀 全部签到';
|
||||
} else { alert('签到失败: ' + (data.message || '未知错误')); }
|
||||
} catch(e) { alert('请求失败: ' + e.message); }
|
||||
btn.disabled = false; btn.textContent = '🚀 全部签到';
|
||||
location.reload();
|
||||
}
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user