certs优化
AI Code Reviewer / ai_review (pull_request) Successful in 27s

This commit is contained in:
2026-03-29 09:31:03 +08:00
Unverified
parent 4db083926e
commit 0414810364
2 changed files with 332 additions and 219 deletions
+123 -80
View File
@@ -3,9 +3,10 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>荣誉证书系统</title>
<title>荣誉证书核验 - 详细信息</title>
<script src="https://cdn.jsdelivr.net/npm/@supabase/supabase-js@2"></script>
<style>
:root { --a4-ratio: 210 / 297; }
:root { --primary: #1a73e8; }
body {
margin: 0; padding: 0; background: #f0f2f5;
display: flex; flex-direction: column; align-items: center;
@@ -18,125 +19,167 @@
width: 100%; padding: 15px; background: white;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
position: sticky; top: 0; z-index: 100;
display: flex; flex-direction: column; align-items: center; gap: 8px;
display: flex; justify-content: center; gap: 15px;
}
.btn-print {
padding: 10px 25px; background: #1a73e8; color: white;
border: none; border-radius: 6px; cursor: pointer; font-weight: 500;
.btn {
padding: 8px 20px; border-radius: 6px; cursor: pointer;
font-weight: 500; text-decoration: none; font-size: 14px; border: none;
}
.btn-print { background: var(--primary); color: white; }
.btn-back { background: #f1f5f9; color: #475569; border: 1px solid #e2e8f0; }
.tip { font-size: 12px; color: #ef4444; }
@media (min-width: 1024px) { .tip { display: none; } }
/* 证书容器 */
/* 主体内容 */
.main-content {
flex: 1; /* 撑开中间区域 */
display: flex;
flex-direction: column;
align-items: center;
width: 100%;
width: 100%; max-width: 850px;
display: flex; flex-direction: column; padding: 20px;
}
/* 证书预览区域 */
#cert-viewport {
margin: 30px auto;
width: 90vw;
max-width: 650px;
aspect-ratio: var(--a4-ratio);
background: white;
width: 100%; background: white;
box-shadow: 0 10px 30px rgba(0,0,0,0.1);
display: flex; justify-content: center; align-items: center;
position: relative;
margin-bottom: 40px;
display: flex; justify-content: center;
}
#cert-img { width: 100%; height: auto; display: none; }
#cert-img { width: 100%; height: 100%; object-fit: contain; display: none; }
#error-msg { display: none; color: #666; text-align: center; padding: 20px; }
/* --- 版权页脚样式 --- */
.footer {
width: 100%;
padding: 20px 0;
text-align: center;
color: #94a3b8; /* 浅灰色,不抢眼 */
font-size: 14px;
border-top: 1px solid #e2e8f0;
margin-top: 20px;
background: #f8fafc;
/* 详细信息表卡片 */
.info-card {
width: 100%; background: white; border-radius: 12px;
box-shadow: 0 4px 15px rgba(0,0,0,0.05);
overflow: hidden; margin-bottom: 40px;
}
.info-header {
background: #f8fafc; padding: 15px 20px;
border-bottom: 1px solid #edf2f7; font-weight: 600;
display: flex; justify-content: space-between;
}
.info-table { width: 100%; border-collapse: collapse; }
.info-table th, .info-table td {
padding: 16px 20px; text-align: left; border-bottom: 1px solid #f1f5f9;
font-size: 14px;
}
.info-table th { color: #64748b; width: 25%; font-weight: 500; background: #fafbfc; }
.info-table td { color: #1e293b; }
.status-tag { padding: 4px 10px; border-radius: 4px; font-size: 12px; font-weight: 600; }
.status-valid { background: #dcfce7; color: #166534; }
.footer p { margin: 5px 0; }
.footer a { color: #64748b; text-decoration: none; }
.footer a:hover { text-decoration: underline; }
/* --- 打印优化 --- */
/* --- 核心修改:打印分页样式 --- */
@media print {
/* 打印时隐藏工具栏和页脚 */
body { background: white; }
.toolbar, .footer { display: none !important; }
body { background: white; margin: 0; padding: 0; }
.main-content { margin: 0; }
.main-content { padding: 0; max-width: none; width: 100%; }
/* 第一页:证书 */
#cert-viewport {
margin: 0;
width: 100%;
max-width: none;
box-shadow: none;
margin: 0;
width: 100%;
page-break-after: always; /* 旧版浏览器兼容 */
break-after: page; /* 现代浏览器:强制在此元素后分页 */
}
/* 第二页:详情表 */
.info-card {
box-shadow: none;
border: 1px solid #e2e8f0;
margin: 0;
break-before: page; /* 确保详情表从新页面开始 */
}
.info-table th { background: #f8fafc !important; -webkit-print-color-adjust: exact; }
@page {
size: A4 portrait;
margin: 10mm; /* 设置页边距 */
}
@page { size: A4 portrait; margin: 0; }
}
.footer { padding: 40px 0; text-align: center; color: #94a3b8; font-size: 13px; }
</style>
</head>
<body>
<div class="toolbar">
<div class="tip">⚠️ 建议在电脑端使用 Chrome 浏览器打印以获得最佳效果</div>
<button class="btn-print" onclick="window.print()">打印 / 导出 PDF</button>
<a href="javascript:history.back()" class="btn btn-back">返回查询</a>
<button class="btn btn-print" onclick="window.print()">打印证书及明细</button>
</div>
<div class="main-content">
<div id="cert-viewport">
<img id="cert-img" alt="荣誉证书">
<div id="error-msg">
<h2 style="color:#e11d48">❌ 证书不存在</h2>
<p>请核对证书 ID 或联系管理员</p>
<img id="cert-img" alt="荣誉证书原件">
</div>
<div class="info-card" id="info-card" style="display: none;">
<div class="info-header">
<span>证书明细</span>
<span id="display-status"></span>
</div>
<table class="info-table">
<tr><th>证书编号</th><td id="d-cert-number">-</td></tr>
<tr><th>持有人姓名</th><td id="d-holder-name">-</td></tr>
<tr><th>荣誉名称</th><td id="d-honor-title">-</td></tr>
<tr><th>颁发日期</th><td id="d-issue-date">-</td></tr>
<tr><th>颁发机构</th><td id="d-issuer">-</td></tr>
<tr><th>详细描述</th><td id="d-desc">-</td></tr>
<tr><th>系统备注</th><td id="d-remarks">-</td></tr>
<tr><th>核验时间</th><td id="d-verify-time">-</td></tr>
</table>
</div>
</div>
<footer class="footer">
<p>© 2026 BI. All Rights Reserved.</p>
<p style="font-size: 12px; opacity: 0.7;">由 Gemini 技术支持提供生成</p>
<p>© 2026 BI</p>
</footer>
<script>
function loadCertificate() {
const urlParams = new URLSearchParams(window.location.search);
const certId = urlParams.get('id');
const imgElement = document.getElementById('cert-img');
const errorElement = document.getElementById('error-msg');
const SUPABASE_URL = 'https://chixssrphfgxvqqigkzo.supabase.co';
const SUPABASE_ANON_KEY = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImNoaXhzc3JwaGZneHZxcWlna3pvIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NzQ2OTE0OTEsImV4cCI6MjA5MDI2NzQ5MX0.Az_Ew2J2zdOMcSV0UNAjBS-LPqGpqhsaN4IyZ5R7iqU';
const sbClient = supabase.createClient(SUPABASE_URL, SUPABASE_ANON_KEY);
if (!certId) {
errorElement.style.display = 'block';
errorElement.innerHTML = '<h2>请在链接中包含证书 ID</h2>';
return;
async function loadData() {
const id = new URLSearchParams(window.location.search).get('id');
if (!id) return;
try {
const { data, error } = await sbClient
.from('certificates')
.select('*')
.eq('id', id)
.single();
if (error || !data) throw error;
// 填充数据
document.getElementById('info-card').style.display = 'block';
document.getElementById('d-cert-number').innerText = data.cert_number;
document.getElementById('d-holder-name').innerText = data.holder_name;
document.getElementById('d-honor-title').innerText = data.honor_title;
document.getElementById('d-issue-date').innerText = data.issue_date || '-';
document.getElementById('d-issuer').innerText = data.issuer || '官方授权机构';
document.getElementById('d-desc').innerText = data.description || '官方荣誉认证';
document.getElementById('d-remarks').innerText = data.remarks || '无';
document.getElementById('d-verify-time').innerText = new Date().toLocaleString();
if (data.status === 'valid') {
document.getElementById('display-status').innerHTML = '<span class="status-tag status-valid">核验通过</span>';
}
// 加载图片
const img = document.getElementById('cert-img');
img.src = `img/${data.cert_number}.svg`;
img.onload = () => img.style.display = 'block';
} catch (e) {
console.error("加载失败:", e);
alert("证书信息检索失败");
}
// 加载 img/ 目录下的同名 SVG
const filePath = `img/${certId}.svg`;
imgElement.src = filePath;
imgElement.onload = function() {
imgElement.style.display = 'block';
errorElement.style.display = 'none';
document.title = "证书验证 - " + certId;
};
imgElement.onerror = function() {
imgElement.style.display = 'none';
errorElement.style.display = 'block';
};
}
loadCertificate();
loadData();
</script>
</body>
</html>