// Live Stream Page JavaScript $(document).ready(function() { initLivePage(); }); function initLivePage() { loadChatMessages(); loadLiveProducts(); updateLiveStats(); bindLiveEvents(); // 监听语言切换 $(document).on('languageChanged', function() { loadChatMessages(); loadLiveProducts(); }); // 自动滚动到最新消息 scrollChatToBottom(); // 模拟实时更新统计数据 setInterval(updateLiveStats, 5000); // 模拟新消息 setInterval(addRandomMessage, 10000); } // 绑定事件 function bindLiveEvents() { // Tab切换 $('.tab-btn').on('click', function() { const tabName = $(this).data('tab'); switchTab(tabName); }); // 发送消息 $('#sendMessageBtn').on('click', function() { sendMessage(); }); $('#chatInput').on('keypress', function(e) { if (e.which === 13) { sendMessage(); } }); // 产品点击 $(document).on('click', '.live-product-item', function() { const productId = $(this).data('product-id'); window.location.href = `product-detail.html?id=${productId}`; }); $(document).on('click', '.live-product-btn', function(e) { e.stopPropagation(); const productId = $(this).closest('.live-product-item').data('product-id'); addProductToCart(productId); }); } // Tab切换 function switchTab(tabName) { $('.tab-btn').removeClass('active'); $(`.tab-btn[data-tab="${tabName}"]`).addClass('active'); $('.tab-content').removeClass('active'); $(`#${tabName}Tab`).addClass('active'); } // 加载聊天消息 function loadChatMessages() { const lang = i18n.currentLang; const messages = [ { type: 'system', text: lang === 'zh-CN' ? '欢迎来到直播间!' : lang === 'en-US' ? 'Welcome to the live stream!' : 'ライブ配信へようこそ!', time: '10:00' }, { username: lang === 'zh-CN' ? '小明' : lang === 'en-US' ? 'Mike' : 'タロウ', text: lang === 'zh-CN' ? '这款拼图看起来很不错!' : lang === 'en-US' ? 'This puzzle looks great!' : 'このパズルは素晴らしいですね!', time: '10:05' }, { username: lang === 'zh-CN' ? '小红' : lang === 'en-US' ? 'Lucy' : 'ハナコ', text: lang === 'zh-CN' ? '适合多大年龄的孩子?' : lang === 'en-US' ? 'What age is it suitable for?' : '何歳の子供に適していますか?', time: '10:06' }, { username: lang === 'zh-CN' ? '主播' : lang === 'en-US' ? 'Host' : 'ホスト', text: lang === 'zh-CN' ? '这款拼图适合3-6岁的孩子,可以培养动手能力和空间想象力!' : lang === 'en-US' ? 'This puzzle is suitable for children aged 3-6 and helps develop hands-on skills and spatial imagination!' : 'このパズルは3〜6歳の子供に適しており、実践的なスキルと空間想像力を養うのに役立ちます!', time: '10:07' }, { username: lang === 'zh-CN' ? '李华' : lang === 'en-US' ? 'David' : 'ダビデ', text: lang === 'zh-CN' ? '价格很优惠,已经下单了!' : lang === 'en-US' ? 'Great price, just ordered!' : '価格もお得で、注文しました!', time: '10:08' }, { username: lang === 'zh-CN' ? '王芳' : lang === 'en-US' ? 'Sarah' : 'サラ', text: lang === 'zh-CN' ? '材质安全吗?' : lang === 'en-US' ? 'Is the material safe?' : '素材は安全ですか?', time: '10:09' }, { username: lang === 'zh-CN' ? '主播' : lang === 'en-US' ? 'Host' : 'ホスト', text: lang === 'zh-CN' ? '所有产品都通过了安全认证,使用环保材料,家长可以放心!' : lang === 'en-US' ? 'All products are safety certified and made from eco-friendly materials. Parents can rest assured!' : 'すべての製品は安全認証を受けており、環境に優しい素材を使用しています。親御さんも安心です!', time: '10:10' } ]; let chatHtml = ''; messages.forEach(msg => { if (msg.type === 'system') { chatHtml += `
`; } else { chatHtml += ` `; } }); $('#chatMessages').html(chatHtml); scrollChatToBottom(); } // 加载直播商品 function loadLiveProducts() { const lang = i18n.currentLang; const products = [ { id: 1, name: '200片拼图 - 海洋世界', name_en: '200 Piece Puzzle - Ocean World', name_ja: '200ピースパズル - 海の世界', price: 19.99, originalPrice: 29.99, image: 'https://picsum.photos/200/200?random=live1' }, { id: 2, name: '艺术绘画套装', name_en: 'Art Painting Set', name_ja: 'アート絵画セット', price: 24.99, originalPrice: 34.99, image: 'https://picsum.photos/200/200?random=live2' }, { id: 3, name: '木质积木 - 100块', name_en: 'Wooden Blocks - 100 Pieces', name_ja: '木製ブロック - 100ピース', price: 29.99, originalPrice: 39.99, image: 'https://picsum.photos/200/200?random=live3' }, { id: 4, name: '磁力片建构玩具', name_en: 'Magnetic Building Tiles', name_ja: 'マグネットタイル', price: 34.99, originalPrice: 49.99, image: 'https://picsum.photos/200/200?random=live4' }, { id: 5, name: '儿童桌游套装', name_en: 'Kids Board Game Set', name_ja: '子供用ボードゲームセット', price: 27.99, originalPrice: 37.99, image: 'https://picsum.photos/200/200?random=live5' } ]; let productsHtml = ''; products.forEach(product => { const productName = lang === 'zh-CN' ? product.name : lang === 'en-US' ? product.name_en : product.name_ja; const btnText = i18n.t('add_to_cart'); productsHtml += `