统一样式

This commit is contained in:
2026-04-26 10:28:58 +08:00
Unverified
parent ef001c7460
commit c54e5209af
7 changed files with 1813 additions and 1024 deletions
+137 -173
View File
@@ -3,160 +3,84 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>荣誉证书核验 - 详细信息</title>
<title>证书核验详情</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Noto+Sans+SC:wght@400;500;600;700&family=Orbitron:wght@500;700&display=swap" rel="stylesheet">
<link rel="stylesheet" href="../css/tech-query.css">
<script src="https://cdn.jsdelivr.net/npm/@supabase/supabase-js@2"></script>
<style>
:root { --primary: #1a73e8; }
body {
margin: 0; padding: 0; background: #f0f2f5;
display: flex; flex-direction: column; align-items: center;
min-height: 100vh;
font-family: system-ui, -apple-system, sans-serif;
}
/* 顶部工具栏 */
.toolbar {
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; justify-content: center; gap: 15px;
}
.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; }
/* 主体内容 */
.main-content {
width: 100%; max-width: 850px;
display: flex; flex-direction: column; padding: 20px;
}
/* 证书预览区域 */
#cert-viewport {
width: 100%; background: white;
box-shadow: 0 10px 30px rgba(0,0,0,0.1);
margin-bottom: 40px;
display: flex; justify-content: center;
cursor: pointer;
position: relative;
min-height: 400px;
align-items: center;
}
#cert-img { width: 100%; height: auto; display: none; }
/* 点击加载提示 */
.click-hint {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
text-align: center;
color: #64748b;
font-size: 16px;
}
.click-hint-icon {
font-size: 48px;
margin-bottom: 10px;
color: var(--primary);
}
/* 详细信息表卡片 */
.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; }
/* --- 核心修改:打印分页样式 --- */
@media print {
body { background: white; }
.toolbar, .footer { display: none !important; }
.main-content { padding: 0; max-width: none; width: 100%; }
/* 第一页:证书 */
#cert-viewport {
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; /* 设置页边距 */
}
}
.footer { padding: 40px 0; text-align: center; color: #94a3b8; font-size: 13px; }
</style>
</head>
<body>
<div class="toolbar">
<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" onclick="loadCertificateImage()">
<img id="cert-img" alt="荣誉证书原件">
<div class="click-hint" id="click-hint">
<div class="click-hint-icon">🖼️</div>
<div>点击查看证书图片</div>
<main class="detail-shell">
<div class="top-actions">
<a href="javascript:history.back()" class="tech-link-button secondary">返回查询</a>
<div class="top-actions-group">
<button type="button" class="tech-button secondary" onclick="loadCertificateImage()">加载证书图片</button>
<button type="button" class="tech-button" onclick="printCertificate()">打印证书与明细</button>
</div>
</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>
<section class="detail-grid">
<section class="preview-panel">
<div class="section-kicker">Certificate Preview</div>
<h1 class="section-heading">证书原件预览</h1>
<p class="section-copy">点击下方预览区域或使用顶部按钮,即可加载对应证书原件图片。</p>
<div id="cert-viewport" class="certificate-stage" onclick="loadCertificateImage()">
<img id="cert-img" alt="证书原件">
<div class="certificate-hint" id="click-hint">
<span class="hint-orb"></span>
<strong>点击加载证书图片</strong>
<span>原件图片将从当前证书编号对应的 `img/*.svg` 文件中读取。</span>
</div>
</div>
</section>
<footer class="footer">
<p>© 2026 BI</p>
<aside class="summary-panel">
<div class="section-kicker">Verify Status</div>
<h2 class="section-heading">核验摘要</h2>
<p class="section-copy">证书基础信息与系统核验状态会在这里同步展示。</p>
<div class="summary-stack">
<div class="summary-tile">
<span class="summary-label">证书编号</span>
<div class="summary-value emphasis" id="summary-cert-number">-</div>
</div>
<div class="summary-tile">
<span class="summary-label">持有人</span>
<div class="summary-value" id="summary-holder-name">-</div>
</div>
<div class="summary-tile">
<span class="summary-label">核验状态</span>
<div id="display-status"><span class="status-pill pending">待核验</span></div>
</div>
<div class="summary-tile">
<span class="summary-label">最近核验时间</span>
<div class="summary-value" id="summary-verify-time">-</div>
</div>
</div>
</aside>
</section>
<section class="detail-panel" id="info-card" style="display: none; margin-top: 18px;">
<div class="section-kicker">Certificate Detail</div>
<h2 class="section-heading">证书明细信息</h2>
<p class="section-copy">以下信息由证书数据库实时读取,用于核验与归档展示。</p>
<div class="info-table-shell">
<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>
</section>
</main>
<footer class="page-footer">
<p>© 2026 BI Intelligent Query Interface</p>
</footer>
<script>
@@ -175,56 +99,55 @@
.eq('id', id)
.single();
if (error || !data) throw error;
if (error || !data) throw error || new Error('未找到证书信息');
// 填充数据
const verifyTime = new Date().toLocaleString('zh-CN');
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-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();
document.getElementById('d-verify-time').innerText = verifyTime;
document.getElementById('summary-cert-number').innerText = data.cert_number || '-';
document.getElementById('summary-holder-name').innerText = data.holder_name || '-';
document.getElementById('summary-verify-time').innerText = verifyTime;
if (data.status === 'valid') {
document.getElementById('display-status').innerHTML = '<span class="status-tag status-valid">有效</span>';
document.getElementById('display-status').innerHTML = '<span class="status-pill done">有效</span>';
} else if (data.status === 'invalid') {
document.getElementById('display-status').innerHTML = '<span class="status-pill pending">无效</span>';
} else {
document.getElementById('display-status').innerHTML = '<span class="status-pill pending">待核验</span>';
}
if (data.status === 'invalid') {
document.getElementById('display-status').innerHTML = '<span class="status-tag">无效</span>';
}
// 图片改为点击加载,初始不加载
window.currentCertNumber = data.cert_number;
} catch (e) {
console.error("加载失败:", e);
alert("证书信息检索失败");
console.error('加载失败:', e);
alert('证书信息检索失败。');
}
}
// 点击加载证书图片
function loadCertificateImage() {
const certNumber = window.currentCertNumber;
if (!certNumber) return;
const img = document.getElementById('cert-img');
const hint = document.getElementById('click-hint');
// 如果图片已加载,直接显示
if (img.src && img.complete) {
img.style.display = 'block';
if (hint) hint.style.display = 'none';
return;
}
// 加载中提示
if (hint) {
hint.innerHTML = '<div class="click-hint-icon"></div><div>图片加载中...</div>';
hint.innerHTML = '<span class="hint-orb"></span><strong>图片加载中</strong><span>正在读取证书原件,请稍候。</span>';
}
img.src = `img/${certNumber}.svg`;
img.onload = () => {
img.style.display = 'block';
@@ -232,14 +155,55 @@
};
img.onerror = () => {
if (hint) {
hint.innerHTML = '<div class="click-hint-icon"></div><div>图片加载失败</div>';
hint.innerHTML = '<span class="hint-orb">!</span><strong>图片加载失败</strong><span>未找到对应证书图片文件,请检查 `img` 目录资源。</span>';
}
};
}
loadData();
async function ensureCertificateImageLoaded() {
const certNumber = window.currentCertNumber;
const img = document.getElementById('cert-img');
const hint = document.getElementById('click-hint');
if (!certNumber) {
throw new Error('未找到证书编号');
}
if (img.src && img.complete && img.naturalWidth > 0) {
img.style.display = 'block';
if (hint) hint.style.display = 'none';
return;
}
if (hint) {
hint.innerHTML = '<span class="hint-orb">载</span><strong>图片加载中</strong><span>正在为打印准备证书原件,请稍候。</span>';
}
await new Promise((resolve, reject) => {
img.onload = () => {
img.style.display = 'block';
if (hint) hint.style.display = 'none';
resolve();
};
img.onerror = () => {
reject(new Error('证书图片加载失败'));
};
img.src = `img/${certNumber}.svg`;
});
}
async function printCertificate() {
try {
await ensureCertificateImageLoaded();
window.print();
} catch (error) {
console.error('打印前加载证书失败:', error);
alert('证书原件加载失败,无法打印。');
}
}
loadData();
</script>
<script src="https://cdn.jsdmirror.cn/gh/bishshi/wechat-detect@main/wechat-detect.js"></script>
</body>
</html>
</html>
+191 -316
View File
@@ -3,335 +3,210 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>荣誉证书查询系统</title>
<title>证书查询系统</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Noto+Sans+SC:wght@400;500;600;700&family=Orbitron:wght@500;700&display=swap" rel="stylesheet">
<link rel="stylesheet" href="../css/tech-query.css">
<script src="https://cdn.jsdelivr.net/npm/@supabase/supabase-js@2"></script>
<script src="https://unpkg.com/html5-qrcode"></script>
<style>
:root {
--primary-color: #1a73e8;
--bg-color: #f8fafc;
--card-bg: #ffffff;
--text-main: #1e293b;
--text-muted: #64748b;
--border-color: #e2e8f0;
</head>
<body>
<main class="page-shell">
<section class="page-header">
<div class="hero-card">
<span class="eyebrow">Certificate Search</span>
<h1>荣誉证书智能核验平台</h1>
<p>支持按证书编号、持有人姓名与发证日期进行检索,也可以直接扫码快速定位证书记录。</p>
<div class="hero-meta">
<span class="meta-chip">数据范围:2024 年 10 月至今</span>
<span class="meta-chip">查询方式:文本检索 / 二维码扫描</span>
</div>
</div>
<aside class="stat-card">
<div>
<div class="stat-label">Module</div>
<div class="stat-value">CERT</div>
</div>
<p></p>
</aside>
</section>
<section class="panel-card">
<div class="panel-title-row">
<div>
<h2 class="panel-title">检索条件</h2>
<div class="panel-subtitle">输入编号或姓名后即可开始查询</div>
</div>
</div>
<div class="search-grid">
<div class="form-group">
<label class="form-label" for="searchTerm">编号 / 姓名</label>
<div class="input-with-action">
<input type="text" id="searchTerm" class="tech-input" placeholder="输入编号或姓名,或点击右侧扫码">
<button type="button" class="icon-action" id="startScanBtn" title="扫码查询" aria-label="扫码查询">
<svg xmlns="http://www.w3.org/2000/svg" width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M3 7V5a2 2 0 0 1 2-2h2"></path><path d="M17 3h2a2 2 0 0 1 2 2v2"></path><path d="M21 17v2a2 2 0 0 1-2 2h-2"></path><path d="M7 21H5a2 2 0 0 1-2-2v-2"></path><rect x="7" y="7" width="10" height="10"></rect></svg>
</button>
</div>
</div>
<div class="form-group">
<label class="form-label" for="dateStart">开始日期</label>
<input type="date" id="dateStart" class="tech-input">
</div>
<div class="form-group">
<label class="form-label" for="dateEnd">结束日期</label>
<input type="date" id="dateEnd" class="tech-input">
</div>
<button id="searchBtn" class="tech-button">执行查询</button>
</div>
</section>
<section class="panel-card results-card">
<div class="panel-title-row">
<div>
<h2 class="panel-title">查询结果</h2>
<div class="panel-subtitle">点击“查看详情”进入证书详情页</div>
</div>
</div>
<div id="resultsArea" class="results-shell">
<div class="empty-state">请输入查询条件,或使用扫码功能快速检索证书。</div>
</div>
</section>
</main>
<div id="scanner-overlay" class="scanner-overlay">
<div class="scanner-frame">
<div id="reader"></div>
<div class="scanner-line"></div>
</div>
<div class="scanner-text">请将二维码置于识别框内</div>
<button class="tech-button secondary" id="stopScanBtn" type="button">退出扫描</button>
</div>
<footer class="page-footer">
<p>© 2026 BI Intelligent Query Interface</p>
</footer>
<script>
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);
const html5QrCode = new Html5Qrcode("reader");
const scannerOverlay = document.getElementById('scanner-overlay');
document.getElementById('startScanBtn').addEventListener('click', async () => {
scannerOverlay.style.display = 'flex';
const config = {
fps: 15,
qrbox: { width: 300, height: 180 },
aspectRatio: 1.0
};
try {
await html5QrCode.start(
{ facingMode: "environment" },
config,
(decodedText) => {
document.getElementById('searchTerm').value = decodedText;
closeScanner();
handleSearch();
},
() => {}
);
} catch (err) {
alert("无法启动摄像头,请检查 HTTPS 权限或设备连接。");
scannerOverlay.style.display = 'none';
}
});
async function closeScanner() {
if (html5QrCode.isScanning) {
await html5QrCode.stop();
}
scannerOverlay.style.display = 'none';
}
* { box-sizing: border-box; }
body {
background: var(--bg-color);
font-family: system-ui, -apple-system, sans-serif;
margin: 0; padding: 10px;
color: var(--text-main);
line-height: 1.5;
}
document.getElementById('stopScanBtn').addEventListener('click', closeScanner);
.container {
max-width: 1000px;
margin: 20px auto;
background: var(--card-bg);
padding: 24px;
border-radius: 16px;
box-shadow: 0 4px 20px rgba(0,0,0,0.05);
}
async function handleSearch() {
const term = document.getElementById('searchTerm').value.trim();
const start = document.getElementById('dateStart').value;
const end = document.getElementById('dateEnd').value;
const display = document.getElementById('resultsArea');
h1 {
text-align: center;
color: var(--primary-color);
font-size: clamp(20px, 5vw, 26px);
margin-bottom: 30px;
}
if (!term) {
alert("请输入证书编号或持有人姓名。");
return;
}
.search-section {
background: var(--bg-color);
padding: 20px;
border-radius: 12px;
margin-bottom: 24px;
border: 1px solid var(--border-color);
}
display.innerHTML = '<div class="loading-state">正在连接证书数据库并执行检索...</div>';
.search-grid {
display: grid;
grid-template-columns: 1fr;
gap: 16px;
}
try {
let query = sbClient.from('certificates').select('*');
query = query.or(`cert_number.ilike.%${term}%,holder_name.ilike.%${term}%`);
@media (min-width: 768px) {
.search-grid {
grid-template-columns: 2fr 1fr 1fr auto;
align-items: end;
if (start) query = query.gte('issue_date', start);
if (end) query = query.lte('issue_date', end);
const { data, error } = await query.order('issue_date', { ascending: false });
if (error) throw error;
renderResults(data);
} catch (err) {
display.innerHTML = `<div class="error-state">检索失败:${err.message}</div>`;
}
}
.form-group { display: flex; flex-direction: column; }
.form-group label {
font-size: 13px;
color: var(--text-muted);
margin-bottom: 6px;
font-weight: 600;
}
function renderResults(data) {
const display = document.getElementById('resultsArea');
if (!data || data.length === 0) {
display.innerHTML = '<div class="empty-state">未找到匹配的证书记录。</div>';
return;
}
/* 搜索框容器:容纳扫码图标 */
.input-with-icon {
position: relative;
display: flex;
align-items: center;
}
.form-control {
padding: 10px 45px 10px 14px; /* 右侧留出空间给图标 */
border: 1px solid var(--border-color);
border-radius: 8px;
font-size: 15px;
width: 100%;
height: 42px;
}
.scan-trigger {
position: absolute;
right: 10px;
cursor: pointer;
color: var(--primary-color);
padding: 5px;
display: flex;
align-items: center;
transition: transform 0.2s;
}
.scan-trigger:hover { transform: scale(1.1); }
.btn-search {
height: 42px;
padding: 0 30px;
background: var(--primary-color);
color: #fff;
border: none;
border-radius: 8px;
font-weight: 600;
cursor: pointer;
transition: 0.2s;
}
/* 扫码弹出层 */
#scanner-overlay {
display: none;
position: fixed;
top: 0; left: 0; width: 100%; height: 100%;
background: rgba(0,0,0,0.85);
z-index: 9999;
flex-direction: column;
justify-content: center;
align-items: center;
padding: 20px;
}
#reader {
width: 100%;
max-width: 400px;
border-radius: 12px;
overflow: hidden;
background: #000;
}
.scanner-controls {
margin-top: 20px;
display: flex;
gap: 15px;
}
.btn-cancel {
padding: 10px 24px;
background: #ef4444;
color: white;
border: none;
border-radius: 6px;
cursor: pointer;
}
/* 表格样式 */
.table-wrapper { overflow-x: auto; margin-top: 10px; }
.result-table { width: 100%; border-collapse: collapse; min-width: 600px; }
.result-table th {
text-align: left; padding: 14px;
background: #f1f5f9; color: var(--text-muted);
font-size: 13px; border-bottom: 2px solid var(--border-color);
}
.result-table td { padding: 14px; border-bottom: 1px solid var(--bg-color); font-size: 14px; }
@media (max-width: 640px) { .hide-on-mobile { display: none; } }
.btn-link { color: var(--primary-color); text-decoration: none; cursor: pointer; font-weight: 600; }
.loading, .no-result { text-align: center; padding: 40px; color: var(--text-muted); }
</style>
</head>
<body>
<div class="container">
<h1>证书查询系统</h1>
<p>说明:可以输入编号或姓名进行查询,也可以点击右侧图标扫码查询;查询范围2024年10月至今</p>
<div class="search-section">
<div class="search-grid">
<div class="form-group">
<label>编号 / 姓名</label>
<div class="input-with-icon">
<input type="text" id="searchTerm" class="form-control" placeholder="输入或扫码查询">
<div class="scan-trigger" id="startScanBtn" title="请扫描条形码">
<svg xmlns="http://www.w3.org/2000/svg" width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M3 7V5a2 2 0 0 1 2-2h2"></path><path d="M17 3h2a2 2 0 0 1 2 2v2"></path><path d="M21 17v2a2 2 0 0 1-2 2h-2"></path><path d="M7 21H5a2 2 0 0 1-2-2v-2"></path><rect x="7" y="7" width="10" height="10"></rect></svg>
</div>
</div>
</div>
<div class="form-group">
<label>颁发起</label>
<input type="date" id="dateStart" class="form-control">
</div>
<div class="form-group">
<label>颁发止</label>
<input type="date" id="dateEnd" class="form-control">
</div>
<button id="searchBtn" class="btn-search">查询</button>
</div>
</div>
<div id="resultsArea">
<div class="no-result">请输入信息或点击右侧图标扫码</div>
</div>
</div>
<div id="scanner-overlay">
<div id="reader"></div>
<div class="scanner-controls">
<button class="btn-cancel" id="stopScanBtn">退出扫描</button>
</div>
</div>
<footer class="footer">
<p>© 2026 BI All rights reserved</p>
</footer>
<script>
// Supabase 配置
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);
// 初始化扫码器
const html5QrCode = new Html5Qrcode("reader");
const scannerOverlay = document.getElementById('scanner-overlay');
// --- 扫码逻辑 ---
document.getElementById('startScanBtn').addEventListener('click', async () => {
scannerOverlay.style.display = 'flex';
// 扫码配置:qrbox 设为长方形有助于识别条形码
const config = {
fps: 15,
qrbox: { width: 300, height: 180 },
aspectRatio: 1.0
};
try {
await html5QrCode.start(
{ facingMode: "environment" }, // 使用后置摄像头
config,
(decodedText) => {
// 识别成功
document.getElementById('searchTerm').value = decodedText;
closeScanner();
handleSearch(); // 自动执行查询
},
(errorMessage) => { /* 扫描中不抛出错误 */ }
);
} catch (err) {
alert("无法启动摄像头,请检查 HTTPS 权限或设备连接");
scannerOverlay.style.display = 'none';
}
});
async function closeScanner() {
if (html5QrCode.isScanning) {
await html5QrCode.stop();
}
scannerOverlay.style.display = 'none';
}
document.getElementById('stopScanBtn').addEventListener('click', closeScanner);
// --- 查询逻辑 ---
async function handleSearch() {
const term = document.getElementById('searchTerm').value.trim();
const start = document.getElementById('dateStart').value;
const end = document.getElementById('dateEnd').value;
const display = document.getElementById('resultsArea');
if (!term) {
alert("请输入证书编号或持有人姓名");
return;
}
display.innerHTML = '<div class="loading">正在检索数据库...</div>';
try {
let query = sbClient.from('certificates').select('*');
query = query.or(`cert_number.ilike.%${term}%,holder_name.ilike.%${term}%`);
if (start) query = query.gte('issue_date', start);
if (end) query = query.lte('issue_date', end);
const { data, error } = await query.order('issue_date', { ascending: false });
if (error) throw error;
renderResults(data);
} catch (err) {
display.innerHTML = `<div style="color:#dc2626; text-align:center;">检索失败: ${err.message}</div>`;
}
}
function renderResults(data) {
const display = document.getElementById('resultsArea');
if (!data || data.length === 0) {
display.innerHTML = '<div class="no-result">未找到匹配的证书</div>';
return;
}
let html = `
<div class="table-wrapper">
<table class="result-table">
<thead>
<tr>
<th>证书编号</th>
<th>持有人</th>
<th>荣誉标题</th>
<th>颁发日期</th>
<th>操作</th>
</tr>
</thead>
<tbody>
`;
data.forEach(item => {
html += `
<tr>
<td><strong>${item.cert_number}</strong></td>
<td>${item.holder_name}</td>
<td>${item.honor_title}</td>
<td>${item.issue_date || '-'}</td>
<td><a class="btn-link" onclick="goToDetail('${item.id}')">详情</a></td>
</tr>
let html = `
<div class="table-wrapper">
<table class="result-table">
<thead>
<tr>
<th>证书编号</th>
<th>持有人</th>
<th>荣誉标题</th>
<th>颁发日期</th>
<th>操作</th>
</tr>
</thead>
<tbody>
`;
data.forEach(item => {
html += `
<tr>
<td class="table-highlight">${item.cert_number || '-'}</td>
<td>${item.holder_name || '-'}</td>
<td>${item.honor_title || '-'}</td>
<td>${item.issue_date || '-'}</td>
<td><button class="tech-link-button secondary" type="button" onclick="goToDetail('${item.id}')">查看详情</button></td>
</tr>
`;
});
html += '</tbody></table></div>';
display.innerHTML = html;
}
function goToDetail(id) {
window.location.href = `certificate.html?id=${id}`;
}
document.getElementById('searchBtn').addEventListener('click', handleSearch);
document.getElementById('searchTerm').addEventListener('keypress', e => {
if (e.key === 'Enter') handleSearch();
});
html += '</tbody></table></div>';
display.innerHTML = html;
}
function goToDetail(id) {
window.location.href = `certificate.html?id=${id}`;
}
document.getElementById('searchBtn').addEventListener('click', handleSearch);
document.getElementById('searchTerm').addEventListener('keypress', e => {
if (e.key === 'Enter') handleSearch();
});
</script>
<script src="https://cdn.jsdmirror.cn/gh/bishshi/wechat-detect@main/wechat-detect.js"></script>
</script>
<script src="https://cdn.jsdmirror.cn/gh/bishshi/wechat-detect@main/wechat-detect.js"></script>
</body>
</html>
</html>