120 lines
5.4 KiB
JavaScript
120 lines
5.4 KiB
JavaScript
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();
|