前后端数据流对齐:
后端改动:
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:
@@ -213,18 +213,32 @@ def logout():
|
||||
@app.route('/dashboard')
|
||||
@login_required
|
||||
def dashboard():
|
||||
page = request.args.get('page', 1, type=int)
|
||||
try:
|
||||
response = api_request(
|
||||
'GET',
|
||||
f'{API_BASE_URL}/api/v1/accounts',
|
||||
params={'page': page, 'size': 12},
|
||||
)
|
||||
data = response.json()
|
||||
accounts = data.get('data', []) if data.get('success') else []
|
||||
if data.get('success'):
|
||||
payload = data.get('data', {})
|
||||
# 兼容旧版 API(返回列表)和新版(返回分页对象)
|
||||
if isinstance(payload, list):
|
||||
accounts = payload
|
||||
pagination = {'items': payload, 'total': len(payload), 'page': 1, 'size': len(payload), 'total_pages': 1, 'status_counts': {}}
|
||||
else:
|
||||
accounts = payload.get('items', [])
|
||||
pagination = payload
|
||||
else:
|
||||
accounts = []
|
||||
pagination = {'items': [], 'total': 0, 'page': 1, 'size': 12, 'total_pages': 0, 'status_counts': {}}
|
||||
except requests.RequestException:
|
||||
accounts = []
|
||||
pagination = {'items': [], 'total': 0, 'page': 1, 'size': 12, 'total_pages': 0, 'status_counts': {}}
|
||||
flash('加载账号列表失败', 'warning')
|
||||
|
||||
return render_template('dashboard.html', accounts=accounts, user=session.get('user'))
|
||||
return render_template('dashboard.html', accounts=accounts, pagination=pagination, user=session.get('user'))
|
||||
|
||||
@app.route('/accounts/new')
|
||||
@login_required
|
||||
@@ -841,9 +855,10 @@ def delete_task(task_id):
|
||||
def batch_verify():
|
||||
"""批量验证所有账号的 Cookie 有效性"""
|
||||
try:
|
||||
response = api_request('GET', f'{API_BASE_URL}/api/v1/accounts')
|
||||
response = api_request('GET', f'{API_BASE_URL}/api/v1/accounts', params={'page': 1, 'size': 500})
|
||||
data = response.json()
|
||||
accounts = data.get('data', []) if data.get('success') else []
|
||||
payload = data.get('data', {}) if data.get('success') else {}
|
||||
accounts = payload.get('items', []) if isinstance(payload, dict) else payload
|
||||
|
||||
valid = invalid = errors = 0
|
||||
for account in accounts:
|
||||
@@ -871,9 +886,10 @@ def batch_verify():
|
||||
def batch_signin():
|
||||
"""批量签到所有正常状态的账号"""
|
||||
try:
|
||||
response = api_request('GET', f'{API_BASE_URL}/api/v1/accounts')
|
||||
response = api_request('GET', f'{API_BASE_URL}/api/v1/accounts', params={'page': 1, 'size': 500})
|
||||
data = response.json()
|
||||
accounts = data.get('data', []) if data.get('success') else []
|
||||
payload = data.get('data', {}) if data.get('success') else {}
|
||||
accounts = payload.get('items', []) if isinstance(payload, dict) else payload
|
||||
|
||||
total_signed = total_already = total_failed = 0
|
||||
processed = 0
|
||||
|
||||
Reference in New Issue
Block a user