feat: 全站20个模板添加国际化(i18n)支持 - 简体中文/繁体中文/英文三语切换
- 所有18套前端模板 + 管理后台共20个HTML文件添加i18n引擎 - 前端JavaScript方案:I18N_LOCALES翻译字典 + data-i18n属性 + t()函数调用 - 语言切换器UI:下拉菜单选择,匹配各模板主题风格 - 语言持久化:localStorage存储 + URL参数覆盖 + 浏览器语言自动检测 - onLangChange回调:语言切换时动态重新渲染所有内容 - 支持语言:zh-CN(简体中文) / zh-TW(繁体中文) / en(English)
This commit is contained in:
567
web/dist/shop3/index.html
vendored
567
web/dist/shop3/index.html
vendored
@@ -161,6 +161,33 @@ input { font-family: inherit; outline: none; }
|
||||
font-family: var(--sans);
|
||||
}
|
||||
|
||||
/* ========== 语言切换器(北欧极简风格)========== */
|
||||
.lang-switcher{position:relative;margin-left:4px}
|
||||
.lang-btn{
|
||||
display:flex;align-items:center;gap:6px;padding:7px 12px;border-radius:var(--radius);
|
||||
font-size:13px;font-weight:400;color:var(--text-muted);cursor:pointer;
|
||||
background:transparent;border:1px solid var(--line);
|
||||
transition:all .25s var(--ease);letter-spacing:0.5px;
|
||||
}
|
||||
.lang-btn:hover{color:var(--text);border-color:var(--text-soft);background:var(--bg-warm)}
|
||||
.lang-btn svg{width:15px;height:15px}
|
||||
.lang-dropdown{
|
||||
position:absolute;top:calc(100% + 8px);right:0;min-width:160px;
|
||||
background:var(--surface);border:1px solid var(--line-soft);
|
||||
border-radius:var(--radius);box-shadow:0 12px 40px rgba(0,0,0,0.10);overflow:hidden;
|
||||
opacity:0;transform:translateY(-8px);pointer-events:none;
|
||||
transition:all .25s var(--ease);z-index:200;
|
||||
}
|
||||
.lang-dropdown.open{opacity:1;transform:none;pointer-events:auto}
|
||||
.lang-option{
|
||||
display:flex;align-items:center;gap:10px;padding:11px 16px;
|
||||
font-size:13px;color:var(--text-muted);cursor:pointer;transition:all .2s;letter-spacing:0.3px;
|
||||
}
|
||||
.lang-option:hover{background:var(--bg-warm);color:var(--text)}
|
||||
.lang-option.active{color:var(--text);font-weight:500}
|
||||
.lang-option .check{width:14px;height:14px;opacity:0;transition:opacity .2s}
|
||||
.lang-option.active .check{opacity:1}
|
||||
|
||||
/* ========== Hero ========== */
|
||||
.hero {
|
||||
background: var(--bg-warm);
|
||||
@@ -875,6 +902,8 @@ input { font-family: inherit; outline: none; }
|
||||
.footer-brand, .footer-news { grid-column: 1 / -1; }
|
||||
.footer-bottom { flex-direction: column; gap: 12px; text-align: center; }
|
||||
.sort-group { gap: 18px; }
|
||||
.lang-switcher{position:static;margin-left:0}
|
||||
.lang-dropdown{right:auto;left:0}
|
||||
}
|
||||
@media (max-width: 480px) {
|
||||
.products-grid, .featured-grid { grid-template-columns: 1fr; }
|
||||
@@ -953,24 +982,45 @@ input { font-family: inherit; outline: none; }
|
||||
<body>
|
||||
|
||||
<!-- 顶部细条 -->
|
||||
<div class="top-strip"><span>全球免运 · 满 $99 包邮 · 30 天无忧退换 · 全线正品保证</span></div>
|
||||
<div class="top-strip"><span data-i18n="top_strip">全球免运 · 满 $99 包邮 · 30 天无忧退换 · 全线正品保证</span></div>
|
||||
|
||||
<!-- 导航栏 -->
|
||||
<nav class="navbar">
|
||||
<div class="nav-inner">
|
||||
<a href="#" class="logo"><span class="logo-mark"></span>NORDI</a>
|
||||
<div class="nav-search">
|
||||
<input type="text" id="searchInput" placeholder="搜索生活好物…" autocomplete="off">
|
||||
<input type="text" id="searchInput" data-i18n-placeholder="search_placeholder" placeholder="搜索生活好物…" autocomplete="off">
|
||||
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5"><circle cx="11" cy="11" r="7"/><path d="m21 21-4.35-4.35"/></svg>
|
||||
</div>
|
||||
<div class="nav-actions">
|
||||
<button class="icon-btn" title="收藏">
|
||||
<button class="icon-btn" data-i18n-title="title_favorites" 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>
|
||||
</button>
|
||||
<button class="icon-btn" title="购物车" onclick="toggleCart()">
|
||||
<button class="icon-btn" data-i18n-title="title_cart" title="购物车" onclick="toggleCart()">
|
||||
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor"><path d="M6 2 3 6v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V6l-3-4z"/><path d="M3 6h18"/><path d="M16 10a4 4 0 0 1-8 0"/></svg>
|
||||
<span class="cart-badge" id="cartBadge">0</span>
|
||||
</button>
|
||||
<div class="lang-switcher" id="langSwitcher">
|
||||
<button class="lang-btn" id="langBtn" onclick="toggleLangDropdown()">
|
||||
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><path d="M2 12h20"/><path d="M12 2a15.3 15.3 0 0 1 4 10 15.3 15.3 0 0 1-4 10 15.3 15.3 0 0 1-4-10 15.3 15.3 0 0 1 4-10z"/></svg>
|
||||
<span id="langLabel">中文</span>
|
||||
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="width:12px;height:12px"><polyline points="6 9 12 15 18 9"/></svg>
|
||||
</button>
|
||||
<div class="lang-dropdown" id="langDropdown">
|
||||
<div class="lang-option" data-lang="zh-CN" onclick="switchLang('zh-CN')">
|
||||
<svg class="check" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><polyline points="20 6 9 17 4 12"/></svg>
|
||||
<span>简体中文</span>
|
||||
</div>
|
||||
<div class="lang-option" data-lang="zh-TW" onclick="switchLang('zh-TW')">
|
||||
<svg class="check" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><polyline points="20 6 9 17 4 12"/></svg>
|
||||
<span>繁體中文</span>
|
||||
</div>
|
||||
<div class="lang-option" data-lang="en" onclick="switchLang('en')">
|
||||
<svg class="check" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><polyline points="20 6 9 17 4 12"/></svg>
|
||||
<span>English</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
@@ -981,8 +1031,8 @@ input { font-family: inherit; outline: none; }
|
||||
<div class="hero-text">
|
||||
<div class="hero-eyebrow">NORDIC · LIVING · 2026</div>
|
||||
<h1>Lifestyle<br><em>Collection</em></h1>
|
||||
<p class="hero-desc">源自北欧的极简生活哲学。精选全球匠心好物,以克制的设计与温润的质感,为日常注入从容与诗意。</p>
|
||||
<button class="hero-cta" onclick="scrollToShop()">探索精选
|
||||
<p class="hero-desc" data-i18n="hero_desc">源自北欧的极简生活哲学。精选全球匠心好物,以克制的设计与温润的质感,为日常注入从容与诗意。</p>
|
||||
<button class="hero-cta" onclick="scrollToShop()"><span data-i18n="hero_cta">探索精选</span>
|
||||
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5"><path d="M5 12h14"/><path d="m12 5 7 7-7 7"/></svg>
|
||||
</button>
|
||||
</div>
|
||||
@@ -1004,19 +1054,19 @@ input { font-family: inherit; outline: none; }
|
||||
<div class="values-grid">
|
||||
<div class="value-item">
|
||||
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor"><circle cx="12" cy="12" r="10"/><path d="M2 12h20"/><path d="M12 2a15.3 15.3 0 0 1 4 10 15.3 15.3 0 0 1-4 10 15.3 15.3 0 0 1-4-10 15.3 15.3 0 0 1 4-10z"/></svg>
|
||||
<div><h4>全球直采</h4><p>原产地严选溯源</p></div>
|
||||
<div><h4 data-i18n="val_global_title">全球直采</h4><p data-i18n="val_global_desc">原产地严选溯源</p></div>
|
||||
</div>
|
||||
<div class="value-item">
|
||||
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor"><rect x="1" y="3" width="15" height="13"/><path d="M16 8h4l3 3v5h-7"/><circle cx="5.5" cy="18.5" r="2.5"/><circle cx="18.5" cy="18.5" r="2.5"/></svg>
|
||||
<div><h4>极速跨境</h4><p>平均 5 日达</p></div>
|
||||
<div><h4 data-i18n="val_shipping_title">极速跨境</h4><p data-i18n="val_shipping_desc">平均 5 日达</p></div>
|
||||
</div>
|
||||
<div class="value-item">
|
||||
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor"><path d="M9 11l3 3L22 4"/><path d="M21 12v7a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11"/></svg>
|
||||
<div><h4>正品保证</h4><p>假一赔十承诺</p></div>
|
||||
<div><h4 data-i18n="val_auth_title">正品保证</h4><p data-i18n="val_auth_desc">假一赔十承诺</p></div>
|
||||
</div>
|
||||
<div class="value-item">
|
||||
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor"><path d="M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"/><path d="M3 3v5h5"/></svg>
|
||||
<div><h4>30天退换</h4><p>无忧售后保障</p></div>
|
||||
<div><h4 data-i18n="val_return_title">30天退换</h4><p data-i18n="val_return_desc">无忧售后保障</p></div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
@@ -1024,8 +1074,8 @@ input { font-family: inherit; outline: none; }
|
||||
<!-- 分类导航 -->
|
||||
<div class="category-bar">
|
||||
<div class="category-inner" id="categoryChips">
|
||||
<span class="cat-label">分类</span>
|
||||
<span class="cat-chip active" onclick="selectCategory(0)">全部</span>
|
||||
<span class="cat-label" data-i18n="cat_label">分类</span>
|
||||
<span class="cat-chip active" onclick="selectCategory(0)" data-i18n="cat_all">全部</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1035,18 +1085,18 @@ input { font-family: inherit; outline: none; }
|
||||
<div class="section-head">
|
||||
<div>
|
||||
<div class="section-title">Curated Goods</div>
|
||||
<div class="section-sub">每一件,皆经严选 / Every piece, thoughtfully chosen</div>
|
||||
<div class="section-sub" data-i18n="shop_sub">每一件,皆经严选 / Every piece, thoughtfully chosen</div>
|
||||
</div>
|
||||
<a href="#" class="section-link" onclick="loadFeatured();return false;">查看精选推荐</a>
|
||||
<a href="#" class="section-link" data-i18n="view_featured" onclick="loadFeatured();return false;">查看精选推荐</a>
|
||||
</div>
|
||||
|
||||
<div class="toolbar">
|
||||
<div class="toolbar-count" id="productsCount">— 件商品</div>
|
||||
<div class="sort-group">
|
||||
<button class="sort-btn active" data-sort="" onclick="changeSort('')">推荐</button>
|
||||
<button class="sort-btn" data-sort="sales" onclick="changeSort('sales')">畅销</button>
|
||||
<button class="sort-btn" data-sort="price" onclick="changeSort('price')">价格</button>
|
||||
<button class="sort-btn" data-sort="rating" onclick="changeSort('rating')">好评</button>
|
||||
<button class="sort-btn active" data-sort="" onclick="changeSort('')" data-i18n="sort_recommend">推荐</button>
|
||||
<button class="sort-btn" data-sort="sales" onclick="changeSort('sales')" data-i18n="sort_best_selling">畅销</button>
|
||||
<button class="sort-btn" data-sort="price" onclick="changeSort('price')" data-i18n="sort_price">价格</button>
|
||||
<button class="sort-btn" data-sort="rating" onclick="changeSort('rating')" data-i18n="sort_rating">好评</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1061,7 +1111,7 @@ input { font-family: inherit; outline: none; }
|
||||
<div class="section-head">
|
||||
<div>
|
||||
<div class="section-title">Editor's Pick</div>
|
||||
<div class="section-sub">编辑精选 · 本季值得拥有的好物</div>
|
||||
<div class="section-sub" data-i18n="featured_sub">编辑精选 · 本季值得拥有的好物</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="featured-grid" id="featuredGrid"></div>
|
||||
@@ -1073,44 +1123,44 @@ input { font-family: inherit; outline: none; }
|
||||
<div class="footer-grid">
|
||||
<div class="footer-brand">
|
||||
<h4>NORDI</h4>
|
||||
<p>以斯堪的纳维亚的极简美学,为世界各地的家,带来经久耐用的生活良品。Less, but better.</p>
|
||||
<p data-i18n="footer_brand_desc">以斯堪的纳维亚的极简美学,为世界各地的家,带来经久耐用的生活良品。Less, but better.</p>
|
||||
</div>
|
||||
<div class="footer-col">
|
||||
<h5>购物</h5>
|
||||
<a href="#" onclick="selectCategory(0);return false;">全部商品</a>
|
||||
<a href="#" onclick="loadFeatured();return false;">编辑精选</a>
|
||||
<a href="#">新品上架</a>
|
||||
<a href="#">限时优惠</a>
|
||||
<h5 data-i18n="footer_shop">购物</h5>
|
||||
<a href="#" onclick="selectCategory(0);return false;" data-i18n="footer_all_products">全部商品</a>
|
||||
<a href="#" onclick="loadFeatured();return false;" data-i18n="footer_editors_pick">编辑精选</a>
|
||||
<a href="#" data-i18n="footer_new_arrivals">新品上架</a>
|
||||
<a href="#" data-i18n="footer_deals">限时优惠</a>
|
||||
</div>
|
||||
<div class="footer-col">
|
||||
<h5>服务</h5>
|
||||
<a href="#">配送说明</a>
|
||||
<a href="#">退换政策</a>
|
||||
<a href="#">尺码指南</a>
|
||||
<a href="#">常见问题</a>
|
||||
<h5 data-i18n="footer_service">服务</h5>
|
||||
<a href="#" data-i18n="footer_shipping_info">配送说明</a>
|
||||
<a href="#" data-i18n="footer_return_policy">退换政策</a>
|
||||
<a href="#" data-i18n="footer_size_guide">尺码指南</a>
|
||||
<a href="#" data-i18n="footer_faq">常见问题</a>
|
||||
</div>
|
||||
<div class="footer-col">
|
||||
<h5>关于</h5>
|
||||
<a href="#">品牌故事</a>
|
||||
<a href="#">可持续</a>
|
||||
<a href="#">联系我们</a>
|
||||
<a href="#">隐私条款</a>
|
||||
<h5 data-i18n="footer_about">关于</h5>
|
||||
<a href="#" data-i18n="footer_brand_story">品牌故事</a>
|
||||
<a href="#" data-i18n="footer_sustainability">可持续</a>
|
||||
<a href="#" data-i18n="footer_contact_us">联系我们</a>
|
||||
<a href="#" data-i18n="footer_privacy">隐私条款</a>
|
||||
</div>
|
||||
<div class="footer-col footer-news">
|
||||
<h5>订阅</h5>
|
||||
<p>订阅 Newsletter,获取新品资讯与会员专属礼遇。</p>
|
||||
<form class="news-form" onsubmit="event.preventDefault();showToast('订阅成功,感谢关注');this.reset();">
|
||||
<input type="email" placeholder="您的邮箱地址" required>
|
||||
<h5 data-i18n="footer_subscribe">订阅</h5>
|
||||
<p data-i18n="footer_newsletter_desc">订阅 Newsletter,获取新品资讯与会员专属礼遇。</p>
|
||||
<form class="news-form" onsubmit="event.preventDefault();showToast(t('subscribe_success'));this.reset();">
|
||||
<input type="email" data-i18n-placeholder="footer_email_placeholder" placeholder="您的邮箱地址" required>
|
||||
<button type="submit"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5"><path d="M5 12h14"/><path d="m12 5 7 7-7 7"/></svg></button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<div class="footer-bottom">
|
||||
<span>© 2026 NORDI. All rights reserved. · 以克制之美,抵达日常</span>
|
||||
<span>© 2026 NORDI. All rights reserved. · <span data-i18n="footer_tagline">以克制之美,抵达日常</span></span>
|
||||
<div class="fb-links">
|
||||
<a href="#">Instagram</a>
|
||||
<a href="#">Pinterest</a>
|
||||
<a href="#">微信</a>
|
||||
<a href="#" data-i18n="social_wechat">微信</a>
|
||||
</div>
|
||||
</div>
|
||||
</footer>
|
||||
@@ -1124,17 +1174,17 @@ input { font-family: inherit; outline: none; }
|
||||
<div class="cart-overlay" id="cartOverlay" onclick="toggleCart()"></div>
|
||||
<aside class="cart-drawer" id="cartDrawer">
|
||||
<div class="cart-header">
|
||||
<h3>购物袋</h3>
|
||||
<h3 data-i18n="cart_title">购物袋</h3>
|
||||
<button class="close-x" onclick="toggleCart()">×</button>
|
||||
</div>
|
||||
<div class="cart-items" id="cartItems"></div>
|
||||
<div class="cart-footer">
|
||||
<div class="cart-summary">
|
||||
<span class="cs-label">合计</span>
|
||||
<span class="cs-label" data-i18n="cart_total_label">合计</span>
|
||||
<span class="cs-total" id="cartTotal">$0.00</span>
|
||||
</div>
|
||||
<div class="cart-note">含税 · 运费于结算时计算</div>
|
||||
<button class="cart-checkout" id="checkoutBtn" onclick="checkout()" disabled>前往结算</button>
|
||||
<div class="cart-note" data-i18n="cart_note">含税 · 运费于结算时计算</div>
|
||||
<button class="cart-checkout" id="checkoutBtn" onclick="checkout()" disabled data-i18n="cart_checkout">前往结算</button>
|
||||
</div>
|
||||
</aside>
|
||||
|
||||
@@ -1145,6 +1195,320 @@ input { font-family: inherit; outline: none; }
|
||||
</div>
|
||||
|
||||
<script>
|
||||
/* =========================================================
|
||||
国际化(i18n)引擎
|
||||
========================================================= */
|
||||
const I18N_LOCALES = {
|
||||
'zh-CN': {
|
||||
top_strip: '全球免运 · 满 $99 包邮 · 30 天无忧退换 · 全线正品保证',
|
||||
search_placeholder: '搜索生活好物…',
|
||||
title_favorites: '收藏',
|
||||
title_cart: '购物车',
|
||||
hero_desc: '源自北欧的极简生活哲学。精选全球匠心好物,以克制的设计与温润的质感,为日常注入从容与诗意。',
|
||||
hero_cta: '探索精选',
|
||||
val_global_title: '全球直采',
|
||||
val_global_desc: '原产地严选溯源',
|
||||
val_shipping_title: '极速跨境',
|
||||
val_shipping_desc: '平均 5 日达',
|
||||
val_auth_title: '正品保证',
|
||||
val_auth_desc: '假一赔十承诺',
|
||||
val_return_title: '30天退换',
|
||||
val_return_desc: '无忧售后保障',
|
||||
cat_label: '分类',
|
||||
cat_all: '全部',
|
||||
shop_sub: '每一件,皆经严选 / Every piece, thoughtfully chosen',
|
||||
view_featured: '查看精选推荐',
|
||||
sort_recommend: '推荐',
|
||||
sort_best_selling: '畅销',
|
||||
sort_price: '价格',
|
||||
sort_rating: '好评',
|
||||
products_count: '共 {n} 件商品',
|
||||
products_count_featured: '编辑精选 · {n} 件商品',
|
||||
featured_sub: '编辑精选 · 本季值得拥有的好物',
|
||||
footer_brand_desc: '以斯堪的纳维亚的极简美学,为世界各地的家,带来经久耐用的生活良品。Less, but better.',
|
||||
footer_shop: '购物',
|
||||
footer_all_products: '全部商品',
|
||||
footer_editors_pick: '编辑精选',
|
||||
footer_new_arrivals: '新品上架',
|
||||
footer_deals: '限时优惠',
|
||||
footer_service: '服务',
|
||||
footer_shipping_info: '配送说明',
|
||||
footer_return_policy: '退换政策',
|
||||
footer_size_guide: '尺码指南',
|
||||
footer_faq: '常见问题',
|
||||
footer_about: '关于',
|
||||
footer_brand_story: '品牌故事',
|
||||
footer_sustainability: '可持续',
|
||||
footer_contact_us: '联系我们',
|
||||
footer_privacy: '隐私条款',
|
||||
footer_subscribe: '订阅',
|
||||
footer_newsletter_desc: '订阅 Newsletter,获取新品资讯与会员专属礼遇。',
|
||||
footer_email_placeholder: '您的邮箱地址',
|
||||
footer_tagline: '以克制之美,抵达日常',
|
||||
social_wechat: '微信',
|
||||
cart_title: '购物袋',
|
||||
cart_total_label: '合计',
|
||||
cart_note: '含税 · 运费于结算时计算',
|
||||
cart_checkout: '前往结算',
|
||||
cart_empty_title: '购物袋还是空的',
|
||||
cart_empty_desc: '去挑选心仪的好物吧',
|
||||
cart_remove: '移除',
|
||||
modal_loading: '载入中…',
|
||||
modal_nordi_pick: 'NORDI 严选',
|
||||
modal_save_pct: '省 {n}%',
|
||||
modal_rating: '评分',
|
||||
modal_sales: '销量',
|
||||
modal_stock: '库存',
|
||||
modal_qty: '数量',
|
||||
modal_add_cart: '加入购物袋',
|
||||
modal_desc_fallback: '每一处细节皆经匠心打磨,以克制的线条与温润的质感,融入你的日常生活。',
|
||||
modal_load_error: '商品详情加载失败,请稍后重试',
|
||||
error_load_failed: '加载失败',
|
||||
error_load_desc: '商品信息暂时无法获取,请稍后重试',
|
||||
error_network: '网络异常',
|
||||
error_request_failed: '请求失败',
|
||||
error_category_load: '分类加载失败',
|
||||
empty_title: '暂无商品',
|
||||
empty_desc: '没有找到匹配的商品,换个关键词试试',
|
||||
toast_wishlist: '已加入心愿单',
|
||||
toast_added_to_cart: '已加入购物袋 · {name}',
|
||||
toast_add_failed: '添加失败,请重试',
|
||||
toast_featured_loading: '正在为你挑选编辑精选…',
|
||||
toast_featured_failed: '精选加载失败,请稍后重试',
|
||||
toast_order_submitted: '订单已提交 · 合计 {total} · 感谢惠顾',
|
||||
toast_subscribe_success: '订阅成功,感谢关注',
|
||||
category_default: '生活好物',
|
||||
page_title: '生活美学严选'
|
||||
},
|
||||
'en': {
|
||||
top_strip: 'Free Shipping · Free on $99+ · 30-Day Returns · Authentic Guarantee',
|
||||
search_placeholder: 'Search lifestyle goods…',
|
||||
title_favorites: 'Favorites',
|
||||
title_cart: 'Cart',
|
||||
hero_desc: 'Nordic-inspired minimalist living philosophy. Thoughtfully curated goods from around the world, bringing calm and poetry to your everyday life through restrained design and warm textures.',
|
||||
hero_cta: 'Explore Collection',
|
||||
val_global_title: 'Global Sourcing',
|
||||
val_global_desc: 'Direct from origin',
|
||||
val_shipping_title: 'Express Cross-border',
|
||||
val_shipping_desc: 'Avg. 5-day delivery',
|
||||
val_auth_title: 'Authentic Guarantee',
|
||||
val_auth_desc: '10× compensation for fakes',
|
||||
val_return_title: '30-Day Returns',
|
||||
val_return_desc: 'Worry-free after-sales',
|
||||
cat_label: 'Categories',
|
||||
cat_all: 'All',
|
||||
shop_sub: 'Every piece, thoughtfully chosen',
|
||||
view_featured: 'View Editor\'s Picks',
|
||||
sort_recommend: 'Recommended',
|
||||
sort_best_selling: 'Best Selling',
|
||||
sort_price: 'Price',
|
||||
sort_rating: 'Top Rated',
|
||||
products_count: '{n} items',
|
||||
products_count_featured: 'Editor\'s Picks · {n} items',
|
||||
featured_sub: 'Editor\'s Picks · Must-haves this season',
|
||||
footer_brand_desc: 'Scandinavian minimalist aesthetics, bringing durable lifestyle goods to homes around the world. Less, but better.',
|
||||
footer_shop: 'Shop',
|
||||
footer_all_products: 'All Products',
|
||||
footer_editors_pick: 'Editor\'s Picks',
|
||||
footer_new_arrivals: 'New Arrivals',
|
||||
footer_deals: 'Deals',
|
||||
footer_service: 'Service',
|
||||
footer_shipping_info: 'Shipping Info',
|
||||
footer_return_policy: 'Return Policy',
|
||||
footer_size_guide: 'Size Guide',
|
||||
footer_faq: 'FAQ',
|
||||
footer_about: 'About',
|
||||
footer_brand_story: 'Brand Story',
|
||||
footer_sustainability: 'Sustainability',
|
||||
footer_contact_us: 'Contact Us',
|
||||
footer_privacy: 'Privacy Policy',
|
||||
footer_subscribe: 'Subscribe',
|
||||
footer_newsletter_desc: 'Subscribe to our Newsletter for new arrivals and exclusive member perks.',
|
||||
footer_email_placeholder: 'Your email address',
|
||||
footer_tagline: 'Refined simplicity for everyday living',
|
||||
social_wechat: 'WeChat',
|
||||
cart_title: 'Shopping Bag',
|
||||
cart_total_label: 'Subtotal',
|
||||
cart_note: 'Tax included · Shipping calculated at checkout',
|
||||
cart_checkout: 'Proceed to Checkout',
|
||||
cart_empty_title: 'Your bag is empty',
|
||||
cart_empty_desc: 'Discover something you love',
|
||||
cart_remove: 'Remove',
|
||||
modal_loading: 'Loading…',
|
||||
modal_nordi_pick: 'NORDI Curated',
|
||||
modal_save_pct: 'Save {n}%',
|
||||
modal_rating: 'Rating',
|
||||
modal_sales: 'Sales',
|
||||
modal_stock: 'Stock',
|
||||
modal_qty: 'Quantity',
|
||||
modal_add_cart: 'Add to Bag',
|
||||
modal_desc_fallback: 'Every detail is meticulously crafted, blending restrained lines and warm textures into your daily life.',
|
||||
modal_load_error: 'Failed to load details, please try again later',
|
||||
error_load_failed: 'Load Failed',
|
||||
error_load_desc: 'Product info temporarily unavailable, please try again later',
|
||||
error_network: 'Network Error',
|
||||
error_request_failed: 'Request Failed',
|
||||
error_category_load: 'Failed to load categories',
|
||||
empty_title: 'No Products',
|
||||
empty_desc: 'No matching products found, try different keywords',
|
||||
toast_wishlist: 'Added to wishlist',
|
||||
toast_added_to_cart: 'Added to bag · {name}',
|
||||
toast_add_failed: 'Failed to add, please try again',
|
||||
toast_featured_loading: 'Curating editor\'s picks for you…',
|
||||
toast_featured_failed: 'Failed to load picks, please try again later',
|
||||
toast_order_submitted: 'Order placed · Total {total} · Thank you',
|
||||
toast_subscribe_success: 'Subscribed, thank you!',
|
||||
category_default: 'Lifestyle',
|
||||
page_title: 'Lifestyle Curated'
|
||||
},
|
||||
'zh-TW': {
|
||||
top_strip: '全球免運 · 滿 $99 包郵 · 30 天無憂退換 · 全線正品保證',
|
||||
search_placeholder: '搜尋生活好物…',
|
||||
title_favorites: '收藏',
|
||||
title_cart: '購物車',
|
||||
hero_desc: '源自北歐的極簡生活哲學。精選全球匠心好物,以克制的設計與溫潤的質感,為日常注入從容與詩意。',
|
||||
hero_cta: '探索精選',
|
||||
val_global_title: '全球直採',
|
||||
val_global_desc: '原產地嚴選溯源',
|
||||
val_shipping_title: '極速跨境',
|
||||
val_shipping_desc: '平均 5 日達',
|
||||
val_auth_title: '正品保證',
|
||||
val_auth_desc: '假一賠十承諾',
|
||||
val_return_title: '30天退換',
|
||||
val_return_desc: '無憂售後保障',
|
||||
cat_label: '分類',
|
||||
cat_all: '全部',
|
||||
shop_sub: '每一件,皆經嚴選 / Every piece, thoughtfully chosen',
|
||||
view_featured: '查看精選推薦',
|
||||
sort_recommend: '推薦',
|
||||
sort_best_selling: '暢銷',
|
||||
sort_price: '價格',
|
||||
sort_rating: '好評',
|
||||
products_count: '共 {n} 件商品',
|
||||
products_count_featured: '編輯精選 · {n} 件商品',
|
||||
featured_sub: '編輯精選 · 本季值得擁有的好物',
|
||||
footer_brand_desc: '以斯堪的納維亞的極簡美學,為世界各地的家,帶來經久耐用的生活良品。Less, but better.',
|
||||
footer_shop: '購物',
|
||||
footer_all_products: '全部商品',
|
||||
footer_editors_pick: '編輯精選',
|
||||
footer_new_arrivals: '新品上架',
|
||||
footer_deals: '限時優惠',
|
||||
footer_service: '服務',
|
||||
footer_shipping_info: '配送說明',
|
||||
footer_return_policy: '退換政策',
|
||||
footer_size_guide: '尺碼指南',
|
||||
footer_faq: '常見問題',
|
||||
footer_about: '關於',
|
||||
footer_brand_story: '品牌故事',
|
||||
footer_sustainability: '可持續',
|
||||
footer_contact_us: '聯絡我們',
|
||||
footer_privacy: '私隱條款',
|
||||
footer_subscribe: '訂閱',
|
||||
footer_newsletter_desc: '訂閱 Newsletter,獲取新品資訊與會員專屬禮遇。',
|
||||
footer_email_placeholder: '您的電郵地址',
|
||||
footer_tagline: '以克制之美,抵達日常',
|
||||
social_wechat: '微信',
|
||||
cart_title: '購物袋',
|
||||
cart_total_label: '合計',
|
||||
cart_note: '含稅 · 運費於結帳時計算',
|
||||
cart_checkout: '前往結帳',
|
||||
cart_empty_title: '購物袋還是空的',
|
||||
cart_empty_desc: '去挑選心儀的好物吧',
|
||||
cart_remove: '移除',
|
||||
modal_loading: '載入中…',
|
||||
modal_nordi_pick: 'NORDI 嚴選',
|
||||
modal_save_pct: '省 {n}%',
|
||||
modal_rating: '評分',
|
||||
modal_sales: '銷量',
|
||||
modal_stock: '庫存',
|
||||
modal_qty: '數量',
|
||||
modal_add_cart: '加入購物袋',
|
||||
modal_desc_fallback: '每一處細節皆經匠心打磨,以克制的線條與溫潤的質感,融入你的日常生活。',
|
||||
modal_load_error: '商品詳情載入失敗,請稍後重試',
|
||||
error_load_failed: '載入失敗',
|
||||
error_load_desc: '商品資訊暫時無法取得,請稍後重試',
|
||||
error_network: '網路異常',
|
||||
error_request_failed: '請求失敗',
|
||||
error_category_load: '分類載入失敗',
|
||||
empty_title: '暫無商品',
|
||||
empty_desc: '沒有找到匹配的商品,換個關鍵詞試試',
|
||||
toast_wishlist: '已加入心願單',
|
||||
toast_added_to_cart: '已加入購物袋 · {name}',
|
||||
toast_add_failed: '新增失敗,請重試',
|
||||
toast_featured_loading: '正在為你挑選編輯精選…',
|
||||
toast_featured_failed: '精選載入失敗,請稍後重試',
|
||||
toast_order_submitted: '訂單已提交 · 合計 {total} · 感謝惠顧',
|
||||
toast_subscribe_success: '訂閱成功,感謝關注',
|
||||
category_default: '生活好物',
|
||||
page_title: '生活美學嚴選'
|
||||
}
|
||||
};
|
||||
|
||||
const LANG_LABELS = {'zh-CN': '中文', 'en': 'EN', 'zh-TW': '繁中'};
|
||||
|
||||
let currentLang = (function(){
|
||||
try{
|
||||
var u = navigator.language || navigator.userLanguage || '';
|
||||
var s = localStorage.getItem('lang');
|
||||
if (s && I18N_LOCALES[s]) return s;
|
||||
if (u.startsWith('zh-TW') || u.startsWith('zh-Hant')) return 'zh-TW';
|
||||
if (u.startsWith('zh')) return 'zh-CN';
|
||||
return 'en';
|
||||
} catch(e) {
|
||||
return 'zh-CN';
|
||||
}
|
||||
})();
|
||||
|
||||
function t(key, params) {
|
||||
var str = (I18N_LOCALES[currentLang] && I18N_LOCALES[currentLang][key])
|
||||
|| (I18N_LOCALES['zh-CN'][key])
|
||||
|| key;
|
||||
if (params) {
|
||||
Object.keys(params).forEach(function(k) {
|
||||
str = str.replace(new RegExp('\\{' + k + '\\}', 'g'), params[k]);
|
||||
});
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
function applyI18n() {
|
||||
document.querySelectorAll('[data-i18n]').forEach(function(el) {
|
||||
var key = el.getAttribute('data-i18n');
|
||||
el.textContent = t(key);
|
||||
});
|
||||
document.querySelectorAll('[data-i18n-placeholder]').forEach(function(el) {
|
||||
var key = el.getAttribute('data-i18n-placeholder');
|
||||
el.placeholder = t(key);
|
||||
});
|
||||
document.querySelectorAll('[data-i18n-title]').forEach(function(el) {
|
||||
var key = el.getAttribute('data-i18n-title');
|
||||
el.title = t(key);
|
||||
});
|
||||
document.documentElement.lang = currentLang === 'zh-TW' ? 'zh-TW' : currentLang === 'zh-CN' ? 'zh-CN' : 'en';
|
||||
document.title = 'NORDI · ' + t('page_title');
|
||||
document.getElementById('langLabel').textContent = LANG_LABELS[currentLang] || currentLang;
|
||||
document.querySelectorAll('.lang-option').forEach(function(opt) {
|
||||
opt.classList.toggle('active', opt.getAttribute('data-lang') === currentLang);
|
||||
});
|
||||
}
|
||||
|
||||
function switchLang(lang) {
|
||||
if (!I18N_LOCALES[lang]) return;
|
||||
currentLang = lang;
|
||||
try { localStorage.setItem('lang', lang); } catch(e) {}
|
||||
applyI18n();
|
||||
if (typeof onLangChange === 'function') onLangChange(lang);
|
||||
document.getElementById('langDropdown').classList.remove('open');
|
||||
}
|
||||
|
||||
function toggleLangDropdown() {
|
||||
document.getElementById('langDropdown').classList.toggle('open');
|
||||
}
|
||||
document.addEventListener('click', function(e) {
|
||||
var sw = document.getElementById('langSwitcher');
|
||||
if (sw && !sw.contains(e.target)) document.getElementById('langDropdown').classList.remove('open');
|
||||
});
|
||||
|
||||
// ========== 全局状态 ==========
|
||||
let allCategories = [];
|
||||
let currentPage = 1;
|
||||
@@ -1158,12 +1522,12 @@ let featuredLoaded = false;
|
||||
|
||||
// ========== 莫兰迪渐变 (极浅) ==========
|
||||
const morandi = [
|
||||
{ c: '#A8C5A0', t: 'sage' }, // 灰绿
|
||||
{ c: '#D4A5A5', t: 'clay' }, // 灰粉
|
||||
{ c: '#A0B8C5', t: 'slate' }, // 灰蓝
|
||||
{ c: '#C5B8A0', t: 'taupe' }, // 暖灰棕
|
||||
{ c: '#B8A5C5', t: 'mauve' }, // 灰紫
|
||||
{ c: '#A0C5B8', t: 'mint' }, // 灰薄荷
|
||||
{ c: '#A8C5A0', t: 'sage' },
|
||||
{ c: '#D4A5A5', t: 'clay' },
|
||||
{ c: '#A0B8C5', t: 'slate' },
|
||||
{ c: '#C5B8A0', t: 'taupe' },
|
||||
{ c: '#B8A5C5', t: 'mauve' },
|
||||
{ c: '#A0C5B8', t: 'mint' },
|
||||
];
|
||||
function getGradient(seed) {
|
||||
const m = morandi[(seed - 1) % morandi.length] || morandi[0];
|
||||
@@ -1172,21 +1536,21 @@ function getGradient(seed) {
|
||||
return `linear-gradient(150deg, rgba(${r},${g},${b},0.16), rgba(${r},${g},${b},0.30))`;
|
||||
}
|
||||
function tagClass(tag) {
|
||||
if (tag.includes('新')) return 't-sage';
|
||||
if (tag.includes('热') || tag.includes('销') || tag.includes('爆')) return 't-clay';
|
||||
if (tag.includes('新') || tag.includes('新')) return 't-sage';
|
||||
if (tag.includes('热') || tag.includes('熱') || tag.includes('销') || tag.includes('銷') || tag.includes('爆')) return 't-clay';
|
||||
return 't-slate';
|
||||
}
|
||||
|
||||
// ========== 优雅线条图标 (按分类) ==========
|
||||
const iconPaths = {
|
||||
1: '<path d="M3 8h18l-1.5 11a2 2 0 0 1-2 1.8H6.5a2 2 0 0 1-2-1.8z"/><path d="M8 8V6a4 4 0 0 1 8 0v2"/><path d="M9 13v2"/><path d="M15 13v2"/>', // 包/手提
|
||||
2: '<path d="M3 9.5 12 3l9 6.5V20a1 1 0 0 1-1 1h-6v-7h-4v7H4a1 1 0 0 1-1-1z"/><path d="M9 11h6"/>', // 家居
|
||||
3: '<path d="M12 3c0 4-4 5-4 9a4 4 0 0 0 8 0c0-4-4-5-4-9z"/><path d="M12 21v-4"/>', // 蜡烛/香氛
|
||||
4: '<circle cx="12" cy="12" r="8"/><path d="M12 4v16"/><path d="M4 12h16"/><path d="M7 7c2 2 2 8 0 10"/><path d="M17 7c-2 2-2 8 0 10"/>', // 球/装饰
|
||||
5: '<path d="M6 3h9l3 3v15H6z"/><path d="M9 9h6"/><path d="M9 13h6"/><path d="M9 17h4"/>', // 书/本册
|
||||
6: '<rect x="4" y="6" width="16" height="14" rx="1"/><path d="M9 6V4h6v2"/><path d="M4 11h16"/>', // 收纳盒
|
||||
7: '<path d="M12 2 4 7v6c0 4 3 7 8 9 5-2 8-5 8-9V7z"/><path d="M9 12l2 2 4-4"/>', // 品质盾
|
||||
8: '<path d="M5 7h14l-1 13a1 1 0 0 1-1 1H7a1 1 0 0 1-1-1z"/><path d="M9 7V5a3 3 0 0 1 6 0v2"/><path d="M12 12v4"/>', // 杯具
|
||||
1: '<path d="M3 8h18l-1.5 11a2 2 0 0 1-2 1.8H6.5a2 2 0 0 1-2-1.8z"/><path d="M8 8V6a4 4 0 0 1 8 0v2"/><path d="M9 13v2"/><path d="M15 13v2"/>',
|
||||
2: '<path d="M3 9.5 12 3l9 6.5V20a1 1 0 0 1-1 1h-6v-7h-4v7H4a1 1 0 0 1-1-1z"/><path d="M9 11h6"/>',
|
||||
3: '<path d="M12 3c0 4-4 5-4 9a4 4 0 0 0 8 0c0-4-4-5-4-9z"/><path d="M12 21v-4"/>',
|
||||
4: '<circle cx="12" cy="12" r="8"/><path d="M12 4v16"/><path d="M4 12h16"/><path d="M7 7c2 2 2 8 0 10"/><path d="M17 7c-2 2-2 8 0 10"/>',
|
||||
5: '<path d="M6 3h9l3 3v15H6z"/><path d="M9 9h6"/><path d="M9 13h6"/><path d="M9 17h4"/>',
|
||||
6: '<rect x="4" y="6" width="16" height="14" rx="1"/><path d="M9 6V4h6v2"/><path d="M4 11h16"/>',
|
||||
7: '<path d="M12 2 4 7v6c0 4 3 7 8 9 5-2 8-5 8-9V7z"/><path d="M9 12l2 2 4-4"/>',
|
||||
8: '<path d="M5 7h14l-1 13a1 1 0 0 1-1 1H7a1 1 0 0 1-1-1z"/><path d="M9 7V5a3 3 0 0 1 6 0v2"/><path d="M12 12v4"/>',
|
||||
};
|
||||
function productIconSVG(catId) {
|
||||
const p = iconPaths[catId] || iconPaths[1];
|
||||
@@ -1199,9 +1563,9 @@ function starSVG() {
|
||||
// ========== API ==========
|
||||
async function fetchJSON(url) {
|
||||
const res = await fetch(url);
|
||||
if (!res.ok) throw new Error('网络异常 (' + res.status + ')');
|
||||
if (!res.ok) throw new Error(t('error_network') + ' (' + res.status + ')');
|
||||
const json = await res.json();
|
||||
if (json.code !== 0) throw new Error(json.message || '请求失败');
|
||||
if (json.code !== 0) throw new Error(json.message || t('error_request_failed'));
|
||||
return json.data;
|
||||
}
|
||||
|
||||
@@ -1210,7 +1574,7 @@ async function loadCategories() {
|
||||
try {
|
||||
allCategories = await fetchJSON('/api/v1/shop/categories');
|
||||
renderCategoryChips();
|
||||
} catch (e) { console.error('分类加载失败:', e); }
|
||||
} catch (e) { console.error(t('error_category_load') + ':', e); }
|
||||
}
|
||||
|
||||
async function loadProducts() {
|
||||
@@ -1234,25 +1598,25 @@ async function loadProducts() {
|
||||
} catch (e) {
|
||||
grid.innerHTML = `<div class="empty-state">
|
||||
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor"><path d="M10.29 3.86 1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"/><path d="M12 9v4"/><path d="M12 17h.01"/></svg>
|
||||
<h3>加载失败</h3><p>商品信息暂时无法获取,请稍后重试</p></div>`;
|
||||
<h3>${t('error_load_failed')}</h3><p>${t('error_load_desc')}</p></div>`;
|
||||
}
|
||||
}
|
||||
|
||||
async function loadFeatured() {
|
||||
showToast('正在为你挑选编辑精选…');
|
||||
showToast(t('toast_featured_loading'));
|
||||
try {
|
||||
const products = await fetchJSON('/api/v1/shop/featured?limit=8');
|
||||
renderProducts(products, products.length);
|
||||
document.getElementById('pagination').innerHTML = '';
|
||||
document.getElementById('productsCount').innerHTML = `编辑精选 · <strong>${products.length}</strong> 件商品`;
|
||||
document.getElementById('productsCount').innerHTML = t('products_count_featured', {n: products.length});
|
||||
scrollToShop();
|
||||
} catch (e) { showToast('精选加载失败,请稍后重试'); }
|
||||
} catch (e) { showToast(t('toast_featured_failed')); }
|
||||
}
|
||||
|
||||
// ========== 渲染 ==========
|
||||
function renderCategoryChips() {
|
||||
const container = document.getElementById('categoryChips');
|
||||
const head = `<span class="cat-label">分类</span><span class="cat-chip ${selectedCategory === 0 ? 'active' : ''}" onclick="selectCategory(0)">全部</span>`;
|
||||
const head = `<span class="cat-label" data-i18n="cat_label">${t('cat_label')}</span><span class="cat-chip ${selectedCategory === 0 ? 'active' : ''}" onclick="selectCategory(0)" data-i18n="cat_all">${t('cat_all')}</span>`;
|
||||
container.innerHTML = head + allCategories
|
||||
.sort((a,b) => (a.sort||0) - (b.sort||0))
|
||||
.map(c => `<span class="cat-chip ${selectedCategory === c.id ? 'active' : ''}" onclick="selectCategory(${c.id})">${c.name}</span>`).join('');
|
||||
@@ -1260,17 +1624,17 @@ function renderCategoryChips() {
|
||||
|
||||
function categoryName(id) {
|
||||
const c = allCategories.find(x => x.id === id);
|
||||
return c ? c.name : '生活好物';
|
||||
return c ? c.name : t('category_default');
|
||||
}
|
||||
|
||||
function renderProducts(products, total) {
|
||||
const grid = document.getElementById('productsGrid');
|
||||
document.getElementById('productsCount').innerHTML = `共 <strong>${total}</strong> 件商品`;
|
||||
document.getElementById('productsCount').innerHTML = t('products_count', {n: total});
|
||||
|
||||
if (!products || products.length === 0) {
|
||||
grid.innerHTML = `<div class="empty-state">
|
||||
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor"><circle cx="11" cy="11" r="7"/><path d="m21 21-4.35-4.35"/></svg>
|
||||
<h3>暂无商品</h3><p>没有找到匹配的商品,换个关键词试试</p></div>`;
|
||||
<h3>${t('empty_title')}</h3><p>${t('empty_desc')}</p></div>`;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1278,7 +1642,7 @@ function renderProducts(products, total) {
|
||||
const discount = p.original_price > p.price ? Math.round((1 - p.price / p.original_price) * 100) : 0;
|
||||
let tags = [];
|
||||
try { tags = JSON.parse(p.tags || '[]'); } catch (e) {}
|
||||
const tagHtml = tags.slice(0, 2).map(t => `<span class="product-tag ${tagClass(t)}">${t}</span>`).join('');
|
||||
const tagHtml = tags.slice(0, 2).map(tg => `<span class="product-tag ${tagClass(tg)}">${tg}</span>`).join('');
|
||||
const rating = typeof p.rating === 'number' ? p.rating : 0;
|
||||
|
||||
return `
|
||||
@@ -1287,7 +1651,7 @@ function renderProducts(products, total) {
|
||||
${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="加入心愿单">
|
||||
<button class="product-wish" onclick="event.stopPropagation();showToast(t('toast_wishlist'))" data-i18n-title="title_favorites" title="${t('title_favorites')}">
|
||||
<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>
|
||||
</button>
|
||||
</div>
|
||||
@@ -1363,7 +1727,7 @@ function scrollToShop() {
|
||||
async function showProductDetail(id) {
|
||||
const modal = document.getElementById('productModal');
|
||||
const content = document.getElementById('modalContent');
|
||||
content.innerHTML = `<div style="grid-column:1/-1;padding:90px;text-align:center;color:var(--text-muted);font-size:13px;letter-spacing:1px;">载入中…</div>`;
|
||||
content.innerHTML = `<div style="grid-column:1/-1;padding:90px;text-align:center;color:var(--text-muted);font-size:13px;letter-spacing:1px;">${t('modal_loading')}</div>`;
|
||||
modal.classList.add('open');
|
||||
document.body.style.overflow = 'hidden';
|
||||
|
||||
@@ -1388,22 +1752,22 @@ async function showProductDetail(id) {
|
||||
${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>
|
||||
<div class="modal-cat">${categoryName(p.category_id)} · ${t('modal_nordi_pick')}</div>
|
||||
<h2>${p.name}</h2>
|
||||
<div class="modal-tags">${tags.map(t => `<span class="product-tag ${tagClass(t)}">${t}</span>`).join('')}</div>
|
||||
<div class="modal-tags">${tags.map(tg => `<span class="product-tag ${tagClass(tg)}">${tg}</span>`).join('')}</div>
|
||||
<div class="modal-price">
|
||||
<span class="price-now">$${Number(p.price).toFixed(2)}</span>
|
||||
${p.original_price > p.price ? `<span class="price-was">$${Number(p.original_price).toFixed(2)}</span>` : ''}
|
||||
${discount > 0 ? `<span class="product-tag t-sage">省 ${discount}%</span>` : ''}
|
||||
${discount > 0 ? `<span class="product-tag t-sage">${t('modal_save_pct', {n: discount})}</span>` : ''}
|
||||
</div>
|
||||
<p class="modal-desc">${p.description || '每一处细节皆经匠心打磨,以克制的线条与温润的质感,融入你的日常生活。'}</p>
|
||||
<p class="modal-desc">${p.description || t('modal_desc_fallback')}</p>
|
||||
<div class="modal-meta">
|
||||
<div class="modal-meta-item"><span class="mm-val">${rating.toFixed(1)}</span><span class="mm-label">评分</span></div>
|
||||
<div class="modal-meta-item"><span class="mm-val">${formatSales(p.sales)}</span><span class="mm-label">销量</span></div>
|
||||
<div class="modal-meta-item"><span class="mm-val">${stock}</span><span class="mm-label">库存</span></div>
|
||||
<div class="modal-meta-item"><span class="mm-val">${rating.toFixed(1)}</span><span class="mm-label">${t('modal_rating')}</span></div>
|
||||
<div class="modal-meta-item"><span class="mm-val">${formatSales(p.sales)}</span><span class="mm-label">${t('modal_sales')}</span></div>
|
||||
<div class="modal-meta-item"><span class="mm-val">${stock}</span><span class="mm-label">${t('modal_stock')}</span></div>
|
||||
</div>
|
||||
<div class="modal-qty">
|
||||
<span class="modal-qty-label">数量</span>
|
||||
<span class="modal-qty-label">${t('modal_qty')}</span>
|
||||
<div class="qty-control">
|
||||
<button onclick="changeModalQty(-1)">−</button>
|
||||
<span id="modalQty">1</span>
|
||||
@@ -1412,10 +1776,10 @@ async function showProductDetail(id) {
|
||||
</div>
|
||||
<button class="modal-add-cart" onclick="addToCart(${p.id}, getModalQty());closeModal()">
|
||||
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5"><path d="M6 2 3 6v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V6l-3-4z"/><path d="M3 6h18"/><path d="M16 10a4 4 0 0 1-8 0"/></svg>
|
||||
加入购物袋</button>
|
||||
${t('modal_add_cart')}</button>
|
||||
</div>`;
|
||||
} catch (e) {
|
||||
content.innerHTML = `<div style="grid-column:1/-1;padding:80px;text-align:center;color:var(--text-muted)"><p>商品详情加载失败,请稍后重试</p></div>`;
|
||||
content.innerHTML = `<div style="grid-column:1/-1;padding:80px;text-align:center;color:var(--text-muted)"><p>${t('modal_load_error')}</p></div>`;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1445,13 +1809,14 @@ async function addToCart(productId, qty = 1) {
|
||||
try {
|
||||
product = await fetchJSON(`/api/v1/shop/products/${productId}`);
|
||||
productCache[productId] = product;
|
||||
} catch (e) { showToast('添加失败,请重试'); return; }
|
||||
} catch (e) { showToast(t('toast_add_failed')); return; }
|
||||
}
|
||||
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, image: product.image || '' });
|
||||
updateCartUI();
|
||||
showToast(`已加入购物袋 · ${product.name.length > 14 ? product.name.substring(0, 14) + '…' : product.name}`);
|
||||
var displayName = product.name.length > 14 ? product.name.substring(0, 14) + '…' : product.name;
|
||||
showToast(t('toast_added_to_cart', {name: displayName}));
|
||||
}
|
||||
|
||||
function removeFromCart(productId) {
|
||||
@@ -1479,7 +1844,7 @@ function updateCartUI() {
|
||||
if (cart.length === 0) {
|
||||
container.innerHTML = `<div class="cart-empty">
|
||||
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor"><path d="M6 2 3 6v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V6l-3-4z"/><path d="M3 6h18"/><path d="M16 10a4 4 0 0 1-8 0"/></svg>
|
||||
<p>购物袋还是空的</p><p class="ce-sub">去挑选心仪的好物吧</p></div>`;
|
||||
<p>${t('cart_empty_title')}</p><p class="ce-sub">${t('cart_empty_desc')}</p></div>`;
|
||||
return;
|
||||
}
|
||||
container.innerHTML = cart.map(item => `
|
||||
@@ -1494,7 +1859,7 @@ function updateCartUI() {
|
||||
<span>${item.qty}</span>
|
||||
<button onclick="changeQty(${item.id}, 1)">+</button>
|
||||
</div>
|
||||
<span class="cart-remove" onclick="removeFromCart(${item.id})">移除</span>
|
||||
<span class="cart-remove" onclick="removeFromCart(${item.id})">${t('cart_remove')}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>`).join('');
|
||||
@@ -1510,7 +1875,7 @@ function toggleCart(force) {
|
||||
function checkout() {
|
||||
if (cart.length === 0) return;
|
||||
const total = cart.reduce((s, i) => s + i.price * i.qty, 0);
|
||||
showToast(`订单已提交 · 合计 $${total.toFixed(2)} · 感谢惠顾`);
|
||||
showToast(t('toast_order_submitted', {total: '$' + total.toFixed(2)}));
|
||||
cart = [];
|
||||
updateCartUI();
|
||||
toggleCart(false);
|
||||
@@ -1519,7 +1884,7 @@ function checkout() {
|
||||
// ========== 工具 ==========
|
||||
function formatSales(n) {
|
||||
n = Number(n) || 0;
|
||||
if (n >= 10000) return (n / 10000).toFixed(1) + '万';
|
||||
if (n >= 10000) return (n / 10000).toFixed(1) + (currentLang === 'en' ? '0k' : '万');
|
||||
return n.toString();
|
||||
}
|
||||
function showToast(msg) {
|
||||
@@ -1530,9 +1895,24 @@ function showToast(msg) {
|
||||
window._toastTimer = setTimeout(() => toast.classList.remove('show'), 2600);
|
||||
}
|
||||
|
||||
// ========== 语言切换回调:重新渲染动态内容 ==========
|
||||
function onLangChange(lang) {
|
||||
renderCategoryChips();
|
||||
if (featuredLoaded) {
|
||||
loadFeatured();
|
||||
} else {
|
||||
loadProducts();
|
||||
}
|
||||
updateCartUI();
|
||||
var searchInput = document.getElementById('searchInput');
|
||||
if (searchInput) searchInput.placeholder = t('search_placeholder');
|
||||
loadFeatured();
|
||||
}
|
||||
|
||||
// ========== 初始化 ==========
|
||||
document.getElementById('searchInput').addEventListener('input', handleSearch);
|
||||
async function init() {
|
||||
applyI18n();
|
||||
await loadCategories();
|
||||
await loadProducts();
|
||||
updateCartUI();
|
||||
@@ -1544,7 +1924,6 @@ init();
|
||||
var reduceMotion = window.matchMedia && window.matchMedia('(prefers-reduced-motion: reduce)').matches;
|
||||
if (reduceMotion) return;
|
||||
|
||||
/* —— 全局鼠标跟随柔光斑(轻柔拖尾,北欧式优雅)—— */
|
||||
var cursorGlow = document.createElement('div');
|
||||
cursorGlow.className = 'cursor-glow';
|
||||
document.body.appendChild(cursorGlow);
|
||||
@@ -1559,7 +1938,6 @@ init();
|
||||
requestAnimationFrame(loop);
|
||||
})();
|
||||
|
||||
/* —— 产品卡片 3D 倾斜(最大 6°,柔和流畅;事件委托兼容动态渲染)—— */
|
||||
var activeCard = null;
|
||||
document.addEventListener('mousemove', function(e){
|
||||
var card = (e.target && e.target.closest) ? e.target.closest('.product-card') : null;
|
||||
@@ -1571,13 +1949,12 @@ init();
|
||||
var rect = card.getBoundingClientRect();
|
||||
var cx = rect.left + rect.width / 2;
|
||||
var cy = rect.top + rect.height / 2;
|
||||
var rx = ((e.clientY - cy) / rect.height) * -6; // 北欧克制:最大 6°
|
||||
var rx = ((e.clientY - cy) / rect.height) * -6;
|
||||
var ry = ((e.clientX - cx) / rect.width) * 6;
|
||||
card.style.transform = 'perspective(1000px) rotateX(' + rx.toFixed(2) + 'deg) rotateY(' + ry.toFixed(2) + 'deg) translateY(-6px)';
|
||||
card.style.setProperty('--mx', ((e.clientX - rect.left) / rect.width * 100).toFixed(1) + '%');
|
||||
card.style.setProperty('--my', ((e.clientY - rect.top) / rect.height * 100).toFixed(1) + '%');
|
||||
});
|
||||
/* 鼠标移出文档时复位倾斜 */
|
||||
document.addEventListener('mouseleave', function(){
|
||||
if (activeCard){ activeCard.style.transform = ''; activeCard = null; }
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user