418 lines
9.6 KiB
HTML
418 lines
9.6 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="zh-CN">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>PC装机配置表</title>
|
|
<style>
|
|
* { margin: 0; padding: 0; box-sizing: border-box; }
|
|
|
|
body {
|
|
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
|
|
background: #f0f2f5;
|
|
color: #333;
|
|
min-height: 100vh;
|
|
}
|
|
|
|
.container {
|
|
max-width: 1100px;
|
|
margin: 0 auto;
|
|
padding: 20px;
|
|
}
|
|
|
|
/* Header */
|
|
.header {
|
|
background: #fff;
|
|
border-radius: 12px;
|
|
padding: 20px 24px;
|
|
margin-bottom: 20px;
|
|
box-shadow: 0 2px 8px rgba(0,0,0,0.06);
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: space-between;
|
|
flex-wrap: wrap;
|
|
gap: 12px;
|
|
}
|
|
|
|
.header h1 {
|
|
font-size: 22px;
|
|
font-weight: 600;
|
|
color: #1a1a1a;
|
|
}
|
|
|
|
/* Table */
|
|
.config-table-wrap {
|
|
background: #fff;
|
|
border-radius: 12px;
|
|
box-shadow: 0 2px 8px rgba(0,0,0,0.06);
|
|
overflow: hidden;
|
|
margin-bottom: 80px;
|
|
}
|
|
|
|
.config-table {
|
|
width: 100%;
|
|
border-collapse: collapse;
|
|
font-size: 14px;
|
|
}
|
|
|
|
.config-table thead { background: #fafafa; }
|
|
|
|
.config-table th {
|
|
padding: 12px 16px;
|
|
text-align: left;
|
|
font-weight: 600;
|
|
color: #666;
|
|
font-size: 13px;
|
|
border-bottom: 1px solid #f0f0f0;
|
|
white-space: nowrap;
|
|
}
|
|
|
|
.config-table td {
|
|
padding: 12px 16px;
|
|
border-bottom: 1px solid #f0f0f0;
|
|
vertical-align: middle;
|
|
}
|
|
|
|
.config-table tbody tr:last-child td { border-bottom: none; }
|
|
.config-table tbody tr:hover { background: #fafafa; }
|
|
|
|
/* Image cell */
|
|
.cell-img {
|
|
width: 64px;
|
|
height: 64px;
|
|
border-radius: 8px;
|
|
object-fit: contain;
|
|
background: #f5f5f5;
|
|
border: 1px solid #eee;
|
|
cursor: pointer;
|
|
transition: transform 0.2s;
|
|
}
|
|
|
|
.cell-img:hover { transform: scale(1.05); }
|
|
|
|
.cell-img-placeholder {
|
|
width: 64px;
|
|
height: 64px;
|
|
border-radius: 8px;
|
|
background: #f5f5f5;
|
|
border: 1px solid #eee;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
color: #ccc;
|
|
font-size: 20px;
|
|
}
|
|
|
|
/* Type badge */
|
|
.type-badge {
|
|
font-size: 13px;
|
|
font-weight: 600;
|
|
color: #1677ff;
|
|
background: #e6f4ff;
|
|
padding: 4px 10px;
|
|
border-radius: 6px;
|
|
display: inline-block;
|
|
}
|
|
|
|
/* Price cell */
|
|
.price-cell {
|
|
font-weight: 700;
|
|
color: #ff4d4f;
|
|
white-space: nowrap;
|
|
}
|
|
|
|
.price-cell .currency { font-size: 12px; font-weight: 500; }
|
|
|
|
/* Link cell */
|
|
.link-cell a {
|
|
color: #1677ff;
|
|
text-decoration: none;
|
|
font-size: 13px;
|
|
}
|
|
.link-cell a:hover { text-decoration: underline; }
|
|
|
|
/* Alt selector */
|
|
.alt-selector { margin-top: 4px; }
|
|
|
|
.alt-label {
|
|
font-size: 11px;
|
|
color: #999;
|
|
margin-bottom: 4px;
|
|
}
|
|
|
|
.alt-options {
|
|
display: flex;
|
|
gap: 4px;
|
|
flex-wrap: wrap;
|
|
}
|
|
|
|
.alt-pill {
|
|
padding: 3px 8px;
|
|
border: 1px solid #e8e8e8;
|
|
border-radius: 4px;
|
|
font-size: 11px;
|
|
cursor: pointer;
|
|
background: #fff;
|
|
color: #666;
|
|
transition: all 0.2s;
|
|
}
|
|
|
|
.alt-pill:hover { border-color: #1677ff; color: #1677ff; }
|
|
.alt-pill.active { border-color: #1677ff; background: #e6f4ff; color: #1677ff; font-weight: 500; }
|
|
|
|
/* Footer / Total */
|
|
.footer {
|
|
position: fixed;
|
|
bottom: 0;
|
|
left: 0;
|
|
right: 0;
|
|
background: #fff;
|
|
box-shadow: 0 -2px 8px rgba(0,0,0,0.08);
|
|
padding: 16px 24px;
|
|
z-index: 100;
|
|
}
|
|
|
|
.footer-inner {
|
|
max-width: 1100px;
|
|
margin: 0 auto;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: space-between;
|
|
}
|
|
|
|
.footer-label { font-size: 14px; color: #666; }
|
|
|
|
.footer-total {
|
|
font-size: 28px;
|
|
font-weight: 700;
|
|
color: #ff4d4f;
|
|
}
|
|
|
|
.footer-total .currency { font-size: 16px; }
|
|
|
|
/* Empty State */
|
|
.empty-state {
|
|
text-align: center;
|
|
padding: 60px 20px;
|
|
color: #999;
|
|
}
|
|
|
|
.empty-state p { margin-bottom: 16px; font-size: 15px; }
|
|
|
|
/* Lightbox */
|
|
.lightbox {
|
|
display: none;
|
|
position: fixed;
|
|
inset: 0;
|
|
background: rgba(0,0,0,0.85);
|
|
z-index: 2000;
|
|
justify-content: center;
|
|
align-items: center;
|
|
cursor: pointer;
|
|
}
|
|
|
|
.lightbox.active { display: flex; }
|
|
|
|
.lightbox img {
|
|
max-width: 90vw;
|
|
max-height: 90vh;
|
|
border-radius: 8px;
|
|
box-shadow: 0 4px 24px rgba(0,0,0,0.4);
|
|
}
|
|
|
|
.lightbox-close {
|
|
position: absolute;
|
|
top: 20px;
|
|
right: 24px;
|
|
background: rgba(255,255,255,0.2);
|
|
border: none;
|
|
color: #fff;
|
|
font-size: 28px;
|
|
cursor: pointer;
|
|
width: 40px;
|
|
height: 40px;
|
|
border-radius: 50%;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
transition: background 0.2s;
|
|
}
|
|
|
|
.lightbox-close:hover { background: rgba(255,255,255,0.3); }
|
|
|
|
/* Responsive */
|
|
@media (max-width: 768px) {
|
|
.container { padding: 12px; }
|
|
.header { padding: 16px; }
|
|
.config-table-wrap { overflow-x: auto; }
|
|
.config-table { min-width: 700px; }
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
|
|
<div class="container">
|
|
<div class="header">
|
|
<div>
|
|
<h1 id="configName">PC装机配置表</h1>
|
|
<div id="configMeta" style="font-size:12px;color:#999;margin-top:4px"></div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="contentArea"></div>
|
|
</div>
|
|
|
|
<!-- Footer Total -->
|
|
<div class="footer">
|
|
<div class="footer-inner">
|
|
<span class="footer-label">总计</span>
|
|
<span class="footer-total"><span class="currency">¥</span><span id="totalPrice">0</span></span>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Lightbox -->
|
|
<div class="lightbox" id="lightbox" onclick="closeLightbox()">
|
|
<button class="lightbox-close">×</button>
|
|
<img id="lightboxImg" src="" alt="">
|
|
</div>
|
|
|
|
<script>
|
|
// ========== State ==========
|
|
let config = { configName: 'PC装机配置表', components: [] };
|
|
|
|
// ========== Init ==========
|
|
document.addEventListener('DOMContentLoaded', loadFromURL);
|
|
|
|
function loadFromURL() {
|
|
const params = new URLSearchParams(window.location.search);
|
|
const configURL = params.get('config');
|
|
if (configURL) {
|
|
fetch(configURL)
|
|
.then(r => { if (!r.ok) throw new Error(`HTTP ${r.status}`); return r.json(); })
|
|
.then(data => { config = data; document.getElementById('configName').textContent = config.configName || 'PC装机配置表'; updateMeta(); render(); })
|
|
.catch(err => { console.error('加载配置失败:', err); render(); });
|
|
} else {
|
|
render();
|
|
}
|
|
}
|
|
|
|
// ========== Meta ==========
|
|
function updateMeta() {
|
|
const meta = document.getElementById('configMeta');
|
|
const parts = [];
|
|
if (config.version) parts.push('v' + config.version);
|
|
if (config.updatedAt) {
|
|
const d = new Date(config.updatedAt);
|
|
parts.push('更新于 ' + d.toLocaleDateString('zh-CN') + ' ' + d.toLocaleTimeString('zh-CN', {hour:'2-digit', minute:'2-digit'}));
|
|
}
|
|
meta.textContent = parts.join(' · ');
|
|
}
|
|
|
|
// ========== Render ==========
|
|
function render() {
|
|
const area = document.getElementById('contentArea');
|
|
|
|
if (!config.components || config.components.length === 0) {
|
|
area.innerHTML = `
|
|
<div class="empty-state">
|
|
<p>暂无配置数据</p>
|
|
</div>`;
|
|
updateTotal();
|
|
return;
|
|
}
|
|
|
|
let rows = config.components.map((comp, i) => {
|
|
const selectedIdx = comp.selected || 0;
|
|
const opt = comp.options[selectedIdx];
|
|
if (!opt) return '';
|
|
|
|
const imgCell = opt.image
|
|
? `<img class="cell-img" src="${opt.image}" alt="${opt.model}" onclick="openLightbox('${opt.image.replace(/'/g, "\\'")}', '${opt.model.replace(/'/g, "\\'")}')" onerror="this.outerHTML='<div class=\\'cell-img-placeholder\\'> </div>'">`
|
|
: '<div class="cell-img-placeholder"> </div>';
|
|
|
|
const linkCell = opt.link
|
|
? `<a href="${opt.link}" target="_blank" rel="noopener">🔗链接</a>`
|
|
: '-';
|
|
|
|
const altCell = comp.options.length > 1 ? `
|
|
<div class="alt-selector">
|
|
<div class="alt-label">备选 (${comp.options.length})</div>
|
|
<div class="alt-options">
|
|
${comp.options.map((o, j) => `
|
|
<button class="alt-pill ${j === selectedIdx ? 'active' : ''}" onclick="selectAlt(${i}, ${j})">
|
|
${o.model}
|
|
</button>
|
|
`).join('')}
|
|
</div>
|
|
</div>` : '';
|
|
|
|
return `
|
|
<tr>
|
|
<td>${imgCell}</td>
|
|
<td><span class="type-badge">${comp.type}</span></td>
|
|
<td>${opt.brand || '-'}</td>
|
|
<td>${opt.model || '-'}</td>
|
|
<td>${opt.specs || '-'}</td>
|
|
<td class="price-cell"><span class="currency">¥</span>${(opt.price || 0).toLocaleString()}</td>
|
|
<td class="link-cell">${linkCell}</td>
|
|
<td>${altCell}</td>
|
|
</tr>`;
|
|
}).join('');
|
|
|
|
area.innerHTML = `
|
|
<div class="config-table-wrap">
|
|
<table class="config-table">
|
|
<thead>
|
|
<tr>
|
|
<th style="width:72px">图片</th>
|
|
<th style="width:90px">类型</th>
|
|
<th style="width:72px">品牌</th>
|
|
<th style="width:130px">型号</th>
|
|
<th>参数</th>
|
|
<th style="width:90px">价格</th>
|
|
<th style="width:80px">链接</th>
|
|
<th style="width:220px">备选</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>${rows}</tbody>
|
|
</table>
|
|
</div>`;
|
|
|
|
updateTotal();
|
|
}
|
|
|
|
// ========== Total Price ==========
|
|
function updateTotal() {
|
|
const total = (config.components || []).reduce((sum, comp) => {
|
|
const opt = comp.options[comp.selected || 0];
|
|
return sum + (opt ? (opt.price || 0) : 0);
|
|
}, 0);
|
|
document.getElementById('totalPrice').textContent = total.toLocaleString();
|
|
}
|
|
|
|
// ========== Select Alternative ==========
|
|
function selectAlt(compIndex, altIndex) {
|
|
config.components[compIndex].selected = altIndex;
|
|
render();
|
|
}
|
|
|
|
// ========== Lightbox ==========
|
|
function openLightbox(src, alt) {
|
|
document.getElementById('lightboxImg').src = src;
|
|
document.getElementById('lightboxImg').alt = alt || '';
|
|
document.getElementById('lightbox').classList.add('active');
|
|
}
|
|
|
|
function closeLightbox() {
|
|
document.getElementById('lightbox').classList.remove('active');
|
|
}
|
|
|
|
// ========== Keyboard ==========
|
|
document.addEventListener('keydown', (e) => {
|
|
if (e.key === 'Escape') { closeLightbox(); }
|
|
});
|
|
</script>
|
|
|
|
</body>
|
|
</html>
|