feat: 统一文件上传接口 + 模板图片展示 + 导航页 + 侧边栏调整
This commit is contained in:
17
web/dist/shop3/index.html
vendored
17
web/dist/shop3/index.html
vendored
@@ -1219,7 +1219,8 @@ function renderProducts(products, total) {
|
||||
return `
|
||||
<div class="product-card" onclick="showProductDetail(${p.id})">
|
||||
<div class="product-img">
|
||||
<div class="product-img-fill" style="background:${getGradient(p.category_id)}">${productIconSVG(p.category_id)}</div>
|
||||
${p.image ? `<img src="${p.image}" style="position:absolute;inset:0;width:100%;height:100%;object-fit:cover" onerror="this.style.display='none';this.nextElementSibling.style.display='flex'">` : ''}
|
||||
<div class="product-img-fill" style="background:${getGradient(p.category_id)};${p.image ? 'display:none' : 'display:flex'}">${productIconSVG(p.category_id)}</div>
|
||||
<div class="product-tags">${tagHtml}</div>
|
||||
<button class="product-wish" onclick="event.stopPropagation();showToast('已加入心愿单')" title="加入心愿单">
|
||||
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor"><path d="M20.84 4.61a5.5 5.5 0 0 0-7.78 0L12 5.67l-1.06-1.06a5.5 5.5 0 0 0-7.78 7.78l1.06 1.06L12 21.23l7.78-7.78 1.06-1.06a5.5 5.5 0 0 0 0-7.78z"/></svg>
|
||||
@@ -1306,13 +1307,21 @@ async function showProductDetail(id) {
|
||||
productCache[id] = p;
|
||||
let tags = [];
|
||||
try { tags = JSON.parse(p.tags || '[]'); } catch (e) {}
|
||||
let imgList = [];
|
||||
try { imgList = JSON.parse(p.images || '[]'); } catch(e) {}
|
||||
if (!Array.isArray(imgList)) imgList = [];
|
||||
if (p.image) imgList = [p.image, ...imgList.filter(img => img !== p.image)];
|
||||
const discount = p.original_price > p.price ? Math.round((1 - p.price / p.original_price) * 100) : 0;
|
||||
const rating = typeof p.rating === 'number' ? p.rating : 0;
|
||||
const stock = typeof p.stock === 'number' ? p.stock : 0;
|
||||
|
||||
content.innerHTML = `
|
||||
<button class="modal-close" onclick="closeModal()">×</button>
|
||||
<div class="modal-img" style="background:${getGradient(p.category_id)}">${productIconSVG(p.category_id)}</div>
|
||||
<div class="modal-img" style="background:${getGradient(p.category_id)};position:relative;overflow:hidden">
|
||||
${imgList.length > 0 ? `<img id="modalMainImg" src="${imgList[0]}" style="position:absolute;inset:0;width:100%;height:100%;object-fit:cover" onerror="this.style.display='none';this.nextElementSibling.style.display=''">` : ''}
|
||||
<div style="${imgList.length > 0 ? 'display:none' : ''}">${productIconSVG(p.category_id)}</div>
|
||||
${imgList.length > 1 ? `<div style="position:absolute;bottom:8px;left:0;right:0;display:flex;gap:6px;justify-content:center;z-index:5">${imgList.map((img,idx) => `<img src="${img}" onclick="document.getElementById('modalMainImg').src=this.src" style="width:40px;height:40px;border-radius:4px;object-fit:cover;cursor:pointer;border:2px solid ${idx===0?'#fff':'rgba(255,255,255,0.5)'}" onerror="this.remove()">`).join('')}</div>` : ''}
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<div class="modal-cat">${categoryName(p.category_id)} · NORDI 严选</div>
|
||||
<h2>${p.name}</h2>
|
||||
@@ -1375,7 +1384,7 @@ async function addToCart(productId, qty = 1) {
|
||||
}
|
||||
const existing = cart.find(i => i.id === productId);
|
||||
if (existing) existing.qty += qty;
|
||||
else cart.push({ id: productId, name: product.name, price: Number(product.price), qty, category_id: product.category_id });
|
||||
else cart.push({ id: productId, name: product.name, price: Number(product.price), qty, category_id: product.category_id, image: product.image || '' });
|
||||
updateCartUI();
|
||||
showToast(`已加入购物袋 · ${product.name.length > 14 ? product.name.substring(0, 14) + '…' : product.name}`);
|
||||
}
|
||||
@@ -1410,7 +1419,7 @@ function updateCartUI() {
|
||||
}
|
||||
container.innerHTML = cart.map(item => `
|
||||
<div class="cart-item">
|
||||
<div class="cart-item-img" style="background:${getGradient(item.category_id)}">${productIconSVG(item.category_id)}</div>
|
||||
<div class="cart-item-img" style="background:${getGradient(item.category_id)};position:relative;overflow:hidden">${item.image ? `<img src="${item.image}" style="position:absolute;inset:0;width:100%;height:100%;object-fit:cover" onerror="this.remove()">` : ''}${productIconSVG(item.category_id)}</div>
|
||||
<div class="cart-item-info">
|
||||
<div class="cart-item-name">${item.name}</div>
|
||||
<div class="cart-item-price">$${item.price.toFixed(2)}</div>
|
||||
|
||||
Reference in New Issue
Block a user