Compare commits

..

2 Commits

2 changed files with 93 additions and 55 deletions
+47 -26
View File
@@ -58,11 +58,13 @@
.deals-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.deal-card { background: var(--card); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); cursor: pointer; transition: transform 0.15s; }
.deal-card:active { transform: scale(0.98); }
.deal-img { width: 100%; height: 90px; background: #f3f4f6; border-radius: 8px; margin-bottom: 10px; display: flex; align-items: center; justify-content: center; font-size: 32px; }
.deal-title { font-size: 13px; font-weight: 600; color: var(--text); margin-bottom: 6px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.deal-img { width: 100%; height: 100px; background: linear-gradient(135deg, #f3f4f6, #e5e7eb); border-radius: 8px; margin-bottom: 10px; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.deal-img img { width: 100%; height: 100%; object-fit: cover; }
.deal-title { font-size: 13px; font-weight: 600; color: var(--text); margin-bottom: 6px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; line-height: 1.4; height: 2.8em; }
.deal-price { color: #ef4444; font-weight: 700; font-size: 16px; }
.deal-price span { font-size: 12px; }
.deal-tag { display: inline-block; background: #fef2f2; color: #ef4444; font-size: 10px; padding: 2px 6px; border-radius: 4px; margin-left: 6px; font-weight: 600; }
.deal-price span { font-size: 12px; text-decoration: line-through; color: #9ca3af; margin-left: 4px; }
.deal-tag { display: inline-block; background: linear-gradient(135deg, #ef4444, #f97316); color: white; font-size: 10px; padding: 2px 6px; border-radius: 4px; margin-left: 6px; font-weight: 600; }
.deal-commission { font-size: 11px; color: var(--primary); margin-top: 4px; font-weight: 600; }
/* Linbao List */
.linbao-list { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
@@ -79,10 +81,15 @@
.product-item { padding: 14px 16px; border-bottom: 1px solid var(--border); display: flex; gap: 12px; cursor: pointer; transition: background 0.15s; }
.product-item:last-child { border-bottom: none; }
.product-item:active { background: #f9fafb; }
.product-img { width: 72px; height: 72px; background: #f3f4f6; border-radius: 8px; display: flex; align-items: center; justify-content: center; font-size: 28px; flex-shrink: 0; }
.product-img { width: 72px; height: 72px; background: linear-gradient(135deg, #f3f4f6, #e5e7eb); border-radius: 8px; display: flex; align-items: center; justify-content: center; font-size: 28px; flex-shrink: 0; overflow: hidden; }
.product-img img { width: 100%; height: 100%; object-fit: cover; }
.product-info { flex: 1; min-width: 0; }
.product-title { font-size: 13px; font-weight: 600; color: var(--text); margin-bottom: 4px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.product-shop { font-size: 11px; color: var(--text-light); margin-bottom: 6px; }
.product-shop { font-size: 11px; color: var(--text-light); margin-bottom: 6px; display: flex; align-items: center; gap: 6px; }
.platform-badge { display: inline-block; padding: 1px 4px; border-radius: 3px; font-size: 10px; font-weight: 600; color: white; }
.platform-badge.taobao { background: #ff5000; }
.platform-badge.jd { background: #c00; }
.platform-badge.pinduoduo { background: #c00; }
.product-bottom { display: flex; align-items: center; justify-content: space-between; }
.product-price { color: #ef4444; font-weight: 700; font-size: 15px; }
.product-coupon { background: var(--primary); color: white; font-size: 11px; padding: 3px 8px; border-radius: 4px; font-weight: 600; }
@@ -137,15 +144,15 @@
</div>
<div class="stats">
<div class="stat">
<div class="stat-value" id="statDeals">0</div>
<div class="stat-value" id="statDeals">6</div>
<div class="stat-label">今日特价</div>
</div>
<div class="stat">
<div class="stat-value" id="statCoupon">0</div>
<div class="stat-value" id="statCoupon">2</div>
<div class="stat-label">覆盖平台</div>
</div>
<div class="stat">
<div class="stat-value">¥0</div>
<div class="stat-value" id="statSaved">¥12</div>
<div class="stat-label">已帮省下</div>
</div>
</div>
@@ -211,9 +218,12 @@
// State
let currentTab = 'home';
// API Base
// API Base - 留空使用相对路径,服务器通过nginx转发/api到后端
const API_BASE = '';
// Platform config
const PLATFORM_NAME = { taobao: '淘宝', jd: '京东', pinduoduo: '拼多多' };
// DOM Elements
const searchInput = document.getElementById('searchInput');
const searchBtn = document.getElementById('searchBtn');
@@ -231,7 +241,7 @@
await Promise.all([loadDeals(), loadLinbao()]);
updateStats();
apiDot.classList.add('active');
apiStatusEl.textContent = '本地运行';
apiStatusEl.textContent = '服务正常';
}
// Load Deals
@@ -255,11 +265,11 @@
return;
}
dealsGrid.innerHTML = deals.map(deal => `
<div class="deal-card" onclick="openDeal('${deal.id}')">
<div class="deal-img">🏷️</div>
<div class="deal-title">${deal.title}</div>
<div class="deal-price">¥${deal.price}<span style="text-decoration:line-through;color:#9ca3af;font-size:11px;margin-left:4px;">¥${deal.originalPrice}</span></div>
<div style="margin-top:6px;"><span class="deal-tag">${deal.discount}</span></div>
<div class="deal-card" onclick='openDeal(${JSON.stringify(deal)})'>
<div class="deal-img"><img src="https://picsum.photos/seed/${deal.id}/200/200" alt="${deal.title}" loading="lazy" onerror="this.style.display='none'"></div>
<div class="deal-title" style="margin-top:4px;"><span class="platform-badge ${deal.platform}" style="font-size:9px;margin-right:4px;">${PLATFORM_NAME[deal.platform] || deal.platform}</span>${deal.title}</div>
<div class="deal-price">¥${deal.price}<span${deal.originalPrice}</span><span class="deal-tag">${deal.discount}</span></div>
<div class="deal-commission">🎁 预估返 ¥${deal.commission || 0}</div>
</div>
`).join('');
}
@@ -271,7 +281,6 @@
const json = await res.json();
if (json.success) {
renderLinbao(json.data);
statCoupon.textContent = json.data.length;
}
} catch (e) {
linbaoList.innerHTML = '<div class="empty-state"><div class="empty-icon">📢</div><div class="empty-text">暂无线报</div></div>';
@@ -285,7 +294,7 @@
return;
}
linbaoList.innerHTML = items.map(item => `
<div class="linbao-item" onclick="openLinbao('${item.id}')">
<div class="linbao-item" onclick="window.open('${item.url || '#'}', '_blank')">
<div class="linbao-top">
<div class="linbao-title">${item.title}</div>
<span class="linbao-hot">🔥 ${item.hot}</span>
@@ -319,15 +328,16 @@
// Render Search Results
function renderSearchResults(products) {
searchResults.innerHTML = products.map(p => `
<div class="product-item" onclick="goToCoupon('${p.id}')">
<div class="product-img">🏷️</div>
<div class="product-item" onclick='goToCoupon(${JSON.stringify(p)})'>
<div class="product-img"><img src="https://picsum.photos/seed/${p.id}/200/200" alt="${p.title}" loading="lazy" onerror="this.parentElement.innerHTML='🏷️'"></div>
<div class="product-info">
<div class="product-title">${p.title}</div>
<div class="product-shop">🏪 ${p.shop}</div>
<div class="product-shop"><span class="platform-badge ${p.platform}">${PLATFORM_NAME[p.platform] || p.platform}</span> ${p.shop}</div>
<div class="product-bottom">
<span class="product-price">¥${p.price}</span>
<span class="product-coupon">${p.coupon}券</span>
<span class="product-coupon">${p.coupon}券</span>
</div>
<div style="font-size:11px;color:var(--text-light);margin-top:4px;">🎁 返 ¥${p.commission || 0}</div>
</div>
</div>
`).join('');
@@ -338,10 +348,21 @@
// Stats updated from data
}
// Placeholder actions
function openDeal(id) { console.log('open deal', id); }
function openLinbao(id) { console.log('open linbao', id); }
function goToCoupon(id) { console.log('go to coupon', id); alert('请复制链接到淘宝/京东app打开'); }
// Actions
function openDeal(deal) {
if (deal.link && deal.link !== '#') {
window.open(deal.link, '_blank');
} else {
alert('复制商品链接,请在淘宝/京东App打开购买~');
}
}
function goToCoupon(product) {
if (product.link && product.link !== '#') {
window.open(product.link, '_blank');
} else {
alert('复制商品链接,请在淘宝/京东App打开购买~');
}
}
// Event Listeners
searchBtn.addEventListener('click', () => doSearch(searchInput.value));
+46 -29
View File
@@ -65,57 +65,74 @@ function generateMockResults(keyword) {
return [
{
id: '1',
title: `${keyword} 空气炸锅 智能`,
price: 199,
originalPrice: 299,
coupon: 50,
title: `苏泊尔空气炸锅5.5L大容量${keyword}智能`,
price: 189,
originalPrice: 399,
coupon: 60,
commission: 15,
shop: '某某电器旗舰店',
link: '#',
platform: 'taobao'
shop: '苏泊尔官方旗舰店',
link: 'https://s.click.taobao.com/abc123',
platform: 'taobao',
img: 'https://img.alicdn.com/bao/uploaded/O1CN01Z1a2b3_!!600000000.jpg'
},
{
id: '2',
title: `${keyword} 破壁机 多功能`,
title: `九阳破壁机L12-Y5多功能全自动${keyword}`,
price: 299,
originalPrice: 499,
coupon: 80,
originalPrice: 699,
coupon: 100,
commission: 25,
shop: '厨房电器专营店',
link: '#',
platform: 'taobao'
shop: '九阳厨房电器旗舰店',
link: 'https://s.click.taobao.com/def456',
platform: 'taobao',
img: 'https://img.alicdn.com/bao/uploaded/O1CN01C3d4e5_!!600000000.jpg'
},
{
id: '3',
title: `${keyword} 电饭煲 智能预约`,
title: `美的${keyword}电饭煲MB-RE476智能预约`,
price: 159,
originalPrice: 259,
coupon: 40,
originalPrice: 399,
coupon: 50,
commission: 12,
shop: '品牌电器直营',
link: '#',
platform: 'jd'
shop: '美的官方旗舰店',
link: 'https://u.jd.com/gh789',
platform: 'jd',
img: 'https://img.alicdn.com/bao/uploaded/O1CN01F6h7i8_!!600000000.jpg'
},
{
id: '4',
title: `小米手环8 NFC版${keyword}运动健康监测`,
price: 229,
originalPrice: 399,
coupon: 30,
commission: 18,
shop: '小米官方旗舰店',
link: 'https://s.click.taobao.com/jkl012',
platform: 'taobao',
img: 'https://img.alicdn.com/bao/uploaded/O1CN01G8m9n0_!!600000000.jpg'
}
];
}
function generateMockDeals() {
return [
{ id: 'd1', title: '苏泊尔空气炸锅', price: 189, originalPrice: 299, discount: '63折', endTime: '2026-06-05' },
{ id: 'd2', title: '九阳破壁机', price: 299, originalPrice: 599, discount: '5折', endTime: '2026-06-05' },
{ id: 'd3', title: '美的电饭煲', price: 159, originalPrice: 299, discount: '53折', endTime: '2026-06-05' },
{ id: 'd4', title: '小米手环8', price: 199, originalPrice: 299, discount: '67折', endTime: '2026-06-06' },
{ id: 'd5', title: '华为手表GT4', price: 899, originalPrice: 1488, discount: '6折', endTime: '2026-06-07' }
{ id: 'd1', title: '苏泊尔空气炸锅5.5L大容量智能款', price: 189, originalPrice: 399, discount: '47折', endTime: '2026-06-25', img: 'https://img.alicdn.com/bao/uploaded/O1CN01abc123_!!600000000.jpg', platform: 'taobao', commission: 15 },
{ id: 'd2', title: '九阳破壁机L12-Y536多功能全自动', price: 299, originalPrice: 699, discount: '43折', endTime: '2026-06-25', img: 'https://img.alicdn.com/bao/uploaded/O1CN01def456_!!600000000.jpg', platform: 'taobao', commission: 25 },
{ id: 'd3', title: '美的电饭煲MB-RE476智能预约', price: 159, originalPrice: 399, discount: '40折', endTime: '2026-06-23', img: 'https://img.alicdn.com/bao/uploaded/O1CN01ghi789_!!600000000.jpg', platform: 'jd', commission: 12 },
{ id: 'd4', title: '小米手环8 NFC版运动健康', price: 229, originalPrice: 399, discount: '57折', endTime: '2026-06-26', img: 'https://img.alicdn.com/bao/uploaded/O1CN01jkl012_!!600000000.jpg', platform: 'taobao', commission: 18 },
{ id: 'd5', title: '戴森吹风机HD15负离子护发', price: 2199, originalPrice: 3299, discount: '67折', endTime: '2026-06-28', img: 'https://img.alicdn.com/bao/uploaded/O1CN01mno345_!!600000000.jpg', platform: 'taobao', commission: 180 },
{ id: 'd6', title: '添可洗地机2.0 LED智能清洁', price: 1499, originalPrice: 2599, discount: '58折', endTime: '2026-06-24', img: 'https://img.alicdn.com/bao/uploaded/O1CN01pqr678_!!600000000.jpg', platform: 'jd', commission: 120 }
];
}
function generateMockLinbao() {
return [
{ id: 'l1', title: '淘宝618预售开启付定金可抵双倍', source: '官方', time: '10分钟前', hot: 98 },
{ id: 'l2', title: '美团外卖新用户立减15元', source: '美团', time: '30分钟前', hot: 85 },
{ id: 'l3', title: '京东闪购不定时放大额券', source: '京东', time: '1小时前', hot: 92 },
{ id: 'l4', title: '饿了么端午红包来袭', source: '饿了么', time: '2小时前', hot: 78 },
{ id: 'l5', title: '拼多多百亿补贴再加码', source: '拼多多', time: '3小时前', hot: 88 }
{ id: 'l1', title: '🎉 淘宝618预售开启付定金可抵双倍AirPods Pro低至999', source: '官方公告', time: '10分钟前', hot: 98, url: 'https://taobao.com' },
{ id: 'l2', title: '🔥 京东PLUS会员专属大额券,500-50全场通用', source: '京东', time: '30分钟前', hot: 92, url: 'https://jd.com' },
{ id: 'l3', title: '💰 美团外卖新用户首单立减15元,红包秒到账', source: '美团', time: '1小时前', hot: 85, url: 'https://meituan.com' },
{ id: 'l4', title: '🛒 拼多多百亿补贴再加码,iPhone15 Pro Max直降500', source: '拼多多', time: '2小时前', hot: 95, url: 'https://pinduoduo.com' },
{ id: 'l5', title: '⏰ 饿了么端午粽子专场,满39减10', source: '饿了么', time: '3小时前', hot: 78, url: 'https://elem.com' },
{ id: 'l6', title: '📱 抖音618好物节,直播间专属优惠来袭', source: '抖音', time: '4小时前', hot: 88, url: 'https://douyin.com' }
];
}