Skip to content

Commit cef5d70

Browse files
committed
Refactor user list API to remove pagination support and update related frontend logic. Adjusted API documentation and cleaned up user management template by removing pagination elements.
1 parent 1b1cef7 commit cef5d70

2 files changed

Lines changed: 7 additions & 63 deletions

File tree

webpanel/blueprints/user.py

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -491,19 +491,17 @@ def get_user_stats():
491491

492492
@user_bp.route('/api/list')
493493
def get_user_list():
494-
"""获取用户列表(支持分页和搜索)"""
494+
"""获取用户列表(支持搜索,不分页)"""
495495
try:
496496
print("=== 用户列表API被调用 ===")
497497
users = safe_get_users()
498498
print(f"获取到的原始用户数据: {users}")
499499
print(f"用户数量: {len(users)}")
500500

501501
# 获取查询参数
502-
page = int(request.args.get('page', 1))
503-
per_page = int(request.args.get('per_page', 10))
504502
search = request.args.get('search', '').strip()
505503
status = request.args.get('status', '').strip()
506-
print(f"查询参数: page={page}, per_page={per_page}, search='{search}', status='{status}'")
504+
print(f"查询参数: search='{search}', status='{status}'")
507505

508506
# 过滤用户
509507
filtered_users = []
@@ -532,29 +530,13 @@ def get_user_list():
532530
print(f"格式化用户数据: {formatted_user}") # 调试信息
533531
filtered_users.append(formatted_user)
534532

535-
# 分页计算
536-
total_users = len(filtered_users)
537-
total_pages = (total_users + per_page - 1) // per_page if total_users > 0 else 1
538-
start_idx = (page - 1) * per_page
539-
end_idx = start_idx + per_page
540-
541-
paginated_users = filtered_users[start_idx:end_idx]
542-
543-
pagination_info = {
544-
'current_page': page,
545-
'total_pages': total_pages,
546-
'total_items': total_users,
547-
'per_page': per_page
548-
}
549-
550533
result = {
551534
'success': True,
552535
'data': {
553-
'users': paginated_users,
554-
'pagination': pagination_info
536+
'users': filtered_users
555537
}
556538
}
557-
print(f"返回结果: {result}")
539+
print(f"返回结果: {len(filtered_users)}个用户")
558540
return jsonify(result)
559541
except Exception as e:
560542
return jsonify({

webpanel/templates/user_management.html

Lines changed: 3 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -131,12 +131,6 @@ <h3 id="successRate">-</h3>
131131
</table>
132132
</div>
133133

134-
<!-- 分页 -->
135-
<nav aria-label="用户列表分页">
136-
<ul class="pagination justify-content-center" id="pagination">
137-
<!-- 分页将通过JavaScript动态生成 -->
138-
</ul>
139-
</nav>
140134
</div>
141135
</div>
142136

@@ -331,15 +325,12 @@ <h5 class="modal-title">编辑用户</h5>
331325
}
332326

333327
// 加载用户列表
334-
function loadUserList(page = 1) {
335-
console.log('开始请求用户列表API, 页码:', page);
328+
function loadUserList() {
329+
console.log('开始请求用户列表API');
336330
const search = $('#searchInput').val() || '';
337331
const status = $('#statusFilter').val() || '';
338332

339-
const params = {
340-
page: page,
341-
per_page: 10
342-
};
333+
const params = {};
343334

344335
// 只有在有值时才添加搜索和状态参数
345336
if (search) {
@@ -356,12 +347,10 @@ <h5 class="modal-title">编辑用户</h5>
356347
console.log('用户列表API响应:', response);
357348
if (response.success && response.data) {
358349
renderUserTable(response.data.users || []);
359-
renderPagination(response.data.pagination || {current_page: 1, total_pages: 1, total_items: 0, per_page: 10});
360350
console.log('用户列表渲染完成');
361351
} else {
362352
console.error('用户列表API返回失败:', response.message || '未知错误');
363353
renderUserTable([]);
364-
renderPagination({current_page: 1, total_pages: 1, total_items: 0, per_page: 10});
365354
if (typeof showToast === 'function') {
366355
showToast('加载用户列表失败: ' + (response.message || '未知错误'), 'error');
367356
}
@@ -371,7 +360,6 @@ <h5 class="modal-title">编辑用户</h5>
371360
console.error('用户列表API请求失败:', error, 'status:', status, 'xhr:', xhr);
372361
console.error('响应文本:', xhr.responseText);
373362
renderUserTable([]);
374-
renderPagination({current_page: 1, total_pages: 1, total_items: 0, per_page: 10});
375363
if (typeof showToast === 'function') {
376364
showToast('加载用户列表失败: 网络错误', 'error');
377365
}
@@ -441,32 +429,6 @@ <h5 class="modal-title">编辑用户</h5>
441429
console.log('用户表格渲染完成:', users.length, '个用户');
442430
}
443431

444-
// 渲染分页
445-
function renderPagination(pagination) {
446-
const nav = $('#pagination');
447-
nav.empty();
448-
449-
if (pagination.total_pages <= 1) return;
450-
451-
// 上一页
452-
if (pagination.current_page > 1) {
453-
nav.append(`<li class="page-item"><a class="page-link" href="#" onclick="loadUserList(${pagination.current_page - 1})">上一页</a></li>`);
454-
}
455-
456-
// 页码
457-
for (let i = 1; i <= pagination.total_pages; i++) {
458-
if (i === pagination.current_page) {
459-
nav.append(`<li class="page-item active"><span class="page-link">${i}</span></li>`);
460-
} else {
461-
nav.append(`<li class="page-item"><a class="page-link" href="#" onclick="loadUserList(${i})">${i}</a></li>`);
462-
}
463-
}
464-
465-
// 下一页
466-
if (pagination.current_page < pagination.total_pages) {
467-
nav.append(`<li class="page-item"><a class="page-link" href="#" onclick="loadUserList(${pagination.current_page + 1})">下一页</a></li>`);
468-
}
469-
}
470432

471433
// 更新批量操作按钮状态
472434
function updateBatchButtons() {

0 commit comments

Comments
 (0)