From 35eea7a8032c52cf151daf5b89392aa180aa408f Mon Sep 17 00:00:00 2001 From: wzj <244142824@qq.com> Date: Sun, 15 Jun 2025 08:36:37 +0800 Subject: [PATCH] =?UTF-8?q?CA=E8=AF=A6=E6=83=85=E9=A1=B5=E8=AF=81=E4=B9=A6?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E5=88=86=E9=A1=B5=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.py | 25 ++++++++++++++--- templates/base.html | 2 +- templates/ca_detail.html | 59 +++++++++++++++++++++++++++++----------- 3 files changed, 65 insertions(+), 21 deletions(-) diff --git a/app.py b/app.py index 7f11430..9df1b11 100644 --- a/app.py +++ b/app.py @@ -1400,9 +1400,11 @@ def create_ca_view(): from datetime import timedelta # 确保顶部已导入 + @app.route('/cas/') @login_required def ca_detail(ca_id): + page = request.args.get('page', 1, type=int) ca = get_ca_by_id(ca_id) if not ca: flash('CA不存在', 'danger') @@ -1413,16 +1415,28 @@ def ca_detail(ca_id): flash('无权访问此CA', 'danger') return redirect(url_for('ca_list')) - # 获取该CA颁发的证书 + # 获取该CA颁发的证书(分页) conn = get_db_connection() if conn: try: cursor = conn.cursor(dictionary=True) + + # 获取证书总数 + cursor.execute(""" + SELECT COUNT(*) as total FROM certificates + WHERE ca_id = %s + """, (ca_id,)) + total = cursor.fetchone()['total'] + total_pages = ceil(total / PER_PAGE) + + # 获取分页数据 + offset = (page - 1) * PER_PAGE cursor.execute(""" SELECT * FROM certificates WHERE ca_id = %s ORDER BY created_at DESC - """, (ca_id,)) + LIMIT %s OFFSET %s + """, (ca_id, PER_PAGE, offset)) certificates = cursor.fetchall() # 获取CRL信息 @@ -1437,8 +1451,11 @@ def ca_detail(ca_id): ca=ca, certificates=certificates, crl=crl, - timedelta=timedelta, # 传递timedelta到模板 - get_username=get_username # 确保这个函数已定义 + page=page, + total_pages=total_pages, + total=total, + timedelta=timedelta, + get_username=get_username ) except Error as e: print(f"Database error: {e}") diff --git a/templates/base.html b/templates/base.html index 470a737..12f4976 100644 --- a/templates/base.html +++ b/templates/base.html @@ -3,7 +3,7 @@ - 证书管理系统 - {% block title %}{% endblock %} + 自签证书管理系统 - {% block title %}{% endblock %} diff --git a/templates/ca_detail.html b/templates/ca_detail.html index 1b597a4..7a3e01e 100644 --- a/templates/ca_detail.html +++ b/templates/ca_detail.html @@ -112,11 +112,12 @@ +
颁发的证书 - {{ certificates|length }} + {{ total }}
{{ cert.expires_at.strftime('%Y-%m-%d') }} {{ cert.created_at.strftime('%Y-%m-%d') }} - - + {% endfor %}
+ + {% if total_pages > 1 %} + + {% endif %} + {% else %}