+2
-122
@@ -61,7 +61,7 @@
|
||||
</aside>
|
||||
</section>
|
||||
|
||||
<section class="detail-panel" id="info-card" style="display: none; margin-top: 18px;">
|
||||
<section class="detail-panel is-hidden mt-18" id="info-card">
|
||||
<div class="section-kicker">Certificate Detail</div>
|
||||
<h2 class="section-heading">证书明细信息</h2>
|
||||
<p class="section-copy">以下信息由证书数据库实时读取,用于核验与归档展示。</p>
|
||||
@@ -84,127 +84,7 @@
|
||||
<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);
|
||||
|
||||
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 || 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-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 = 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-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>';
|
||||
}
|
||||
|
||||
window.currentCertNumber = data.cert_number;
|
||||
} catch (e) {
|
||||
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.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>';
|
||||
}
|
||||
|
||||
img.src = `https://s3.biss.click/CERTS/${encodeURIComponent(certNumber)}.svg`;
|
||||
img.onload = () => {
|
||||
img.style.display = 'block';
|
||||
if (hint) hint.style.display = 'none';
|
||||
};
|
||||
img.onerror = () => {
|
||||
if (hint) {
|
||||
hint.innerHTML = '<span class="hint-orb">!</span><strong>图片加载失败</strong><span>未找到对应证书图片文件</span>';
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
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 = `https://s3.biss.click/CERTS/${encodeURIComponent(certNumber)}.svg`;
|
||||
});
|
||||
}
|
||||
|
||||
async function printCertificate() {
|
||||
try {
|
||||
await ensureCertificateImageLoaded();
|
||||
window.print();
|
||||
} catch (error) {
|
||||
console.error('打印前加载证书失败:', error);
|
||||
alert('证书原件加载失败,无法打印。');
|
||||
}
|
||||
}
|
||||
|
||||
loadData();
|
||||
</script>
|
||||
<script src="../js/certs-certificate.js"></script>
|
||||
<script src="https://cdn.jsdmirror.cn/gh/bishshi/wechat-detect@main/wechat-detect.js"></script>
|
||||
<script src="../js/notice-banner.js"></script>
|
||||
</body>
|
||||
|
||||
+1
-248
@@ -89,254 +89,7 @@
|
||||
<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: 320, height: 140 },
|
||||
aspectRatio: 1.0
|
||||
};
|
||||
|
||||
if (typeof Html5QrcodeSupportedFormats !== 'undefined') {
|
||||
config.formatsToSupport = [
|
||||
Html5QrcodeSupportedFormats.CODE_128,
|
||||
Html5QrcodeSupportedFormats.CODE_39,
|
||||
Html5QrcodeSupportedFormats.CODE_93,
|
||||
Html5QrcodeSupportedFormats.EAN_13,
|
||||
Html5QrcodeSupportedFormats.EAN_8,
|
||||
Html5QrcodeSupportedFormats.UPC_A,
|
||||
Html5QrcodeSupportedFormats.UPC_E,
|
||||
Html5QrcodeSupportedFormats.ITF,
|
||||
Html5QrcodeSupportedFormats.CODABAR
|
||||
];
|
||||
}
|
||||
|
||||
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';
|
||||
}
|
||||
|
||||
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-state">正在连接证书数据库并执行检索...</div>';
|
||||
|
||||
try {
|
||||
let query = sbClient.from('certificates').select('*');
|
||||
query = query.or(`cert_number.ilike.%${term}%,holder_name.ilike.%${term}%,honor_title.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;
|
||||
|
||||
const awardRecipientCounts = await loadAwardRecipientCounts(data);
|
||||
renderResults(data, awardRecipientCounts);
|
||||
} catch (err) {
|
||||
display.innerHTML = `<div class="error-state">检索失败:${err.message}</div>`;
|
||||
}
|
||||
}
|
||||
|
||||
async function loadAwardRecipientCounts(data) {
|
||||
const awardTitles = [...new Set((data || []).map(item => item.honor_title).filter(Boolean))];
|
||||
if (awardTitles.length === 0) return {};
|
||||
|
||||
const countPairs = await Promise.all(awardTitles.map(async title => {
|
||||
const { count, error } = await sbClient
|
||||
.from('certificates')
|
||||
.select('id', { count: 'exact', head: true })
|
||||
.eq('honor_title', title);
|
||||
|
||||
if (error) throw error;
|
||||
return [title, count || 0];
|
||||
}));
|
||||
|
||||
return Object.fromEntries(countPairs);
|
||||
}
|
||||
|
||||
function escapeHtml(value) {
|
||||
return String(value ?? '').replace(/[&<>"']/g, char => ({
|
||||
'&': '&',
|
||||
'<': '<',
|
||||
'>': '>',
|
||||
'"': '"',
|
||||
"'": '''
|
||||
}[char]));
|
||||
}
|
||||
|
||||
function renderAwardStats(data, awardRecipientCounts) {
|
||||
const holderCounts = (data || []).reduce((counts, item) => {
|
||||
const holderName = item.holder_name || '未填写';
|
||||
counts[holderName] = (counts[holderName] || 0) + 1;
|
||||
return counts;
|
||||
}, {});
|
||||
|
||||
const holderStats = Object.entries(holderCounts)
|
||||
.sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0], 'zh-CN'));
|
||||
const maxHolderCount = Math.max(...holderStats.map(([, count]) => count), 1);
|
||||
|
||||
const awardStats = [...new Set((data || []).map(item => item.honor_title).filter(Boolean))]
|
||||
.map(title => ({
|
||||
title,
|
||||
count: awardRecipientCounts[title] || 0
|
||||
}))
|
||||
.sort((a, b) => b.count - a.count || a.title.localeCompare(b.title, 'zh-CN'));
|
||||
|
||||
const holderBars = holderStats.map(([name, count]) => `
|
||||
<div class="chart-row">
|
||||
<div class="chart-row-label" title="${escapeHtml(name)}">${escapeHtml(name)}</div>
|
||||
<div class="chart-bar-track">
|
||||
<div class="chart-bar-fill" style="width: ${Math.max((count / maxHolderCount) * 100, 6)}%;"></div>
|
||||
</div>
|
||||
<div class="chart-row-value">${count} 项</div>
|
||||
</div>
|
||||
`).join('');
|
||||
|
||||
const awardChips = awardStats.map(item => `
|
||||
<div class="award-count-chip">
|
||||
<span class="award-count-title" title="${escapeHtml(item.title)}">${escapeHtml(item.title)}</span>
|
||||
<strong>${item.count}</strong>
|
||||
<span>人获得</span>
|
||||
</div>
|
||||
`).join('');
|
||||
|
||||
return `
|
||||
<div class="results-summary">
|
||||
<div class="summary-stat-tile">
|
||||
<span>查询结果</span>
|
||||
<strong>${data.length}</strong>
|
||||
</div>
|
||||
<div class="summary-stat-tile">
|
||||
<span>涉及人员</span>
|
||||
<strong>${holderStats.length}</strong>
|
||||
</div>
|
||||
<div class="summary-stat-tile">
|
||||
<span>奖项种类</span>
|
||||
<strong>${awardStats.length}</strong>
|
||||
</div>
|
||||
</div>
|
||||
<div class="stats-grid">
|
||||
<section class="stats-panel">
|
||||
<div class="stats-panel-title">个人奖项数量</div>
|
||||
<div class="bar-chart">${holderBars}</div>
|
||||
</section>
|
||||
<section class="stats-panel">
|
||||
<div class="stats-panel-title">查询奖项获得人数</div>
|
||||
<div class="award-count-grid">${awardChips || '<div class="muted-note">暂无奖项名称</div>'}</div>
|
||||
</section>
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
|
||||
function renderResults(data, awardRecipientCounts = {}) {
|
||||
const display = document.getElementById('resultsArea');
|
||||
if (!data || data.length === 0) {
|
||||
display.innerHTML = '<div class="empty-state">未找到匹配的证书记录。</div>';
|
||||
return;
|
||||
}
|
||||
|
||||
let html = `
|
||||
${renderAwardStats(data, awardRecipientCounts)}
|
||||
<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">${escapeHtml(item.cert_number || '-')}</td>
|
||||
<td>${escapeHtml(item.holder_name || '-')}</td>
|
||||
<td>${escapeHtml(item.honor_title || '-')}</td>
|
||||
<td>${escapeHtml(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}`;
|
||||
}
|
||||
|
||||
function initializeSearchTermFromUrl() {
|
||||
const params = new URLSearchParams(window.location.search);
|
||||
const presetTerm =
|
||||
params.get('searchTerm') ||
|
||||
params.get('term') ||
|
||||
params.get('keyword') ||
|
||||
params.get('cert_number') ||
|
||||
params.get('certNumber') ||
|
||||
params.get('number') ||
|
||||
params.get('awardName') ||
|
||||
params.get('honor_title') ||
|
||||
params.get('honorTitle') ||
|
||||
params.get('award') ||
|
||||
params.get('q') ||
|
||||
'';
|
||||
|
||||
if (presetTerm) {
|
||||
document.getElementById('searchTerm').value = presetTerm;
|
||||
}
|
||||
}
|
||||
|
||||
document.getElementById('searchBtn').addEventListener('click', handleSearch);
|
||||
document.getElementById('searchTerm').addEventListener('keypress', e => {
|
||||
if (e.key === 'Enter') handleSearch();
|
||||
});
|
||||
initializeSearchTermFromUrl();
|
||||
</script>
|
||||
<script src="../js/certs-index.js"></script>
|
||||
<script src="https://cdn.jsdmirror.cn/gh/bishshi/wechat-detect@main/wechat-detect.js"></script>
|
||||
<script src="../js/notice-banner.js"></script>
|
||||
</body>
|
||||
|
||||
Reference in New Issue
Block a user