From 81f1eae2d5be4e575e8db2da8916b1ea281d5d24 Mon Sep 17 00:00:00 2001 From: Viajero <2737079298@qq.com> Date: Tue, 14 Oct 2025 15:01:14 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E2=80=9C=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E7=BC=96=E8=BE=91=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.py | 23 ++++ templates/all.html | 307 +++++++++++++++++++++++++++++++++++---------- 2 files changed, 264 insertions(+), 66 deletions(-) diff --git a/app.py b/app.py index 23ce270..19fd0d6 100644 --- a/app.py +++ b/app.py @@ -370,6 +370,29 @@ def delete_entry(doc_id): else: return "删除失败", 500 +# 批量删除数据路由 +@app.route('/batch_delete', methods=['POST']) +def batch_delete(): + """ + 批量删除数据 + + 返回: + 重定向到所有数据页面或错误信息 + """ + doc_ids = request.form.getlist('doc_ids') + if not doc_ids: + return "没有选择要删除的文档", 400 + + success_count = 0 + for doc_id in doc_ids: + if delete_by_id(doc_id): + success_count += 1 + + if success_count == len(doc_ids): + return redirect(url_for('show_all')) + else: + return f"成功删除 {success_count} 条记录,失败 {len(doc_ids) - success_count} 条", 500 + # 提供图片访问的路由 diff --git a/templates/all.html b/templates/all.html index 06a4d28..514e9b5 100644 --- a/templates/all.html +++ b/templates/all.html @@ -27,50 +27,87 @@ margin-bottom: 15px; } - /* 表格容器 - 顶部边距调整 */ - .table-container { - overflow-x: auto; - margin-top: 15px; /* 减少顶部间距 */ + /* 卡片容器样式 */ + .data-cards { + display: grid; + grid-template-columns: repeat(auto-fill, minmax(400px, 1fr)); + gap: 20px; + margin-bottom: 20px; + } + + /* 卡片样式 */ + .data-card { + background-color: white; border-radius: 8px; - box-shadow: 0 4px 6px rgba(0,0,0,0.1); + box-shadow: 0 2px 8px rgba(0,0,0,0.1); + padding: 20px; + border: 1px solid #e0e0e0; + transition: transform 0.3s, box-shadow 0.3s; } - /* 表格样式 */ - table { - width: 100%; - border-collapse: collapse; - font-family: 'Segoe UI', Arial, sans-serif; + .data-card:hover { + transform: translateY(-2px); + box-shadow: 0 4px 12px rgba(0,0,0,0.15); } - /* 表头样式 */ - thead { - background: linear-gradient(135deg, #3498db, #1a5276); - color: white; + /* 卡片头部样式 */ + .card-header { + display: flex; + justify-content: space-between; + align-items: center; + margin-bottom: 15px; + padding-bottom: 15px; + border-bottom: 1px solid #f0f0f0; } - th { - padding: 16px 12px; - text-align: left; + .card-header h3 { + margin: 0; + color: #333; + font-size: 18px; + } + + .card-actions { + display: flex; + gap: 8px; + } + + /* 卡片内容样式 */ + .card-content { + margin-bottom: 15px; + } + + .field-item { + display: flex; + margin-bottom: 10px; + line-height: 1.5; + } + + .field-key { font-weight: 600; + color: #333; + min-width: 120px; + margin-right: 10px; } - /* 表格行样式 */ - tbody tr { - border-bottom: 1px solid #eef1f5; - transition: background-color 0.3s; + .field-value { + color: #666; + flex: 1; + word-break: break-word; } - tbody tr:nth-child(even) { - background-color: #f8fafc; + /* 卡片图片样式 */ + .card-image { + text-align: center; + margin-top: 15px; + padding-top: 15px; + border-top: 1px solid #f0f0f0; } - tbody tr:hover { - background-color: #e3f2fd; - } - - td { - padding: 14px 12px; - color: #4a5568; + .card-image img { + max-width: 100%; + max-height: 200px; + border-radius: 4px; + box-shadow: 0 2px 4px rgba(0,0,0,0.1); } /* 操作按钮样式 */ @@ -128,6 +165,33 @@ padding: 40px 0; color: #a0aec0; font-style: italic; + grid-column: 1 / -1; + } + + /* 响应式设计 */ + @media (max-width: 768px) { + .data-cards { + grid-template-columns: 1fr; + } + + .card-header { + flex-direction: column; + align-items: flex-start; + gap: 10px; + } + + .card-actions { + align-self: flex-end; + } + + .field-item { + flex-direction: column; + } + + .field-key { + min-width: auto; + margin-bottom: 5px; + } } @@ -135,44 +199,155 @@

所有已录入的奖项信息

在此页面可以查看所有已录入的成果信息,并进行编辑和删除操作

-
- - - - - - - - - - - - {% if data %} - {% for item in data %} - - - - - - - - {% endfor %} - {% else %} - - - - {% endif %} - -
比赛/论文名称项目名称学生指导老师操作
{{ item.id or '无' }}{{ item.name or '无' }}{% if item.students is string %}{{ item.students or '无' }}{% else %}{{ item.students|join(', ') if item.students else '无' }}{% endif %}{% if item.teacher is string %}{{ item.teacher or '无' }}{% else %}{{ item.teacher|join(', ') if item.teacher else '无' }}{% endif %} -
- 编辑 -
- -
-
-
暂无数据
+ +
+
+
+ + +
+ + 已选择 0 项 +
+
+ +
+ {% if data %} + {% for item in data %} +
+
+
+ +

记录 {{ loop.index }}

+
+
+ 编辑 +
+
+ +
+ {% if item.data %} + {# 从原始数据中解析字段 #} + {% set data_string = item.data %} + {% set pairs = data_string.split('|###|') %} + + {% for pair in pairs %} + {% if ':' in pair %} + {% set key_value = pair.split(':', 1) %} + {% set field_key = key_value[0].strip() %} + {% set field_value = key_value[1].strip() %} + + {# 处理列表格式 [item1|##|item2] #} + {% if field_value.startswith('[') and field_value.endswith(']') %} + {% set list_content = field_value[1:-1] %} + {% set field_value = list_content.split('|##|')|join(', ') %} + {% endif %} + +
+ {{ field_key }}: + {{ field_value or '无' }} +
+ {% endif %} + {% endfor %} + {% else %} + {# 如果没有data字段,显示解析后的字段 #} + {% for key, value in item.items() %} + {% if key not in ['_id', 'image'] %} +
+ {{ key }}: + + {% if value is sequence and value is not string %} + {{ value|join(', ') if value else '无' }} + {% else %} + {{ value or '无' }} + {% endif %} + +
+ {% endif %} + {% endfor %} + {% endif %} +
+ + +
+ {% endfor %} + {% else %} +
暂无数据
+ {% endif %}
返回首页
+ + + {% endblock %} \ No newline at end of file